From d097275d5c6d1444dc049d8cc6bb8e11da4208ad Mon Sep 17 00:00:00 2001 From: Breakthrough Date: Fri, 30 Aug 2019 21:45:36 -0400 Subject: [PATCH] Fix bug in get_scenes_from_cuts (resolves #106), add unit test coverage. --- docs/changelog.md | 6 +++--- scenedetect/scene_manager.py | 4 ++-- tests/test_scene_manager.py | 13 +++++++++---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index bf5d66c1..90d177ca 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,9 +4,9 @@ PySceneDetect Changelog ### 0.5.2 (TBD) - * [bugfix] `--min-scene-len` option was not respected by first/last scenes - ([#105](https://github.com/Breakthrough/PySceneDetect/issues/105), thanks @charlesvestal) - NOTE: Only fixed for first scenes currentl + * upcoming minor release of PySceneDetect including various bugfixes/enhancements prior to the v0.6 release + * [bugfix] `--min-scene-len` option was not respected by first scene ([#105](https://github.com/Breakthrough/PySceneDetect/issues/105), thanks @charlesvestal) + * [bugfix] Splitting videos with an analyzed duration only splits within analyzed area ([#106](https://github.com/Breakthrough/PySceneDetect/issues/106), thanks @charlesvestal) ### 0.5.1.1 (August 3, 2019)   diff --git a/scenedetect/scene_manager.py b/scenedetect/scene_manager.py index e41bf47d..5714393e 100644 --- a/scenedetect/scene_manager.py +++ b/scenedetect/scene_manager.py @@ -96,7 +96,7 @@ def get_scenes_from_cuts(cut_list, base_timecode, num_frames, start_frame=0): # Scene list, where scenes are tuples of (Start FrameTimecode, End FrameTimecode). scene_list = [] if not cut_list: - scene_list.append((base_timecode + start_frame, base_timecode + num_frames)) + scene_list.append((base_timecode + start_frame, base_timecode + start_frame + num_frames)) return scene_list # Initialize last_cut to the first frame we processed,as it will be # the start timecode for the first scene in the list. @@ -105,7 +105,7 @@ def get_scenes_from_cuts(cut_list, base_timecode, num_frames, start_frame=0): scene_list.append((last_cut, cut)) last_cut = cut # Last scene is from last cut to end of video. - scene_list.append((last_cut, base_timecode + num_frames)) + scene_list.append((last_cut, base_timecode + start_frame + num_frames)) return scene_list diff --git a/tests/test_scene_manager.py b/tests/test_scene_manager.py index d60d03d2..6f086d6a 100644 --- a/tests/test_scene_manager.py +++ b/tests/test_scene_manager.py @@ -129,8 +129,10 @@ def test_scene_list(test_video_file): try: base_timecode = vm.get_base_timecode() video_fps = vm.get_framerate() - start_time = FrameTimecode('00:00:00', video_fps) - end_time = FrameTimecode('00:00:10', video_fps) + start_time = FrameTimecode('00:00:05', video_fps) + end_time = FrameTimecode('00:00:15', video_fps) + + assert end_time.get_frames() > start_time.get_frames() vm.set_duration(start_time=start_time, end_time=end_time) vm.set_downscale_factor() @@ -138,11 +140,14 @@ def test_scene_list(test_video_file): vm.start() num_frames = sm.detect_scenes(frame_source=vm) - assert num_frames == end_time.get_frames() + 1 + assert num_frames == (1 + end_time.get_frames() - start_time.get_frames()) scene_list = sm.get_scene_list(base_timecode) - + assert scene_list + for i, _ in enumerate(scene_list): + assert len(scene_list[0]) == 2 + assert scene_list[i][0].get_frames() < scene_list[i][1].get_frames() if i > 0: # Ensure frame list is sorted (i.e. end time frame of # one scene is equal to the start time of the next).