Skip to content

Commit

Permalink
Fix bug in get_scenes_from_cuts (resolves #106), add unit test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Breakthrough committed Aug 31, 2019
1 parent 30775d7 commit d097275
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
6 changes: 3 additions & 3 deletions docs/changelog.md
Expand Up @@ -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) &nbsp;<span class="fa fa-tags"></span>
Expand Down
4 changes: 2 additions & 2 deletions scenedetect/scene_manager.py
Expand Up @@ -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.
Expand All @@ -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

Expand Down
13 changes: 9 additions & 4 deletions tests/test_scene_manager.py
Expand Up @@ -129,20 +129,25 @@ 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()

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).
Expand Down

0 comments on commit d097275

Please sign in to comment.