Open AI Models

PyTorch launches TorchCodec 1.0 for multimodal media decoding and encoding

Key Takeaway

TorchCodec 1.0 provides a unified, high-performance media layer for PyTorch, enabling efficient video, audio, and image processing via CPU and GPU hardware acceleration.

Summary

PyTorch has officially released TorchCodec 1.0, a specialized media layer designed to handle the decoding and encoding of video, audio, and images into PyTorch tensors. This release consolidates PyTorch's media capabilities into a single library that supports both training and inference workflows for multimodal AI models.

The library is designed for high-performance environments, utilizing dedicated hardware decoders like NVIDIA's NVDEC and nvJPEG to offload work from CUDA cores. It is already integrated into critical ecosystem components such as Hugging Face's datasets and transformers, as well as high-throughput inference engines like vLLM and SGLang.

Technical architecture and low-level API improvements

  • Multi-stage Pipeline: The new low-level APIs decompose media processing into three distinct stages—Demuxing (extracting packets), Decoding (decompressing to raw frames), and Conversion (transforming to RGB or resampling audio)—allowing developers to run each stage on separate threads to bypass the GIL.
  • Hardware Acceleration: Video decoding can be offloaded to NVIDIA GPUs via NVDEC, while JPEG decoding on data-center GPUs (A100/H100) utilizes dedicated hardware decoders to run concurrently with model computations.
  • Memory and Data Access: The library supports direct access to raw YUV data (SDR and HDR) without unnecessary copies and provides a metadata API to inspect image dimensions and formats without performing a full decode.
  • Broad Format Support: The system leverages FFmpeg (versions 4 through 9) to support a wide array of audio and video formats, while the image decoder handles JPEG, PNG, WebP, GIF, AVIF, and HEIC.
  • Cloud-Native Streaming: The VideoDecoder supports reading from bytes or file-like objects, enabling efficient streaming of media from cloud storage by fetching only required segments rather than entire files.

Why it matters

By providing a stable, ABI-compatible media layer, TorchCodec 1.0 streamlines the data pipeline for multimodal AI practitioners using vLLM or SGLang. It reduces the computational overhead of preparing video and audio inputs, which is critical for scaling large-scale multimodal model training and real-time inference.

What to do

  • Install the library using 'pip install torchcodec' on Linux, macOS, or Windows.
  • Ensure FFmpeg version 4 through 9 is installed on your system.

Original reference: pytorch.org →