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
35 changes: 35 additions & 0 deletions rffmpeg
Original file line number Diff line number Diff line change
Expand Up @@ -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=""):
"""
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions rffmpeg.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,9 @@ rffmpeg:
#special_flags:
# - "-muxers"
# - "-fp_format"

# Specific rules to tell rffmpeg when to use the fallback ffmpeg/ffprobe
fallback_rules:
- match: ["-vf blackframe", "-f null"] # Intro Skipper
- match: ["-f chromaprint"] # chromaprint analyzer
- match: ["-ss 0", "-to 2"] # very short clip scans