Back to articles

TorchCodec 1.0: A Media Layer for PyTorch

3 min read

Introduction

Multimodal systems need more than models: they also depend on dependable ways to move media into and out of tensor workflows. TorchCodec 1.0 marks the formal release of a component that began as a video decoder and has grown into PyTorch’s media layer. It handles video, audio, and images, producing data that can be used with PyTorch transforms or passed to models. PyTorch says the APIs had already been stable for some time; 1.0 makes that status official.

Key points

  • A broader set of media operations. VideoDecoder can read from files, byte data, or file-like objects, retrieve frames by index or timestamp, and decode on CPU or NVIDIA GPUs. AudioDecoder supports formats handled by FFmpeg and can resample or change channel counts during decoding. Image decoding covers JPEG, PNG, WebP, GIF, AVIF, and HEIC. TorchCodec also provides encoding for video and audio, as well as JPEG and PNG images; output can be written to files or file-like destinations.
  • Control over the decoding pipeline. Media decoding can be separated into demuxing, which extracts compressed packets from a container; decoding, which produces raw frames or samples; and conversion, which creates RGB frames or target audio samples. High-level decoders run these stages in sequence. The new low-level APIs expose them individually, allowing developers to place work on different threads or processes, choose devices, and assemble pipelines for their own constraints. They can also work with packets obtained elsewhere and sources such as live streams that have no fixed end.
  • Access to data before conversion. Developers can stop at raw YUV frames rather than converting them to RGB, avoiding some conversions and copies. Ten-bit HDR data can be represented as uint16, while raw audio samples retain the codec’s native format. This creates room for custom color-conversion kernels, combining conversion with resizing, or experimenting with model workflows that operate directly on YUV.
  • A new route to performance tuning. PyTorch describes an experiment in which a coding agent built and tuned a video pipeline. Its throughput was 1.4–1.9x that of a simple baseline and up to 1.36x that of an equally tuned VideoDecoder. These are results from the reported experiment, not a universal performance guarantee: the best choices will depend on the hardware and workload.

Why it matters

TorchCodec’s significance is not simply that it supports more formats. It places media handling within the PyTorch tensor ecosystem while offering two levels of abstraction: convenient decoders for common cases and composable stages for users who need more control. Training and inference pipelines can use that control to overlap work, selectively fetch media, or avoid unnecessary conversions. PyTorch names Hugging Face libraries, vLLM, and SGLang among projects that already use TorchCodec, indicating its role in multimodal infrastructure.

The project can be installed with pip on Linux, macOS, and Windows. Linux wheels include CUDA support, and TorchCodec uses the system’s FFmpeg, supporting major versions 4 through 9. It also describes itself as ABI-stable to reduce compatibility friction with future PyTorch releases. For many users, the high-level APIs remain the simplest starting point; the low-level interfaces are most useful when pipeline control or performance becomes a real requirement.

Source: PyTorch Blog

Comments

Checking sign-in status...

Loading comments...

Related articles

CCTest · Blog
TorchTLX Brings Architecture-Specific GPU Kernels to TorchInductor
Frameworks & Tools
cctest.ai

TorchTLX Brings Architecture-Specific GPU Kernels to TorchInductor

TorchTLX adds architecture-specific TLX kernels and richer fusion options to TorchInductor while preserving the familiar torch.compile workflow. The PyTorch post reports up to 1.2x speedups for specialized GEMM and attention templates, and up to 1.5x for richer fusion in its presented benchmarks.

Read more