Repository navigation
[bugfix] Keep save-images last image inside its scene - #608
Merged
Breakthrough merged 3 commits intoNov 18, 2026
Merged
Breakthrough merged 3 commits into
Breakthrough merged 3 commits into
Conversation
Scene end times are exclusive, but the last image of each scene was taken at end - frame_margin, so with the default margin of 1 it was the last frame of the scene (no margin) and with 0 it was the first frame of the next scene. Count the margin from the last frame of the scene as v0.6 did, and clamp images of very short scenes to that frame.
Breakthrough
requested changes
Nov 17, 2026
Breakthrough
left a comment
Owner
There was a problem hiding this comment.
Thanks for the PR, good find.
Scenes can be shorter than one frame (e.g. VFR), in which case end - 1 frame falls before the scene start.
Breakthrough
approved these changes
Nov 18, 2026
MuhammadBilalKhan267
added a commit
to MuhammadBilalKhan267/PySceneDetect
that referenced
this pull request
Nov 22, 2026
- Preserve FramePosition and exact Timecode arithmetic - Restore frame-rate-based image margins and port the Breakthrough#608 clamp - Retain upstream weight validation and formatter regression tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #607
Scene end times are exclusive, but
_generate_timecode_list()took the last image of each scene atend - frame_margin. So since v0.7:frame_margin=0saves the first frame of the next scene as the last image (a frame that doesn't exist for the last scene of a video)frame_margin=1(default) saves the last frame of the scene, with no margin at the endThis counts the margin from the last frame of the scene, as v0.6 did, and clamps every image to that frame. The clamp covers very short scenes, where the midpoint could round up into the next scene (a one-frame scene
(11, 12)saved frame 12).Frames saved for a scene covering frames 0-99 with
num_images=3:Note that this changes the output for the default margin too: the last image moves one frame earlier, back to where v0.6 put it.
I left the
frame_margindocstring alone. It still says a margin of 0 may fail to extract the very last frame of some videos, which I couldn't check here.Tested on Windows with Python 3.10 and the OpenCV backend. The new tests fail without the change. The full suite passes except
test_write_scene_list_ffmetadata_ffmpeg_roundtrip, which needsffmpegand I don't have it installed.