ffmpy3¶
-
exception
ffmpy3.FFExecutableNotFoundError[source]¶ Raised when FFmpeg/FFprobe executable was not found.
-
exception
ffmpy3.FFRuntimeError(cmd, exit_code, stdout=b'', stderr=b'')[source]¶ Raised when FFmpeg/FFprobe command line execution returns a non-zero exit code.
-
class
ffmpy3.FFmpeg(executable='ffmpeg', global_options=None, inputs=None, outputs=None)[source]¶ Wrapper for various FFmpeg related applications (ffmpeg, ffprobe).
Compiles FFmpeg command line from passed arguments (executable path, options, inputs and outputs).
inputsandoutputsare dictionaries 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).
Parameters: - executable (str) – path to ffmpeg executable; by default the
ffmpegcommand will be searched for in thePATH, but can be overridden with an absolute path toffmpegexecutable - global_options (iterable) – global options passed to
ffmpegexecutable (e.g.-y,-vetc.); 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)[source]¶ Execute FFmpeg command line.
input_datacan contain input for FFmpeg in case pipe protocol is used for input.stdoutandstderrspecify where to redirect thestdoutandstderrof 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
pipeprotocol is used for output,stdoutmust be redirected to a pipe by passing subprocess.PIPE asstdoutargument.Returns a 2-tuple containing
stdoutandstderrof 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 actualstdoutandstderrdata returned by ffmpeg process.Parameters: - input_data (bytes) – input data for FFmpeg to deal with (audio, video etc.) as bytes (e.g. the result of reading a file in binary mode)
- stdout – Where to redirect FFmpeg
stdoutto. Default is None, meaning no redirection. - stderr – Where to redirect FFmpeg
stderrto. Default is None, meaning no redirection.
Raises: FFExecutableNotFoundError– The executable path passed was not valid.FFRuntimeError– The process exited with an error.
Returns: A 2-tuple containing
stdoutandstderrfrom the process.Return type:
-
run_async(input_data=None, stdout=None, stderr=None)[source]¶ Asynchronously execute FFmpeg command line.
input_datacan contain input for FFmpeg in case pipestdoutandstderrspecify where to redirect thestdoutandstderrof 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
pipeprotocol is used for output,stdoutmust be redirected to a pipe by passing subprocess.PIPE asstdoutargument.Note that the parent process is responsible for reading any output from stdout/stderr. This should be done even if the output will not be used since the process may otherwise deadlock. This can be done by awaiting on
asyncio.subprocess.Process.communicate()on the returnedasyncio.subprocess.Processor by manually reading from the streams as necessary.Returns a reference to the child process created for use by the parent program.
Parameters: - input_data (bytes) – input data for FFmpeg to deal with (audio, video etc.) as bytes (e.g. the result of reading a file in binary mode)
- stdout – Where to redirect FFmpeg
stdoutto. Default is None, meaning no redirection. - stderr – Where to redirect FFmpeg
stderrto. Default is None, meaning no redirection.
Raises: FFExecutableNotFoundError– The executable path passed was not valid.Returns: The child process created.
Return type: asyncio.subprocess.Process
-
wait()[source]¶ Asynchronously wait for the process to complete execution.
Raises: FFRuntimeError– The process exited with an error.Returns: 0 if the process finished successfully, or None if it has not been started Return type: int or None
- executable (str) – path to ffmpeg executable; by default the
-
class
ffmpy3.FFprobe(executable='ffprobe', global_options='', inputs=None)[source]¶ Wrapper for ffprobe.
Compiles FFprobe command line from passed arguments (executable path, options, inputs). FFprobe executable by default is taken from
PATHbut can be overridden with an absolute path.Parameters: - executable (str) – absolute path to ffprobe executable
- global_options (iterable) – global options passed to ffprobe 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