Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion scenedetect/_cli/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,8 @@ def _open_video_stream(
backend: str | None,
):
input_hint = "--stdin" if self.use_stdin else "-i/--input"
# The backend may come from the config file or its default (opencv), not just -b/--backend.
backend = self.config.get_value("global", "backend", backend)
if input_path is not None and "%" in input_path and backend != "opencv":
raise click.BadParameter(
"The OpenCV backend (`--backend opencv`) must be used to process image sequences.",
Expand All @@ -566,7 +568,6 @@ def _open_video_stream(
if frame_rate is not None and frame_rate < MAX_FPS_DELTA:
raise click.BadParameter("Invalid frame rate specified!", param_hint="-f/--frame-rate")
try:
backend = self.config.get_value("global", "backend", backend)
if backend not in AVAILABLE_BACKENDS:
raise click.BadParameter(
f"Specified backend {backend} is not available on this system!",
Expand Down
25 changes: 25 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,31 @@ def test_cli_backend(backend_type: str):
)


def test_cli_image_sequence_uses_default_backend(test_image_sequence: str):
"""An image sequence works without -b/--backend, since opencv is the default backend."""
exit_code, output = invoke_cli(["-i", test_image_sequence, "-f", "30", "detect-content"])
assert exit_code == 0, output


def test_cli_image_sequence_uses_config_backend(tmp_path: Path, test_image_sequence: str):
"""`backend = opencv` in a config file is honored by the image sequence check."""
config_path = tmp_path.joinpath("config.cfg")
config_path.write_text("[global]\nbackend = opencv\n")
exit_code, output = invoke_cli(
["-c", str(config_path), "-i", test_image_sequence, "-f", "30", "detect-content"]
)
assert exit_code == 0, output


def test_cli_image_sequence_rejects_other_backend(tmp_path: Path, test_image_sequence: str):
"""Other backends still can't open image sequences and give a usage error."""
config_path = tmp_path.joinpath("config.cfg")
config_path.write_text("[global]\nbackend = moviepy\n")
exit_code, output = invoke_cli(["-c", str(config_path), "-i", test_image_sequence])
assert exit_code != 0
assert "must be used to process image sequences" in output


def test_cli_backend_unsupported():
"""Ensure setting an invalid backend returns an error."""
assert (
Expand Down
Loading