Skip to content

Commit da60b07

Browse files
leninworldBreakthrough
authored andcommitted
[bugfix] Ignore extra spaces in ffmpeg arguments (#634)
1 parent 02ee58d commit da60b07

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎scenedetect/output/video.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def split_video_ffmpeg(
313313
arg_override = arg_override.replace('\\"', '"')
314314

315315
ret_val = 0
316-
ffmpeg_args = arg_override.split(" ")
316+
ffmpeg_args = [arg for arg in arg_override.split(" ") if arg]
317317
scene_num_format = "%0"
318318
scene_num_format += str(max(3, math.floor(math.log(len(scene_list), 10)) + 1)) + "d"
319319

‎tests/test_output.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,33 @@ def name_formatter(video: VideoMetadata, scene: SceneMetadata):
106106
assert len(entries) == len(scenes)
107107

108108

109+
@pytest.mark.parametrize(
110+
("arg_override", "expected"),
111+
[
112+
("-c:v libx264 -crf 30", ["-c:v", "libx264", "-crf", "30"]),
113+
(" -c:v libx264 -crf 30", ["-c:v", "libx264", "-crf", "30"]),
114+
("-c:v libx264 -crf 30 ", ["-c:v", "libx264", "-crf", "30"]),
115+
(" -c:v libx264 -crf 30 ", ["-c:v", "libx264", "-crf", "30"]),
116+
("-metadata title=a\u3000b", ["-metadata", "title=a\u3000b"]),
117+
],
118+
)
119+
def test_split_video_ffmpeg_arg_override_whitespace(tmp_path, monkeypatch, arg_override, expected):
120+
calls = []
121+
monkeypatch.setattr(
122+
"scenedetect.output.video.invoke_command", lambda call: calls.append(call) or 0
123+
)
124+
scenes = [(FrameTimecode(0, 30.0), FrameTimecode(30, 30.0))]
125+
126+
assert (
127+
split_video_ffmpeg("video.mp4", scenes, output_dir=tmp_path, arg_override=arg_override) == 0
128+
)
129+
130+
assert len(calls) == 1
131+
duration_index = calls[0].index("-t")
132+
assert calls[0][duration_index + 2 : -2] == expected
133+
assert calls[0][-2:] == ["-sn", str(tmp_path / "video-Scene-001.mp4")]
134+
135+
109136
# TODO: Add tests for `split_video_mkvmerge`.
110137

111138

0 commit comments

Comments
 (0)