ffmpeg-python

1.4 · active · verified Wed Apr 15

The `ffmpeg` Python package (often referred to as `ffmpeg-python`) provides a lightweight, fluent Python wrapper for the `ffmpeg` command-line tool. It enables programmatic construction of `ffmpeg` commands, management of audio/video streams, application of filters, and format conversions. It currently stands at version 1.4, with its release cadence tied to upstream `ffmpeg` tool features and community contributions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to construct and compile an `ffmpeg` command using the Python wrapper. To execute the command (e.g., `ffmpeg.run()`), the `ffmpeg` command-line tool must be installed separately on your system, and input files like `input.mp4` must exist.

import ffmpeg
import os

# This quickstart demonstrates compiling an ffmpeg command.
# To actually run it, you would need 'input.mp4' to exist
# and the ffmpeg CLI tool to be installed and in your PATH.
# For full execution, replace 'input.mp4' with an actual file
# and remove the '.compile()' to use '.run()'.

# Example: Generate an ffmpeg command to re-encode a video
# without actually running it, useful for inspection.
command_list = (
    ffmpeg.input('input.mp4')
    .output('output_resized.mp4', vf='scale=1280:-1')
    .compile()
)

print(f"Generated ffmpeg command: {' '.join(command_list)}")

# Example: Probe a (potentially non-existent) file to get its metadata
# For this to run successfully, 'input.mp4' would need to exist
# and the ffmpeg CLI tool must be installed.
# try:
#     probe_info = ffmpeg.probe('input.mp4')
#     print("Probe information:")
#     print(probe_info)
# except ffmpeg.Error as e:
#     print(f"Error probing file: {e.stderr.decode()}")

view raw JSON →