Skip to content

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

Merged
Breakthrough merged 3 commits into
Breakthrough:mainfrom
charlesvestal:expand-to-video
May 20, 2026
Merged

Add --expand flag to split-video (#115)#551
Breakthrough merged 3 commits into
Breakthrough:mainfrom
charlesvestal:expand-to-video

Conversation

@charlesvestal
Copy link
Copy Markdown
Contributor

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

charlesvestal and others added 2 commits May 17, 2026 09:39
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.
…ecode

The function builds a SceneList (list[tuple[FrameTimecode, FrameTimecode]]),
so accepting int violated the tuple element type at assignment. All callers
pass FrameTimecode.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Breakthrough Breakthrough self-assigned this May 18, 2026
@Breakthrough Breakthrough added this to the 0.7.1 milestone May 18, 2026
@Breakthrough
Copy link
Copy Markdown
Owner

Thanks for taking a pass at this! Appreciate the up-front disclosures as well. I'll get the main branch ready to continue development after the 0.7 release now (next will be 0.7.1). Happy to include this feature in the next release.

Copy link
Copy Markdown
Owner

@Breakthrough Breakthrough left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Is it possible for you to update the CLI docs as well to include the new flag? Feel free to defer if you want, just say "prefer if you can update docs" and I'll take it from there. Cheers.

Comment thread scenedetect/_cli/__init__.py Outdated
Comment thread scenedetect/_cli/config.py Outdated
Addresses PR Breakthrough#551 review:
- Rename CLI flag --expand-to-video to --expand (terser form).
- Add `expand` entry to scenedetect.cfg template.
- Document --expand option in docs/cli.rst.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Breakthrough Breakthrough merged commit 86469a2 into Breakthrough:main May 20, 2026
27 checks passed
@Breakthrough
Copy link
Copy Markdown
Owner

Thanks for the PR!

@charlesvestal charlesvestal changed the title Add --expand-to-video flag to split-video (#115) Add --expand flag to split-video (#115) May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

2 participants