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.
- Playback rules
- Release builds and PyPI publishing
- Native dependency licenses and source/build notices
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)
| File | Size | Uploaded | |
|---|---|---|---|
| tensorcodec-0.1.0.tar.gz | 54.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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 logRelease 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