MCPcopy Index your code
hub / github.com/Breakthrough/PySceneDetect / test_save_load_from_video

Function test_save_load_from_video

tests/test_stats_manager.py:137–168  ·  view source on GitHub ↗

Test generating and saving some frame metrics from TEST_VIDEO_FILE to a file on disk, and loading the file back to ensure the loaded frame metrics agree with those that were saved.

(test_video_file, tmp_path: Path)

Source from the content-addressed store, hash-verified

135
136
137def test_save_load_from_video(test_video_file, tmp_path: Path):
138 """Test generating and saving some frame metrics from TEST_VIDEO_FILE to a file on disk, and
139 loading the file back to ensure the loaded frame metrics agree with those that were saved.
140 """
141 video = VideoStreamCv2(test_video_file)
142 stats_manager = StatsManager()
143 scene_manager = SceneManager(stats_manager)
144
145 scene_manager.add_detector(ContentDetector())
146
147 video_fps = video.frame_rate
148 duration = FrameTimecode("00:00:05", video_fps)
149
150 scene_manager.auto_downscale = True
151 scene_manager.detect_scenes(video, duration=duration)
152
153 path = tmp_path.joinpath("stats.csv")
154 stats_manager.save_to_csv(csv_file=path)
155
156 metrics = stats_manager.metric_keys
157
158 stats_manager_new = StatsManager()
159
160 stats_manager_new.load_from_csv(path)
161
162 # Compare the first 5 frames. Frame 0 won't have any metrics for this detector.
163 for frame in range(1, 5 + 1):
164 assert stats_manager.metrics_exist(frame, metrics)
165 orig_metrics = stats_manager.get_metrics(frame, metrics)
166 new_metrics = stats_manager_new.get_metrics(frame, metrics)
167 for i, metric_val in enumerate(orig_metrics):
168 assert metric_val == pytest.approx(new_metrics[i])
169
170
171def test_load_corrupt_stats(tmp_path: Path):

Callers

nothing calls this directly

Calls 11

add_detectorMethod · 0.95
detect_scenesMethod · 0.95
save_to_csvMethod · 0.95
load_from_csvMethod · 0.95
metrics_existMethod · 0.95
get_metricsMethod · 0.95
VideoStreamCv2Class · 0.90
StatsManagerClass · 0.90
SceneManagerClass · 0.90
ContentDetectorClass · 0.90
FrameTimecodeClass · 0.90

Tested by

no test coverage detected