ffmpy¶
-
class
ffmpy.
FFmpeg
(executable='ffmpeg', global_options=None, inputs=None, outputs=None)[source]¶ 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
andoutputs
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 callingsplit()
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.Parameters: - executable (str) – path to ffmpeg executable; by default the
ffmpeg
command will be searched for in thePATH
, but can be overridden with an absolute path toffmpeg
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, env=None, **kwargs)[source]¶ Execute FFmpeg command line.
input_data
can contain input for FFmpeg in casepipe
protocol is used for input.stdout
andstderr
specify where to redirect thestdout
andstderr
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 FFmpegpipe
protocol is used for output,stdout
must be redirected to a pipe by passingsubprocess.PIPE
asstdout
argument. You can pass custom environment to ffmpeg process withenv
.Returns a 2-tuple containing
stdout
andstderr
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 twoNone
values, otherwise it will contain the actualstdout
andstderr
data returned by ffmpeg process.More info about
pipe
protocol here.Parameters: - 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 isNone
which means no redirection) - stderr – redirect FFmpeg
stderr
there (default isNone
which means no redirection) - env – custom environment for ffmpeg process
- kwargs – any other keyword arguments to be forwarded to subprocess.Popen
Returns: a 2-tuple containing
stdout
andstderr
of the processReturn type: Raise: FFRuntimeError
in case FFmpeg command exits with a non-zero code;FFExecutableNotFoundError
in case the executable path passed was not valid
- executable (str) – path to ffmpeg executable; by default the
-
class
ffmpy.
FFprobe
(executable='ffprobe', global_options='', inputs=None)[source]¶ 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.Parameters: - 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