torchcodec
A video decoder for PyTorch
What it is and what it does
TorchCodec is a library that converts video, audio, and image files into tensors and back. It wraps FFmpeg for video and audio decoding/encoding, providing Pythonic APIs that abstract FFmpeg's complexity while supporting both CPU and CUDA GPU acceleration. The library returns data as tensors ready for transforms or model training, with metadata like frame counts, timestamps, and codec information.
The package handles video frame indexing by frame number or playback time, batch frame extraction with timing metadata, and image decoding/encoding in multiple formats (JPEG, PNG, WebP, GIF, AVIF, HEIC). FFmpeg is optional—image codecs work without it—but video and audio work requires FFmpeg 4–9 installed on your system. CUDA support depends on GPU hardware with NVDEC/NVENC capabilities.
Use it for:
- Extract video frames as tensors for training models on video datasets
- Decode audio to tensors for speech or music processing in pipelines
- Batch-load images in multiple formats (JPEG, PNG, WebP) directly to GPU
- Encode outputs back to video or audio files with precise frame/sample timing
- Build data loaders that stream video frames with accurate presentation timestamps
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
TorchCodec decodes and encodes videos, audio, and images to and from tensors on CPU and CUDA GPUs, wrapping FFmpeg for video/audio and providing native image codecs.
Yes, if you need to work with video, audio, or images in a media pipeline. TorchCodec is actively maintained (release 1 day old), has no known vulnerabilities, and integrates cleanly into workflows. Install friction is moderate due to compiled wheels and optional FFmpeg dependency, but both are straightforward. License status is unclear, so verify licensing terms before use in proprietary projects.
Install
torchcodec on PyPI
pip
pip install torchcodecuv
uv add torchcodecpoetry
poetry add torchcodecInstalling torchcodec
Before you install
Medium install friction due to compiled wheels for multiple Python versions (3.10–3.14) and platforms, plus an optional FFmpeg system dependency for video/audio work. Actively maintained with a release 1 day old and 1156 repository stars.
Quickstart
pip install torchcodec
from torchcodec.decoders import VideoDecoder
decoder = VideoDecoder("path/to/video.mp4", device="cpu")
frame = decoder[0] # uint8 tensor [C, H, W]
FFmpeg (optional but required for video/audio; image decoders work without it). Requires Python >=3.10.
Verify before relying
- Whether CUDA wheels are available for Windows by default or require explicit --index-url configuration
- Performance characteristics (speed, memory efficiency) compared to direct FFmpeg usage
- Stability and maturity of the 0.16.0 release relative to earlier versions
Package facts
| License | not declared (unclear) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 1 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 4,207,756/month — #2,362 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: torchcodec-0.16.0-cp310-cp310-macosx_14_0_arm64.whl; torchcodec-0.16.0-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl; torchcodec-0.16.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl; torchcodec-0.16.0-cp310-cp310-win_amd64.whl; torchcodec-0.16.0-cp311-cp311-macosx_14_0_arm64.whl; torchcodec-0.16.0-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl; torchcodec-0.16.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl; torchcodec-0.16.0-cp311-cp311-win_amd64.whl; torchcodec-0.16.0-cp312-cp312-macosx_14_0_arm64.whl; torchcodec-0.16.0-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl; torchcodec-0.16.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl; torchcodec-0.16.0-cp312-cp312-win_amd64.whl; torchcodec-0.16.0-cp313-cp313-macosx_14_0_arm64.whl; torchcodec-0.16.0-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl; torchcodec-0.16.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl; torchcodec-0.16.0-cp313-cp313-win_amd64.whl; torchcodec-0.16.0-cp314-cp314-macosx_14_0_arm64.whl; torchcodec-0.16.0-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl; torchcodec-0.16.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl; torchcodec-0.16.0-cp314-cp314t-macosx_14_0_arm64.whl
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
decord2Decord2 decodes video and audio files with…
permissive · top 15,000 on PyPI
decordDecord decodes video and audio files with…
permissive · top 5,000 on PyPI
pynvvideocodecPyNvVideoCodec provides hardware-accelerated…
permissive · top 15,000 on PyPI
torchPyTorch provides GPU-accelerated tensor…
permissive · top 1,000 on PyPI
nvidia-nvimgcodec-cu12nvImageCodec provides GPU-accelerated codec…
permissive · top 15,000 on PyPI
imageio-ffmpegProvides a simple Python wrapper around ffmpeg…
permissive · top 5,000 on PyPI
python-ffmpegProvides a Python binding for FFmpeg with both…
permissive · top 15,000 on PyPI
mediapyMediapy reads, writes, and displays images and…
permissive · top 5,000 on PyPI
torchlibrosaProvides PyTorch implementations of librosa…
permissive · top 15,000 on PyPI
qwen-omni-utilsProvides helper functions to preprocess and…
permissive · top 5,000 on PyPI