Skip to main content

TensorCodec

CPU video/audio decoding with TorchCodec-style APIs and NumPy output.

CI PyPI Python Wheel download License: MIT

Quick start · Features · Package size · Compatibility

  • TorchCodec API without PyTorch. CPU video/audio decoder interfaces follow TorchCodec and return NumPy arrays.
  • Validated playback semantics. Frame selection, ordering, timestamps and audio ranges are checked against TorchCodec 0.17.0 and independently generated media.
  • Efficient batch decoding. Rust/PyO3 bindings to FFmpeg process frame batches in a single native call, avoiding per-frame Python calls.
  • Lightweight installation. Linux wheels are 10.2–10.4 MiB (v0.1.2), including FFmpeg shared libraries. NumPy is the only Python dependency.

Quick start

uv pip install tensorcodec

Use an existing virtual environment, or create one with uv venv first. No separate FFmpeg installation is needed for the published Linux wheels.

from tensorcodec.decoders import VideoDecoder, AudioDecoder

with VideoDecoder("video.mp4") as video:
    frame = video[0]                                  # RGB array: (C, H, W)
    batch = video.get_frames_at([4, 0, 4])              # requested order, including duplicates
    clip = video.get_frames_played_in_range(0, 1, fps=8)

with AudioDecoder("audio.wav", sample_rate=16000, num_channels=1) as audio:
    samples = audio.get_samples_played_in_range(0, 1)
    waveform = samples.data                           # float32: (channels, samples)

Arrays keep their storage after the decoder closes. Paths, URLs, encoded bytes, 1-D uint8 arrays and seekable file objects are supported.

Features

TensorCodec 0.1.3 relative to TorchCodec 0.17.0. ✓ supported · △ partial support · — not implemented.

Component TensorCodec TorchCodec 0.17.0
Video decoder △ CPU, SDR/HDR RGB ✓ CPU / CUDA
Audio decoder ✓ CPU ✓ CPU
Image decoders — ✓
Video / audio / image encoders — ✓
Clip samplers — ✓
Decoder transforms — ✓

FPS-based frame queries are supported; clip samplers are a separate API.

Decoder compatibility

Capability TensorCodec TorchCodec 0.17.0
Index / slice / batch selection ✓ ✓
Playback timestamp / range queries ✓ ✓
Request order and duplicate frames Preserved Preserved
Exact / approximate seeking ✓ Default: exact ✓
FPS queries / custom frame mappings ✓ ✓
CFR / VFR / offset PTS / B-frames ✓ Tested ✓
NCHW / NHWC RGB output ✓ ✓
uint8 / float32 / automatic dtype ✓ SDR and high-bit-depth video ✓
uint16 RGB output ✓ Full-range RGB48 —
Native grayscale/depth and packed RGB(A) ✓ Values preserved —
PQ / HLG decoding ✓ Transfer-encoded RGB ✓
Right-angle display rotation ✓ ✓
Audio ranges / resampling / channel mixing ✓ float32 ✓
Paths / URLs / bytes / seekable file objects ✓ ✓
Encoded array input 1-D uint8 NumPy array PyTorch tensor
Decoded output NumPy array; array interface / DLPack PyTorch tensor
CUDA decoding — ✓

For high-bit-depth video, use VideoDecoder(path, output_dtype="auto") to select float32 above 8 bits, or output_dtype="uint16" for full-range 16-bit RGB. HDR output retains PQ/HLG encoding without SDR tone mapping. Rotation is applied automatically, and metadata dimensions match the output.

For unmodified samples, use VideoDecoder(path, output_format="native"). Supported formats: gray, gray12le, gray16le/be, rgb24, rgba. Native output preserves channel count, integer values and pixel coordinates; expected_pixel_format optionally asserts the source format.

Package size

Linux CPU wheels, Python 3.12. Download / unpacked size in MiB.

Package x86_64 ARM64
TensorCodec 10.2 / 24.7 10.4 / 22.9
PyAV 33.4 / 125.5 31.2 / 90.4
TorchCodec + PyTorch (CPU) 196.7 / 704.7 160.3 / 585.7

TensorCodec and PyAV bundle FFmpeg; TorchCodec needs it separately. Other dependencies are excluded. Measurements.

Scope and compatibility

The supported CPU API is checked for frame selection, ordering, timestamps, durations, stream selection and metadata, both against TorchCodec 0.17.0 and independently generated media.

  • Pixel comparisons allow color-conversion rounding of at most 1 uint8 unit or 1/65535 for float32 in the tested cases.
  • Empty index lists are supported, including the case affected by the reference's empty-list dtype inference bug.
  • NumPy output preserves the decoder API structure; callers expecting torch.Tensor must adapt their array handling.

See the compatibility contract and playback rules for the tested behavior.

