ffmpy

class ffmpy.FFmpeg(executable='ffmpeg', global_options=None, inputs=None, outputs=None)[源代码]

Wrapper for various FFmpeg related applications (ffmpeg, ffprobe).

Initialize FFmpeg command line wrapper.

Compiles FFmpeg command line from passed arguments (executable path, options, inputs and outputs). inputs and outputs are dictionares containing inputs/outputs as keys and their respective options as values. One dictionary value (set of options) must be either a single space separated string, or a list or strings without spaces (i.e. each part of the option is a separate item of the list, the result of calling split() on the options string). If the value is a list, it cannot be mixed, i.e. cannot contain items with spaces. An exception are complex FFmpeg command lines that contain quotes: the quoted part must be one string, even if it contains spaces (see Examples for more info). For more info about FFmpeg command line format see here.

参数:
  • executable (str) – path to ffmpeg executable; by default the ffmpeg command will be searched for in the PATH, but can be overridden with an absolute path to ffmpeg executable
  • global_options (iterable) – global options passed to ffmpeg executable (e.g. -y, -v etc.); can be specified either as a list/tuple/set of strings, or one space-separated string; by default no global options are passed
  • inputs (dict) – a dictionary specifying one or more input arguments as keys with their corresponding options (either as a list of strings or a single space separated string) as values
  • outputs (dict) – a dictionary specifying one or more output arguments as keys with their corresponding options (either as a list of strings or a single space separated string) as values
run(input_data=None, stdout=None, stderr=None)[源代码]

Execute FFmpeg command line.

input_data can contain input for FFmpeg in case pipe protocol is used for input. stdout and stderr specify where to redirect the stdout and stderr of the process. By default no redirection is done, which means all output goes to running shell (this mode should normally only be used for debugging purposes). If FFmpeg pipe protocol is used for output, stdout must be redirected to a pipe by passing subprocess.PIPE as stdout argument.

Returns a 2-tuple containing stdout and stderr of the process. If there was no redirection or if the output was redirected to e.g. os.devnull, the value returned will be a tuple of two None values, otherwise it will contain the actual stdout and stderr data returned by ffmpeg process.

More info about pipe protocol here.

参数:
  • input_data (str) – input data for FFmpeg to deal with (audio, video etc.) as bytes (e.g. the result of reading a file in binary mode)
  • stdout – redirect FFmpeg stdout there (default is None which means no redirection)
  • stderr – redirect FFmpeg stderr there (default is None which means no redirection)
返回:

a 2-tuple containing stdout and stderr of the process

返回类型:

tuple

Raise:

FFRuntimeError in case FFmpeg command exits with a non-zero code; FFExecutableNotFoundError in case the executable path passed was not valid

class ffmpy.FFprobe(executable='ffprobe', global_options='', inputs=None)[源代码]

Wrapper for ffprobe.

Create an instance of FFprobe.

Compiles FFprobe command line from passed arguments (executable path, options, inputs). FFprobe executable by default is taken from PATH but can be overridden with an absolute path. For more info about FFprobe command line format see here.

参数:
  • executable (str) – absolute path to ffprobe executable
  • global_options (iterable) – global options passed to ffmpeg executable; can be specified either as a list/tuple of strings or a space-separated string
  • inputs (dict) – a dictionary specifying one or more inputs as keys with their corresponding options as values
exception ffmpy.FFExecutableNotFoundError[源代码]

Raise when FFmpeg/FFprobe executable was not found.

exception ffmpy.FFRuntimeError(cmd, exit_code, stdout, stderr)[源代码]

Raise when FFmpeg/FFprobe command line execution returns a non-zero exit code.

The resulting exception object will contain the attributes relates to command line execution: cmd, exit_code, stdout, stderr.