Test scenedetect.scene_manager.save_images function.
(test_video_file, tmp_path: Path)
| 95 | |
| 96 | |
| 97 | def test_save_images(test_video_file, tmp_path: Path): |
| 98 | """Test scenedetect.scene_manager.save_images function.""" |
| 99 | video = VideoStreamCv2(test_video_file) |
| 100 | sm = SceneManager() |
| 101 | sm.add_detector(ContentDetector()) |
| 102 | |
| 103 | image_name_glob = "scenedetect.tempfile.*.jpg" |
| 104 | image_name_template = ( |
| 105 | "scenedetect.tempfile.$SCENE_NUMBER.$IMAGE_NUMBER.$FRAME_NUMBER.$TIMESTAMP_MS.$TIMECODE" |
| 106 | ) |
| 107 | |
| 108 | video_fps = video.frame_rate |
| 109 | scene_list = [ |
| 110 | (FrameTimecode(start, video_fps), FrameTimecode(end, video_fps)) |
| 111 | for start, end in [(0, 100), (200, 300), (300, 400)] |
| 112 | ] |
| 113 | |
| 114 | image_filenames = save_images( |
| 115 | scene_list=scene_list, |
| 116 | output_dir=tmp_path, |
| 117 | video=video, |
| 118 | num_images=3, |
| 119 | image_extension="jpg", |
| 120 | image_name_template=image_name_template, |
| 121 | threading=False, |
| 122 | ) |
| 123 | |
| 124 | # Ensure images got created, and the proper number got created. |
| 125 | total_images = 0 |
| 126 | for scene_number in image_filenames: |
| 127 | for path in image_filenames[scene_number]: |
| 128 | assert tmp_path.joinpath(path).exists(), f"expected {path} to exist" |
| 129 | total_images += 1 |
| 130 | |
| 131 | assert total_images == len([path for path in tmp_path.glob(image_name_glob)]) |
| 132 | |
| 133 | |
| 134 | def test_save_images_singlethreaded(test_video_file, tmp_path: Path): |
nothing calls this directly
no test coverage detected