Skip to content

Commit 2d8dc34

Browse files
leninworldBreakthrough
authored andcommitted
[cli] Treat an all-space split-video -a as unset, add changelog (#634)
An all-space -a/--args now behaves like -a "": config-file args and then the built-in defaults apply. split_video_ffmpeg is unchanged; an empty or all-space arg_override passes no extra arguments, now documented and tested.
1 parent da60b07 commit 2d8dc34

5 files changed

Lines changed: 52 additions & 1 deletion

File tree

‎scenedetect/_cli/__init__.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,9 @@ def split_video_command(
13581358
error = "The split-video command is incompatible with image sequences/URLs."
13591359
raise click.BadParameter(error, param_hint="split-video")
13601360

1361+
if args is not None and not args.strip(" "):
1362+
args = ""
1363+
13611364
# Overwrite flags if no encoder flags/options were set via the CLI to avoid conflicting options
13621365
# (e.g. `--copy` should override any `high-quality = yes` setting in the config file).
13631366
if not (mkvmerge or copy or high_quality or args or rate_factor or preset):

‎scenedetect/output/video.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ def split_video_ffmpeg(
276276
$VIDEO_NAME, $SCENE_NUMBER, $START_TIME, $END_TIME, $START_FRAME, $END_FRAME
277277
video_name: Name of the video to be substituted in output_file_template. If not
278278
passed will be calculated from input_video_path automatically.
279-
arg_override: Allows overriding the arguments passed to ffmpeg for encoding.
279+
arg_override: Allows overriding the arguments passed to ffmpeg for encoding. An empty or
280+
all-space value passes no extra arguments; omitting it uses the default.
280281
show_progress: If True, will show progress bar provided by tqdm (if installed).
281282
show_output: If True, will show output from ffmpeg for first split.
282283
suppress_output: [DEPRECATED] DO NOT USE. For backwards compatibility only.

‎tests/test_cli.py‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,47 @@ def test_cli_split_video_ffmpeg(tmp_path: Path):
794794
)
795795

796796

797+
@pytest.mark.parametrize(
798+
("config", "expected_args"),
799+
[
800+
("", "-map 0:v:0 -map 0:a? -map 0:s? -c:v libx264 -preset veryfast -crf 22 -c:a aac"),
801+
("[split-video]\nargs = -c:v libx265 -c:a aac\n", "-c:v libx265 -c:a aac"),
802+
],
803+
)
804+
def test_cli_split_video_empty_args_use_defaults(
805+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, config: str, expected_args: str
806+
):
807+
"""Empty and all-space -a values should behave like omitting the option."""
808+
config_path = tmp_path / "scenedetect.cfg"
809+
config_path.write_text(config)
810+
ffmpeg_args = []
811+
812+
def split_video_ffmpeg(**kwargs):
813+
ffmpeg_args.append(kwargs["arg_override"])
814+
return 0
815+
816+
monkeypatch.setattr("scenedetect._cli.check_split_video_requirements", lambda **kwargs: None)
817+
monkeypatch.setattr("scenedetect._cli.commands.split_video_ffmpeg", split_video_ffmpeg)
818+
for args in ([], ["-a", ""], ["-a", " "]):
819+
exit_code, output = invoke_cli(
820+
[
821+
"-c",
822+
str(config_path),
823+
"-i",
824+
DEFAULT_VIDEO_PATH,
825+
"time",
826+
"-e",
827+
"1",
828+
DEFAULT_DETECTOR,
829+
"split-video",
830+
*args,
831+
]
832+
)
833+
assert exit_code == 0, output
834+
835+
assert ffmpeg_args == [expected_args] * 3
836+
837+
797838
@pytest.mark.skipif(condition=not is_mkvmerge_available(), reason="mkvmerge is not available")
798839
def test_cli_split_video_mkvmerge(tmp_path: Path):
799840
"""Test `split-video` command using mkvmerge."""

‎tests/test_output.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ def name_formatter(video: VideoMetadata, scene: SceneMetadata):
109109
@pytest.mark.parametrize(
110110
("arg_override", "expected"),
111111
[
112+
("", []),
113+
(" ", []),
114+
(" ", []),
112115
("-c:v libx264 -crf 30", ["-c:v", "libx264", "-crf", "30"]),
113116
(" -c:v libx264 -crf 30", ["-c:v", "libx264", "-crf", "30"]),
114117
("-c:v libx264 -crf 30 ", ["-c:v", "libx264", "-crf", "30"]),

‎website/pages/changelog.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,5 +872,8 @@ Major breaking release that overhauls how time is managed. Rather than assigning
872872
- [bugfix] `FrameTimecode.get_timecode()` with `use_rounding=False` now truncates instead of sometimes rounding up the last digit. Previously 0.4996 seconds with `precision=2` gave `00:00:00.50`, and 1.99997 seconds gave `00:00:01.000` instead of `00:00:01.999`. [#611](https://github.com/Breakthrough/PySceneDetect/issues/611)
873873
- [bugfix] `FrameTimecode.get_timecode()` now shows a negative time (e.g. from a negative PTS) as zero. Previously a large negative time gave output such as `-1:-6:00.000`. A negative `precision` now raises a `ValueError`
874874
- [bugfix] Allow image sequences as inputs when the default backend is already OpenCV [#620](https://github.com/Breakthrough/PySceneDetect/issues/620)
875+
- [bugfix] Ignore extra ASCII spaces in `split-video -a`/`--args` and `split_video_ffmpeg(arg_override=...)` instead of passing empty arguments to ffmpeg, so doubled spaces no longer pass empty values [#634](https://github.com/Breakthrough/PySceneDetect/issues/634)
876+
- Breaking: an all-space CLI `-a` is treated like `-a ""` or an unset `-a`, using config-file arguments and then built-in defaults
877+
- Breaking: an empty or all-space API `arg_override` adds no encoding or -map arguments to the ffmpeg command, instead of failing
875878
- [general] Updates to Windows distributions:
876879
- Python 3.13 -> Python 3.14

0 commit comments

Comments
 (0)