diff --git a/scenedetect/_cli/context.py b/scenedetect/_cli/context.py index c367e08d..266f3658 100644 --- a/scenedetect/_cli/context.py +++ b/scenedetect/_cli/context.py @@ -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.", @@ -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!", diff --git a/tests/test_cli.py b/tests/test_cli.py index e333b7a7..40b9f892 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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 (