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)
| 135 | |
| 136 | |
| 137 | def 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 | |
| 171 | def test_load_corrupt_stats(tmp_path: Path): |
nothing calls this directly
no test coverage detected