Test SceneManager detect_scenes method with a callback function. Note that the API signature of the callback will undergo breaking changes in v1.0.
(test_video_file)
| 107 | |
| 108 | |
| 109 | def test_detect_scenes_callback(test_video_file): |
| 110 | """Test SceneManager detect_scenes method with a callback function. |
| 111 | |
| 112 | Note that the API signature of the callback will undergo breaking changes in v1.0. |
| 113 | """ |
| 114 | video = VideoStreamCv2(test_video_file) |
| 115 | sm = SceneManager() |
| 116 | sm.add_detector(ContentDetector()) |
| 117 | |
| 118 | fake_callback = FakeCallback() |
| 119 | |
| 120 | video_fps = video.frame_rate |
| 121 | start_time = FrameTimecode("00:00:05", video_fps) |
| 122 | end_time = FrameTimecode("00:00:15", video_fps) |
| 123 | video.seek(start_time) |
| 124 | sm.auto_downscale = True |
| 125 | |
| 126 | _ = sm.detect_scenes( |
| 127 | video=video, end_time=end_time, callback=fake_callback.get_callback_lambda() |
| 128 | ) |
| 129 | scene_list = sm.get_scene_list() |
| 130 | assert [start for start, end in scene_list] == TEST_VIDEO_START_FRAMES_ACTUAL |
| 131 | assert fake_callback.scene_list == TEST_VIDEO_START_FRAMES_ACTUAL[1:] |
| 132 | |
| 133 | # Perform same test using callback function instead of lambda. |
| 134 | sm.clear() |
| 135 | sm.add_detector(ContentDetector()) |
| 136 | fake_callback = FakeCallback() |
| 137 | video.seek(start_time) |
| 138 | |
| 139 | _ = sm.detect_scenes(video=video, end_time=end_time, callback=fake_callback.get_callback_func()) |
| 140 | scene_list = sm.get_scene_list() |
| 141 | assert [start for start, end in scene_list] == TEST_VIDEO_START_FRAMES_ACTUAL |
| 142 | assert fake_callback.scene_list == TEST_VIDEO_START_FRAMES_ACTUAL[1:] |
| 143 | |
| 144 | |
| 145 | def test_detect_scenes_callback_adaptive(test_video_file): |
nothing calls this directly
no test coverage detected