Merge c81e246846407bb6134726eb6a1afbd139cdcf51 into df129c7ba30aaa9ffffb81a48f53aa7253b0b4e6

This commit is contained in:
Mattia Lecci 2023-03-06 17:03:43 +00:00 committed by GitHub
commit 3183e98a51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 11 deletions

View File

@ -26,7 +26,7 @@ def generate_thumbnail(in_filename, out_filename, time, width):
.run(capture_stdout=True, capture_stderr=True) .run(capture_stdout=True, capture_stderr=True)
) )
except ffmpeg.Error as e: except ffmpeg.Error as e:
print(e.stderr.decode(), file=sys.stderr) print(f"$ {e.cmdline}\n{e.stderr.decode()}", file=sys.stderr)
sys.exit(1) sys.exit(1)

View File

@ -125,6 +125,6 @@ if __name__ == '__main__':
.run(capture_stdout=True, capture_stderr=True) .run(capture_stdout=True, capture_stderr=True)
) )
except ffmpeg.Error as e: except ffmpeg.Error as e:
print(e.stderr, file=sys.stderr) print(f"$ {e.cmdline}\n{e.stderr.decode()}", file=sys.stderr)
sys.exit(1) sys.exit(1)

View File

@ -27,7 +27,7 @@ def decode_audio(in_filename, **input_kwargs):
.run(capture_stdout=True, capture_stderr=True) .run(capture_stdout=True, capture_stderr=True)
) )
except ffmpeg.Error as e: except ffmpeg.Error as e:
print(e.stderr, file=sys.stderr) print(f"$ {e.cmdline}\n{e.stderr.decode()}", file=sys.stderr)
sys.exit(1) sys.exit(1)
return out return out

View File

@ -15,7 +15,7 @@ if __name__ == '__main__':
try: try:
probe = ffmpeg.probe(args.in_filename) probe = ffmpeg.probe(args.in_filename)
except ffmpeg.Error as e: except ffmpeg.Error as e:
print(e.stderr, file=sys.stderr) print(f"$ {e.cmdline}\n{e.stderr.decode()}", file=sys.stderr)
sys.exit(1) sys.exit(1)
video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None) video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)

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)