Skip to content

Add --expand-to-video flag to split-video (#115)#551

Open
charlesvestal wants to merge 1 commit into
Breakthrough:mainfrom
charlesvestal:expand-to-video
Open

Add --expand-to-video flag to split-video (#115)#551
charlesvestal wants to merge 1 commit into
Breakthrough:mainfrom
charlesvestal:expand-to-video

Conversation

@charlesvestal
Copy link
Copy Markdown

Summary

Resolves #115 (which I filed back in 2020).

Adds a --expand-to-video flag to split-video so that when scene detection is limited to a sub-region of a video via time -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

  • New pure helper expand_scenes_to_bounds(scenes, start, end) in scene_manager.py (sits next to get_scenes_from_cuts, same docstring style). Unit-tested in isolation.
  • CLI flag --expand-to-video on split-video, with a matching expand-to-video config entry (default False).
  • split_video command 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 if video_stream.duration is None.

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 for expand_scenes_to_bounds)
  • pytest tests/test_cli.py — 49 pass, 2 unrelated env failures (missing pyav/moviepy deps locally)
  • ruff check and ruff format --check clean on all touched files
  • End-to-end smoke test on a synthesized 30s, 6-segment color test video (cuts every 5s):
    • ffmpeg path with time -s 12 -e 22 + --expand-to-video → 3 clips of ~15s / ~5s / ~10s (keyframe-rounded), first-frame colors red / yellow / magenta
    • mkvmerge path with the same args → 3 clips of exactly 15.0s / 5.0s / 10.0s, same red / yellow / magenta colors
    • No time window + --expand-to-video → no-op, full coverage preserved
    • time -s 12 only + --expand-to-video → first clip extends back to 0
    • time -e 22 only + --expand-to-video → last clip extends to video end

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow for clips to be split with content outside of start/end timeframe

1 participant