Add --expand-to-video flag to split-video (#115)#551
Open
charlesvestal wants to merge 1 commit into
Open
Conversation
Allows scenes to be detected within a sub-region of a video (via time -s/-e) while having the resulting split clips extend to cover content outside that analysis window. The first output clip extends back to the start of the video, and the last clip extends to the end. Adds a pure helper expand_scenes_to_bounds() to scene_manager.py and wires it into the split-video command behind --expand-to-video. Falls back to the original scene boundaries (with a warning) if the video duration is not available.
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.
Summary
Resolves #115 (which I filed back in 2020).
Adds a
--expand-to-videoflag tosplit-videoso that when scene detection is limited to a sub-region of a video viatime -s/-e, the resulting split clips extend outward to cover content outside the analysis window. The first output clip extends back to the start of the video, and the last clip extends to the end.This is useful for files with roughly known split points, where you want to target a specific area only — e.g. a 30-minute file where you know there's a cut somewhere between 13:00 and 17:00. You can limit detection to that range (fast, no false positives elsewhere) and still get two 15-minute clips covering the full video rather than two ~2-minute clips of just the analyzed window.
Implementation
expand_scenes_to_bounds(scenes, start, end)inscene_manager.py(sits next toget_scenes_from_cuts, same docstring style). Unit-tested in isolation.--expand-to-videoonsplit-video, with a matchingexpand-to-videoconfig entry (defaultFalse).split_videocommand handler invokes the helper before dispatching to either ffmpeg or mkvmerge, so both splitters get the expanded list. Falls back to the original scene boundaries with a warning ifvideo_stream.durationisNone.Disclosure
I used Claude to help draft this. All code was reviewed and verified by me; the smoke testing below was driven from my end against synthesized fixtures.
Test plan
pytest tests/test_scene_manager.py— 10/10 pass (6 existing + 4 new unit tests forexpand_scenes_to_bounds)pytest tests/test_cli.py— 49 pass, 2 unrelated env failures (missingpyav/moviepydeps locally)ruff checkandruff format --checkclean on all touched filestime -s 12 -e 22+--expand-to-video→ 3 clips of ~15s / ~5s / ~10s (keyframe-rounded), first-frame colors red / yellow / magentatimewindow +--expand-to-video→ no-op, full coverage preservedtime -s 12only +--expand-to-video→ first clip extends back to 0time -e 22only +--expand-to-video→ last clip extends to video end