• Docs >
  • Welcome to the TorchCodec documentation!
Shortcuts

Welcome to the TorchCodec documentation!

TorchCodec is a Python library for decoding video and audio data into PyTorch tensors, on CPU and CUDA GPU. It aims to be fast, easy to use, and well integrated into the PyTorch ecosystem. If you want to use PyTorch to train ML models on videos and audio, TorchCodec is how you turn these into data.

We achieve these capabilities through:

  • Pythonic APIs that mirror Python and PyTorch conventions.

  • Relying on FFmpeg to do the decoding. TorchCodec uses the version of FFmpeg you already have installed. FMPEG is a mature library with broad coverage available on most systems. It is, however, not easy to use. TorchCodec abstracts FFmpeg’s complexity to ensure it is used correctly and efficiently.

  • Returning data as PyTorch tensors, ready to be fed into PyTorch transforms or used directly to train models.

Installation instructions

How to install TorchCodec

https://github.com/pytorch/torchcodec?tab=readme-ov-file#installing-torchcodec
Getting Started with TorchCodec

A simple video decoding example

generated_examples/basic_example.html
Audio Decoding

A simple audio decoding example

generated_examples/audio_decoding.html
GPU decoding

A simple example demonstrating CUDA GPU decoding

generated_examples/basic_cuda_example.html
Streaming video

How to efficiently decode videos from the cloud

generated_examples/file_like.html
Clip sampling

How to sample regular and random clips from a video

generated_examples/sampling.html

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources