← all repositories
meta-pytorch/torchcodec

FFmpeg for PyTorch without the FFmpeg headache

TorchCodec exists because feeding video and audio into PyTorch models shouldn't require wrestling with FFmpeg command lines.

1.1k stars Python Data Tooling
torchcodec
Not currently ranked — collecting fresh signals.
star history

What it does

TorchCodec decodes video and audio into PyTorch tensors on CPU or CUDA, and encodes them back out on CPU. It wraps your system-installed FFmpeg (versions 4 through 8) in a Pythonic API that supports slice indexing, frame-level lookups, and time-based seeking. The output is ready for transforms or model training without intermediate format shuffling.

The interesting bit

Instead of hiding FFmpeg behind a subprocess call, it abstracts the library’s complexity into tensor-native operations—so decoder[0] returns a uint8 tensor and get_frames_played_at returns timestamps alongside the pixels. It is essentially a carefully written glue layer between a mature C library and PyTorch’s expectations.

Key highlights

  • Returns decoded frames directly as PyTorch tensors with shape [C, H, W] or batched [N, C, H, W]
  • Supports both index-based (get_frames_at) and time-based (get_frames_played_at) retrieval with PTS metadata
  • CUDA decoding available on Linux via NVDEC, falling back to CPU wheels on macOS and Windows
  • Encoding API supports multiplexing video and audio streams into a single output file
  • Tight version coupling with PyTorch releases (e.g., torchcodec 0.13 requires torch >=2.11)

Caveats

  • Encoding is CPU-only; the README does not mention GPU-accelerated encoding
  • Windows users need FFmpeg “shared” library builds, and CUDA wheel installation requires manual index-url selection
  • NVDEC hardware support depends on your specific Nvidia GPU model

Verdict

Worth a look if you build video or audio ML pipelines in PyTorch and are tired of brittle FFmpeg wrappers. Skip it if you only need inference on pre-extracted frames or already have a stable decoding stack you trust.

Frequently asked

What is meta-pytorch/torchcodec?
TorchCodec exists because feeding video and audio into PyTorch models shouldn't require wrestling with FFmpeg command lines.
Is torchcodec open source?
Yes — meta-pytorch/torchcodec is open source, released under the BSD-3-Clause license.
What language is torchcodec written in?
meta-pytorch/torchcodec is primarily written in Python.
How popular is torchcodec?
meta-pytorch/torchcodec has 1.1k stars on GitHub.
Where can I find torchcodec?
meta-pytorch/torchcodec is on GitHub at https://github.com/meta-pytorch/torchcodec.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.