Add cmdline to Error

Having stdout, sterr, and the command used to launch ffmpeg in Error makes debugging easier
This commit is contained in:
Mattia Lecci 2023-03-06 17:51:19 +01:00
parent df129c7ba3
commit a184551aea
3 changed files with 20 additions and 7 deletions

View File

@ -1,7 +1,7 @@
import json import json
import subprocess import subprocess
from ._run import Error from ._run import Error
from ._utils import convert_kwargs_to_cmd_line_args from ._utils import convert_kwargs_to_cmd_line_args, convert_cmd_line_args_to_cmd_line_str
def probe(filename, cmd='ffprobe', timeout=None, **kwargs): def probe(filename, cmd='ffprobe', timeout=None, **kwargs):
@ -23,7 +23,8 @@ def probe(filename, cmd='ffprobe', timeout=None, **kwargs):
communicate_kwargs['timeout'] = timeout communicate_kwargs['timeout'] = timeout
out, err = p.communicate(**communicate_kwargs) out, err = p.communicate(**communicate_kwargs)
if p.returncode != 0: if p.returncode != 0:
raise Error('ffprobe', out, err) cmdline = convert_cmd_line_args_to_cmd_line_str(args)
raise Error('ffprobe', out, err, cmdline)
return json.loads(out.decode('utf-8')) return json.loads(out.decode('utf-8'))

View File

@ -1,6 +1,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from .dag import get_outgoing_edges, topo_sort from .dag import get_outgoing_edges, topo_sort
from ._utils import basestring, convert_kwargs_to_cmd_line_args from ._utils import basestring, convert_kwargs_to_cmd_line_args, convert_cmd_line_args_to_cmd_line_str
from builtins import str from builtins import str
from functools import reduce from functools import reduce
import copy import copy
@ -24,12 +24,13 @@ except ImportError:
class Error(Exception): class Error(Exception):
def __init__(self, cmd, stdout, stderr): def __init__(self, cmd, stdout, stderr, cmdline):
super(Error, self).__init__( super(Error, self).__init__(
'{} error (see stderr output for detail)'.format(cmd) '{} error (see stderr output for detail)'.format(cmd)
) )
self.stdout = stdout self.stdout = stdout
self.stderr = stderr self.stderr = stderr
self.cmdline = cmdline
def _get_input_args(input_node): def _get_input_args(input_node):
@ -334,7 +335,9 @@ def run(
out, err = process.communicate(input) out, err = process.communicate(input)
retcode = process.poll() retcode = process.poll()
if retcode: if retcode:
raise Error('ffmpeg', out, err) args = compile(stream_spec, cmd, overwrite_output=overwrite_output)
cmdline = convert_cmd_line_args_to_cmd_line_str(args)
raise Error('ffmpeg', out, err, cmdline)
return out, err return out, err

View File

@ -2,8 +2,9 @@ from __future__ import unicode_literals
from builtins import str from builtins import str
from past.builtins import basestring from past.builtins import basestring
import hashlib import hashlib
import sys import sys, os
import subprocess
import shlex
if sys.version_info.major == 2: if sys.version_info.major == 2:
# noinspection PyUnresolvedReferences,PyShadowingBuiltins # noinspection PyUnresolvedReferences,PyShadowingBuiltins
@ -106,3 +107,11 @@ def convert_kwargs_to_cmd_line_args(kwargs):
if v is not None: if v is not None:
args.append('{}'.format(v)) args.append('{}'.format(v))
return args return args
def convert_cmd_line_args_to_cmd_line_str(args):
"""Helper function to build command line string from command line args."""
if os.name == "nt": # Windows system
return subprocess.list2cmdline(args)
# Non-windows systems
return shlex.join(args)