FFMPEG wrapper for Python
imageio-ffmpeg is a Python library that provides a convenient wrapper around the FFMPEG executable, enabling Python applications to easily read and write video files. It bundles pre-compiled FFMPEG binaries for various platforms, simplifying deployment. The current version is 0.6.0, and it generally follows a release cadence tied to bug fixes, dependency updates, and new platform support.
Warnings
- breaking Starting from version 0.5.0, imageio-ffmpeg requires Python 3.9 or newer. Users on older Python versions (e.g., Python 3.8 or earlier) will encounter installation failures or runtime errors.
- gotcha Although imageio-ffmpeg bundles pre-compiled FFMPEG binaries, sometimes these might not be compatible with specific system configurations or users may prefer to use a system-wide or custom FFMPEG installation. If you encounter issues like 'ffmpeg not found' or unexpected encoding failures, verify the FFMPEG executable path.
- gotcha imageio-ffmpeg can be used as a standalone wrapper for FFMPEG, but it's primarily designed to be a backend for the `imageio` library for video I/O. Users sometimes confuse when to import `imageio` vs. `imageio_ffmpeg`. For higher-level, more abstract video operations integrated with image processing, `imageio` is often sufficient. For direct, lower-level control over FFMPEG parameters, `imageio_ffmpeg` is the correct choice.
- deprecated In version 0.5.0, imageio-ffmpeg migrated from using `pkg_resources` to `importlib.resources` for internal resource management. While this generally doesn't affect standard API usage, any advanced users who relied on direct interaction with `imageio-ffmpeg`'s internal resource loading mechanisms via `pkg_resources` might experience breaking changes.
Install
-
pip install imageio-ffmpeg
Imports
- imageio_ffmpeg
import imageio_ffmpeg as iio_ffmpeg
Quickstart
import imageio_ffmpeg as iio_ffmpeg
import numpy as np
# Define video parameters
filename = 'my_video_output.mp4'
width, height = 640, 480
fps = 30
num_frames = 100
print(f"Using FFMPEG executable: {iio_ffmpeg.get_ffmpeg_exe()}")
try:
# Initialize the writer
writer = iio_ffmpeg.write_frames(filename, (width, height), fps=fps)
writer.send(None) # Start the pipe
for i in range(num_frames):
# Create a simple frame: black background with a moving red square
frame = np.zeros((height, width, 3), dtype=np.uint8)
x_offset = (i * 5) % (width - 100) # Move square across width
frame[50:150, x_offset : x_offset + 100] = [255, 0, 0] # Red square
writer.send(frame)
writer.close()
print(f"Video saved to {filename}")
except Exception as e:
print(f"An error occurred: {e}")
print("Ensure FFMPEG is correctly configured or its bundled binary is accessible.")