improve ffprobe error reporting

This commit is contained in:
Josh Hawkins 2025-10-23 08:13:15 -05:00
parent f388b4c45a
commit 33aae8c4e9
2 changed files with 25 additions and 14 deletions

View File

@ -199,18 +199,29 @@ def ffprobe(request: Request, paths: str = "", detailed: bool = False):
request.app.frigate_config.ffmpeg, path.strip(), detailed=detailed request.app.frigate_config.ffmpeg, path.strip(), detailed=detailed
) )
if ffprobe.returncode != 0:
try:
stderr_decoded = ffprobe.stderr.decode("utf-8")
except UnicodeDecodeError:
try:
stderr_decoded = ffprobe.stderr.decode("unicode_escape")
except Exception:
stderr_decoded = str(ffprobe.stderr)
stderr_lines = [
line.strip() for line in stderr_decoded.split("\n") if line.strip()
]
result = { result = {
"return_code": ffprobe.returncode, "return_code": ffprobe.returncode,
"stderr": ( "stderr": stderr_lines,
ffprobe.stderr.decode("unicode_escape").strip() "stdout": "",
if ffprobe.returncode != 0 }
else "" else:
), result = {
"stdout": ( "return_code": ffprobe.returncode,
json.loads(ffprobe.stdout.decode("unicode_escape").strip()) "stderr": [],
if ffprobe.returncode == 0 "stdout": json.loads(ffprobe.stdout.decode("unicode_escape").strip()),
else ""
),
} }
# Add detailed metadata if requested and probe was successful # Add detailed metadata if requested and probe was successful

View File

@ -577,7 +577,7 @@ def ffprobe_stream(ffmpeg, path: str, detailed: bool = False) -> sp.CompletedPro
if detailed and format_entries: if detailed and format_entries:
ffprobe_cmd.extend(["-show_entries", f"format={format_entries}"]) ffprobe_cmd.extend(["-show_entries", f"format={format_entries}"])
ffprobe_cmd.extend(["-loglevel", "quiet", clean_path]) ffprobe_cmd.extend(["-loglevel", "error", clean_path])
return sp.run(ffprobe_cmd, capture_output=True) return sp.run(ffprobe_cmd, capture_output=True)