import tempfile import unittest from pathlib import Path from video_ai_analysis_poc.frames import build_frame_records, seconds_to_timecode class FrameTests(unittest.TestCase): def test_seconds_to_timecode_formats_relative_offsets(self): self.assertEqual(seconds_to_timecode(0), "00:00:00") self.assertEqual(seconds_to_timecode(65.2), "00:01:05") self.assertEqual(seconds_to_timecode(3661), "01:01:01") def test_build_frame_records_uses_stable_paths_and_offsets(self): with tempfile.TemporaryDirectory() as tmp: frame_dir = Path(tmp) / "frames" / "video-abc" frame_dir.mkdir(parents=True) first = frame_dir / "000001.jpg" second = frame_dir / "000002.jpg" first.write_bytes(b"jpg") second.write_bytes(b"jpg") records = build_frame_records( "video-abc", Path(tmp), [first, second], frame_fps=1, ) self.assertEqual(records[0]["frame_id"], "video-abc_f000001") self.assertEqual(records[0]["frame_path"], "frames/video-abc/000001.jpg") self.assertEqual(records[0]["offset_seconds"], 0.0) self.assertEqual(records[0]["timecode"], "00:00:00") self.assertEqual(records[0]["pts_time"], 0.0) self.assertEqual(records[0]["status"], "sampled") self.assertEqual(records[1]["offset_seconds"], 1.0) def test_build_frame_records_adds_beijing_time_from_timeline_epoch(self): with tempfile.TemporaryDirectory() as tmp: frame_dir = Path(tmp) / "frames" / "video-abc" frame_dir.mkdir(parents=True) first = frame_dir / "000001.jpg" second = frame_dir / "000002.jpg" first.write_bytes(b"jpg") second.write_bytes(b"jpg") records = build_frame_records( "video-abc", Path(tmp), [first, second], frame_fps=1, timeline_start_epoch=1781478000, timezone_name="Asia/Shanghai", ) self.assertEqual(records[0]["beijing_time"], "2026-06-15 07:00:00") self.assertEqual(records[1]["beijing_time"], "2026-06-15 07:00:01") if __name__ == "__main__": unittest.main()