FFMPEG wrapper for Python

0.6.0 · active · verified Wed Apr 08

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

Install

Imports

Quickstart

This quickstart demonstrates how to use `imageio-ffmpeg` to write a simple video file (e.g., an MP4 with a moving red square). It initializes a video writer, generates a series of NumPy arrays representing frames, and sends them to the FFMPEG process. It also shows how to check the FFMPEG executable path being used.

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.")

view raw JSON →