Skip to main content

iterframes

PyPI CI Documentation

A plain Python loop over the frames of a video, for when each frame goes through something expensive, such as a model. While your code works on one frame, FFmpeg decodes the next ones on a background thread, written in Rust, that never takes the GIL. Decoding overlaps with your work instead of adding to it.

import iterframes

for frame in iterframes.read("video.mp4"):
    model(frame)  # frame is a (height, width, 3) uint8 array of RGB pixels

# Resize while decoding
for frame in iterframes.read("video.mp4", height=224, width=224):
    ...

Hardware decoding

Pass device to decode on a GPU instead of the CPU, which then stays free for your model. The names are PyTorch's:

# NVIDIA GPU on Linux; with height and width, the GPU resizes too
for frame in iterframes.read("video.mp4", height=224, width=224, device="cuda"):
    ...

# Apple silicon (VideoToolbox)
for frame in iterframes.read("video.mp4", device="mps"):
    ...

# Whatever the machine has, else the CPU
for frame in iterframes.read("video.mp4", device="auto"):
    ...

print(iterframes.DEVICES)  # ('cpu', 'mps') on a Mac

By default the frames still arrive as NumPy arrays in memory. A GPU saves CPU time but is not always faster than the CPU decoder, so measure both; see Hardware decoding.

With an NVIDIA GPU, on_device=True keeps the frames on it, in NV12, for PyTorch and other libraries to take without a copy:

import torch

for frame in iterframes.read("video.mp4", device="cuda", on_device=True):
    y = torch.from_dlpack(frame.y)    # (height, width) uint8, on the GPU
    uv = torch.from_dlpack(frame.uv)  # (height / 2, width / 2, 2)

Frames on the GPU shows how to convert them to RGB there.

Installation

pip install iterframes

The wheels bundle FFmpeg and work on any CPython from 3.11 on, on Linux (x86_64, aarch64) and macOS (Apple silicon).

Documentation

https://iterframes.readthedocs.io: reference and development guide.

License

iterframes is released under the LGPL-3.0. The wheels include FFmpeg, built under the LGPL, and dav1d, under the BSD 2-clause license.

Metadata

Release files for iterframes 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iterframes 0.4.0
File Size Uploaded
iterframes-0.4.0.tar.gz 1.2 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for iterframes 0.4.0
File Interpreter ABI Platform
iterframes-0.4.0-cp311-abi3-manylinux_2_28_x86_64.whl CPython 3.11 abi3 Linux glibc 2.28+ x86-64 Details
iterframes-0.4.0-cp311-abi3-manylinux_2_28_aarch64.whl CPython 3.11 abi3 Linux glibc 2.28+ ARM64 Details
iterframes-0.4.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details

Total release size: 28.5 MB

Release files / iterframes-0.4.0.tar.gz

Download URL iterframes-0.4.0.tar.gz
Size 1.2 MB
Tags Source
SHA-256 checksum
How to use checksums
afd1348b0c603c8037fa078fdc9797edca0b5c8c122e47b60a3fcbfc6a12e0b3
BLAKE2b-256 checksum
How to use checksums
4b98f9fa6c4e276fae5e75202b166ffc83cecf479516323debbb9c193bbdc262
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / iterframes-0.4.0-cp311-abi3-manylinux_2_28_x86_64.whl

Download URL iterframes-0.4.0-cp311-abi3-manylinux_2_28_x86_64.whl
Size 10.1 MB
Tags CPython 3.11 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
dc5446ba8679f6c0ad56d19051b8f5f386cc86783258bb275c7634f2547cb0e3
BLAKE2b-256 checksum
How to use checksums
b86c7fe5493bd6faca1d8ef6f8121df8e0e3f626f8c45899edea3bd246152b24
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / iterframes-0.4.0-cp311-abi3-manylinux_2_28_aarch64.whl

Download URL iterframes-0.4.0-cp311-abi3-manylinux_2_28_aarch64.whl
Size 9.5 MB
Tags CPython 3.11 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
b9efa75569e8f2a869572cb46077d5edcd220ee42e24f1a2a3ee599ab746ca21
BLAKE2b-256 checksum
How to use checksums
2ac42d4524ca3c14fc1fb73238c55ab9e2c374a5e215d8dd488c39698c4db35f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / iterframes-0.4.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL iterframes-0.4.0-cp311-abi3-macosx_11_0_arm64.whl
Size 7.7 MB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
24ebfec0b8a8874c340e2457b6f340f7bf83e0187c5a9568061d79dc4a709a76
BLAKE2b-256 checksum
How to use checksums
f8a7d0a10877c0b46299d295bcd94eb0b337e662aaf1b733a672ea25dcf4fd2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.7.0

5 release files

0.6.0

5 release files

0.5.0

5 release files

This release

0.4.0 This release

4 release files

0.2.0

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page