FramePump#

A Python library for high-performance video processing, built on PyAV (Python bindings for FFmpeg’s libraries).

This project provides:

  • Lazy, sliceable video frame access via VideoFrames

  • Threaded video writing via VideoWriter

  • Zero-copy GPU encoding via GLVideoWriter (NVENC)

  • GPU-accelerated decoding support

  • High bit depth (10-bit) video support

Installation#

pip install framepump

For zero-copy GPU encoding with headless/EGL contexts:

pip install framepump[nvenc-cuda]

Quick Start#

Reading Video Frames#

import numpy as np
from framepump import VideoFrames

# Lazy loading - only reads metadata
frames = VideoFrames('my_video.mp4')

# Iterate over frames
for frame in frames:
    # frame is a numpy array of shape (height, width, 3)
    pass

# Grab a single frame by index (decoded via a direct seek)
frame_42 = frames[42]

# Several frames at once (numpy-style), or a whole selection as an array
picked = frames[[10, 50, 300]]        # (3, height, width, 3)
clip = np.asarray(frames[120:180])    # one sequential decode pass

# Slice the video (lazy)
subset = frames[:100:2]  # Every second frame of first 100

# Resize on the fly — shape is (height, width)
resized = frames.resized((128, 128))

Writing Videos#

import numpy as np
from framepump import VideoWriter

with VideoWriter('output.mp4', fps=30) as writer:
    for i in range(100):
        frame = np.zeros((100, 100, 3), dtype=np.uint8)
        writer.append_data(frame)

Zero-Copy GPU Encoding#

For real-time rendering, encode OpenGL textures directly to video without CPU memory transfers:

from framepump import GLVideoWriter

with GLVideoWriter('output.mp4', fps=30) as writer:
    for _ in render_loop:
        render_to_texture(texture)
        ctx.finish()  # Wait for GPU to finish rendering
        writer.append_data(texture)  # Encode directly from GPU

This uses NVIDIA’s NVENC hardware encoder. See Zero-Copy OpenGL to Video Encoding with NVENC for details on how it works.

API Reference#

See the full API documentation at framepump.