Current limits

  • Wheels: Linux x86_64 and ARM64 (aarch64), glibc 2.17+, CPython 3.10+. NumPy must also provide a compatible wheel; newer Python versions may require a newer glibc. macOS 14+ wheels support ARM64 and x86_64. Windows, musl/Alpine and free-threaded Python wheels are not provided.
  • Exact seeking: scans packet timestamps when opening the decoder. Incorrect container keyframe flags can produce corrupt frames; repaired input or corrected frame mappings are needed in that case.
  • Audio ranges: decode from the beginning, so late ranges can be expensive.
  • Video conversion: no HDR-to-SDR tone mapping or native YUV-plane output. Reflected and non-right-angle display matrices are unsupported.

See container behavior for seek limitations and benchmark tools for workload measurements.

Development and verification

Build from source and run tests

Source builds require Rust, Clang/libclang, pkg-config and FFmpeg 7 development headers/libraries. Python handles API and playback selection; Rust + PyO3 handles FFmpeg. Native decoding releases the GIL, allowing separate decoder instances to run concurrently across Python threads. Calls on the same instance are serialized. The default is one FFmpeg thread per decoder; use independent workers for concurrent windows and tune the total thread count to avoid oversubscription.

uv sync --group dev --group oracle

uv run --group oracle pytest tests/test_video_contract.py tests/test_audio_contract.py --backend torchcodec
uv run --group oracle pytest --compare

# Rebuild after changing Rust code.
uv run --group oracle maturin develop --locked --uv

Tests generate media with FFmpeg/ffprobe and Python's wave module. --compare requires the pinned oracle; differential tests otherwise skip.

Playback rules · Release guide · Dependency licenses

TensorCodec's own code is MIT licensed.

Metadata

Release files for tensorcodec 0.1.3

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

Source distribution (sdist)

Source distribution for tensorcodec 0.1.3
File Size Uploaded
tensorcodec-0.1.3.tar.gz 74.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for tensorcodec 0.1.3
File
tensorcodec-0.1.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
tensorcodec-0.1.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
tensorcodec-0.1.3-cp310-abi3-macosx_14_0_x86_64.whl CPython 3.10 abi3 macOS 14.0+ x86-64 Details
tensorcodec-0.1.3-cp310-abi3-macosx_14_0_arm64.whl CPython 3.10 abi3 macOS 14.0+ ARM64 Details

Total release size: 42.6 MB

Release files / tensorcodec-0.1.3.tar.gz

Download URL tensorcodec-0.1.3.tar.gz
Size 74.0 kB
Tags Source
SHA-256 checksum
How to use checksums
eb13fea0250604a3d95e860dc468716d46b34077dd27a607ca474f216d161088
BLAKE2b-256 checksum
How to use checksums
8d7e03a343eb9d8a4df3fe6f6680d2b99a80ad1906f26ddda02481102c8f8186
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release files / tensorcodec-0.1.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL tensorcodec-0.1.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 10.8 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
d63e20c28d664b98027536f1232a48a88202530a8d9510770446e63fd813064e
BLAKE2b-256 checksum
How to use checksums
695577552e87d29b150188055aa900247d68f95324e9bcc57f8b4f209823d33e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release files / tensorcodec-0.1.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL tensorcodec-0.1.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 11.0 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
402b13a6e5cb480359754a57cabaeec06b75aa6d2538a5371ea9f1fc809ff8bb
BLAKE2b-256 checksum
How to use checksums
3ecf82abeee6785fff909cdfbf26bb0d8b388db3cda1f9dfb92a30cdf2d6baee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release files / tensorcodec-0.1.3-cp310-abi3-macosx_14_0_x86_64.whl

Download URL tensorcodec-0.1.3-cp310-abi3-macosx_14_0_x86_64.whl
Size 10.7 MB
Tags CPython 3.10 abi3 macOS 14.0+ x86-64
SHA-256 checksum
How to use checksums
be48e051c66ca2577558cc5e234cec34f32ef60deea412328b17de7f05c0bd0c
BLAKE2b-256 checksum
How to use checksums
1360fd2b3e3a0e7310b3d4a465650a9da674183303aeb359d78bccff4da2653f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release files / tensorcodec-0.1.3-cp310-abi3-macosx_14_0_arm64.whl

Download URL tensorcodec-0.1.3-cp310-abi3-macosx_14_0_arm64.whl
Size 10.1 MB
Tags CPython 3.10 abi3 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
ac9f13cc849412aa2c991a2f668ff9858e27882a4000d149a5bbed7f0a3d16e9
BLAKE2b-256 checksum
How to use checksums
ed34ccb3e4f3d74d9b1fc5496b8753e4c49f21bf9c58a8a6a10cef5e277b9351
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.5

5 release files

0.1.4

5 release files

This release

0.1.3 This release

5 release files

0.1.2

3 release files

0.1.1

3 release files

0.1.0

2 release files

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