Skip to main content

TensorCodec

TorchCodec-style video and audio decoding, without PyTorch.

  • Use the CPU decoder API and playback rules of TorchCodec 0.17.0.
  • Get NumPy arrays instead of torch.Tensor.
  • Install NumPy + TensorCodec. No Torch, PyAV, or FFmpeg CLI at runtime.

The goal is predictable frame selection, timestamps and audio ranges with a small runtime dependency set. This is a CPU decoding subset, not the entire TorchCodec package. It does not promise a speedup over PyAV or TorchCodec.

What is available?

Capability TorchCodec 0.17.0 TensorCodec 0.1.0
Python runtime dependency PyTorch NumPy
Output arrays torch.Tensor numpy.ndarray; array interface + DLPack
Video index/slice/batch access Supported Supported
Playback time/range access Supported Supported
CFR, VFR, offset PTS, B-frames Supported Tested
Request ordering and duplicates Preserved Preserved
Exact / approximate seeking Supported Supported; exact is the default
NCHW / NHWC RGB Supported Supported
uint8 / float32 video Supported Supported for SDR
FPS sampling, custom frame mappings Supported Supported
Audio ranges, resampling, channel mixing Supported Supported; float32 output
Paths, URLs, bytes, seekable file objects Supported Supported
Encoded tensor input torch.Tensor 1-D uint8 NumPy arrays
CUDA decoding Supported Not implemented
Decoder transforms Supported Not implemented
HDR inputs / display rotation Supported Rejected explicitly
Other modules, including samplers/encoders Available Outside the initial scope

Compatibility means

  • Match the supported CPU API's frame selection, ordering, timing and metadata.
  • Check behavior independently and against pinned TorchCodec 0.17.0.
  • Allow color-conversion rounding: at most 1 uint8 unit or 1/65535 for float32 in the tested cases. Do not claim identical pixels across every FFmpeg build.
  • Accept empty index lists, including the case affected by the reference's empty-list dtype inference bug.

Details and the tested scope: compatibility contract.

Current limits

  • Binary wheels: Linux x86_64, glibc 2.28+, CPython 3.10+.
  • No macOS or Windows wheels yet; free-threaded Python is not a release target.
  • Exact video seeking scans packet timestamps when opening the decoder.
  • Audio range queries currently decode from the beginning; late ranges can be expensive.
  • NumPy return types require caller changes where code expects Torch tensors.
  • Historical avdec benchmarks are not TensorCodec performance results.

Install

python -m pip install tensorcodec

Linux wheels bundle shared FFmpeg libraries. Source builds need Rust, libclang and FFmpeg 7 development headers/libraries.

Before the first PyPI upload, install a local wheel:

python -m pip install dist/tensorcodec-*.whl

Use

from tensorcodec.decoders import VideoDecoder, AudioDecoder

with VideoDecoder("video.mp4") as video:
    frame = video.get_frame_played_at(1.25)  # frame playing at this time
    print(frame.data.shape)                 # CHW NumPy array
    batch = video.get_frames_at([4, 0, 4])   # order and duplicates preserved
    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)
    print(samples.data.shape)               # channels × samples, float32

Decoded arrays keep their storage after the decoder closes. Input file objects remain caller-owned.

Implementation

Layer Responsibility
Python Public API, frame/time selection, validation, result objects
Rust + PyO3 FFmpeg handles, seeking/decoding, color conversion, resampling
FFmpeg Codec and container implementations

A batch crosses the Python/Rust boundary once. Native decoding releases the GIL.

Development and verification

# Requires Rust, Clang/libclang, pkg-config and FFmpeg 7 development libraries.
python -m venv .venv
. .venv/bin/activate
python -m pip install numpy pytest ruff 'maturin>=1.8,<2'
maturin develop --locked

# Reference dependencies are for tests only.
python -m pip install torch==2.14.1 torchcodec==0.17.0 \
  --index-url https://download.pytorch.org/whl/cpu
pytest tests/test_video_contract.py tests/test_audio_contract.py --backend torchcodec
pytest --compare

Tests generate fixtures with FFmpeg/ffprobe and Python's wave module. --compare requires the exact oracle version; otherwise differential tests skip. The old avdec decoder and tests are never executed.

TensorCodec's own code is MIT licensed.

Metadata

Release files for tensorcodec 0.1.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 tensorcodec 0.1.0
File Size Uploaded
tensorcodec-0.1.0.tar.gz 54.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tensorcodec 0.1.0
File Interpreter ABI Platform
tensorcodec-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64 Details

Total release size: 11.1 MB

Release files / tensorcodec-0.1.0.tar.gz

Download URL tensorcodec-0.1.0.tar.gz
Size 54.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a3607f25a14bc577733deb863cff1e874a71a761c6defae8460dd001b7c12cbc
BLAKE2b-256 checksum
How to use checksums
ad63e97fb233a3ecb843e213a2572b58436e1675e6c0017ed9a79c9e1c6bc79c
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.0-cp310-abi3-manylinux_2_28_x86_64.whl

Download URL tensorcodec-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl
Size 11.0 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
1b00e3a005148e6587cdc68ace0f0846ab6018c2619f09f46921255f7c8d09b7
BLAKE2b-256 checksum
How to use checksums
2cc793e8e89627d910ff76fe36bd5992ab94c18f863a54ea7378cff67ec456ef
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

0.1.3

5 release files

0.1.2

3 release files

0.1.1

3 release files

This release

0.1.0 This release

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