From c4597a35d8ed226b21766826d774808cb58a0480 Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 23 Oct 2025 03:14:15 +0200 Subject: [PATCH] Implement fallback rules for ffmpeg execution Added fallback rules for ffmpeg commands to handle errors gracefully. --- rffmpeg | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/rffmpeg b/rffmpeg index 5610a3e..e74821d 100755 --- a/rffmpeg +++ b/rffmpeg @@ -226,11 +226,28 @@ def load_config(): "-fp_format", ] + config_commands.get("special_flags", []) + # Parse fallback rules (optional) + config["fallback_rules"] = config_base.get("fallback_rules", []) + # Set the current PID of this process config["current_pid"] = os.getpid() return config +def should_use_fallback(config, ffmpeg_args): + """ + Check configured fallback_rules and decide whether to force fallback. + """ + rules = config.get("fallback_rules", []) + joined_args = " ".join(ffmpeg_args).lower() + + for rule in rules: + patterns = [p.lower() for p in rule.get("match", [])] + if all(p in joined_args for p in patterns): + log.info(f"[rffmpeg] Matched fallback rule: {patterns}") + return True + + return False def cleanup(signum="", frame=""): """ @@ -553,6 +570,24 @@ def run_ffmpeg(config, ffmpeg_args): setup_logging(config) + # Determine if we should use fallback ffmpeg/ffprobe + use_fallback = should_use_fallback(config, ffmpeg_args) + if use_fallback: + if "ffprobe" in cmd_name: + ret = run_local_command( + config, None, cmd_name, ffmpeg_args, + mapped_cmd=config["fallback_ffprobe_command"] + ) + else: + ret = run_local_command( + config, None, cmd_name, ffmpeg_args, + stderr_as_stdout=not any(item in config["special_flags"] for item in ffmpeg_args), + mapped_cmd=config["fallback_ffmpeg_command"] + ) + cleanup() + log.info(f"[rffmpeg] Finished fallback run with return code {ret.returncode}") + exit(ret.returncode) + log.info(f"Starting rffmpeg as {cmd_name} with args: {' '.join(ffmpeg_args)}") target_hid, target_hostname, target_servername = get_target_host(config)