ffmpy
- class ffmpy.FFmpeg(executable: str = 'ffmpeg', global_options: Sequence[str] | str | None = None, inputs: Mapping[str, Sequence[str] | str | None] | None = None, outputs: Mapping[str, Sequence[str] | str | None] | None = 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).
inputsandoutputsare 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
ffmpegcommand will be searched for in thePATH, but can be overridden with an absolute path toffmpegexecutableglobal_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 passedinputs (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: bytes | None = None, stdout: IO | int | None = None, stderr: IO | int | None = None, env: Mapping[str, str] | None = None, **kwargs: Any) Tuple[bytes | None, bytes | None][source]
Execute FFmpeg command line.
input_datacan contain input for FFmpeg in casepipeprotocol 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 FFmpegpipeprotocol is used for output,stdoutmust be redirected to a pipe by passingsubprocess.PIPEasstdoutargument. You can pass custom environment to ffmpeg process withenv.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 twoNonevalues, otherwise it will contain the actualstdoutandstderrdata returned by ffmpeg process.More info about
pipeprotocol 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
stdoutthere (default isNonewhich means no redirection)stderr – redirect FFmpeg
stderrthere (default isNonewhich 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
stdoutandstderrof the process- Return type:
- Raise:
FFRuntimeErrorin case FFmpeg command exits with a non-zero code;FFExecutableNotFoundErrorin case the executable path passed was not valid
- class ffmpy.FFprobe(executable: str = 'ffprobe', global_options: Sequence[str] | str | None = None, inputs: Mapping[str, Sequence[str] | str | None] | None = 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
PATHbut 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
- exception ffmpy.FFExecutableNotFoundError[source]
Raise when FFmpeg/FFprobe executable was not found.
- exception ffmpy.FFRuntimeError(cmd: str, exit_code: int, stdout: bytes, stderr: bytes)[source]
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.