How AV1 Decoders Handle Encrypted Sub-Samples

This article provides an overview of how AV1 decoders process encrypted sub-sample mapping within Open Bitstream Unit (OBU) payloads. While video decoders themselves do not perform cryptographic operations, they interface directly with Content Decryption Modules (CDMs) and container parsers to ingest selectively encrypted bitstreams. The following sections explain the role of sub-sample mapping in AV1, how container metadata defines clear and encrypted regions, the secure pipeline workflow, and how alignment rules ensure smooth decoding.

The Role of Sub-Sample Encryption in AV1

AV1 structures its elementary stream into discrete packets called Open Bitstream Units (OBUs). In a protected media environment using standards like Common Encryption (CENC / ISO/IEC 23001-7), encrypting an entire OBU bitstream would obscure critical structural headers, rendering decoders and demuxers unable to parse the stream without high-overhead decryption passes.

Sub-sample encryption resolves this by splitting individual media samples into alternating clear (unencrypted) and protected (encrypted) byte ranges. In AV1:

  • Clear bytes typically cover high-level OBUs (such as Temporal Delimiters, Sequence Headers, and Frame Headers) as well as the OBU headers and length fields of data-heavy units.
  • Protected bytes contain the sensitive video data, primarily the raw encoded bitstream within Tile Group OBUs or Frame OBUs (specifically the tile payloads containing transform coefficients and motion vectors).

Sub-Sample Mapping via Container Metadata

The AV1 elementary stream does not store its own encryption parameters. Instead, the transport layer—most commonly the ISO Base Media File Format (ISOBMFF / MP4)—carries sub-sample mapping metadata in sample auxiliary information boxes (senc and saiz).

Each sample's mapping is defined by an array of sub-sample entries consisting of two values:

  1. BytesOfClearData: The count of consecutive unencrypted bytes.
  2. BytesOfProtectedData: The count of consecutive encrypted bytes (using AES-128 in CTR or CBCS mode).

A single media sample can contain multiple OBUs. The sub-sample mapping precisely defines where each clear OBU ends, where the protected payload begins, and where subsequent clear headers resume.

The Decryption and Decoding Execution Pipeline

The AV1 decoder operates inside a secure media pipeline, typically interacting with a Trusted Execution Environment (TEE) or a hardware-protected video path:

  1. Demuxing: The demuxer isolates the sample and extracts the sub-sample map, Initialization Vector (IV), and Key ID (KID).
  2. CDM Processing: The container passes the encrypted sample and sub-sample map to the Content Decryption Module (CDM).
  3. Selective Decryption: The cryptographic engine iterates through the sub-sample map. It skips the byte count specified by BytesOfClearData and runs AES decryption exclusively on the byte range defined by BytesOfProtectedData.
  4. Bitstream Reconstruction: In modern implementations, decryption occurs in-place within a secure memory buffer. The clear OBU headers remain untouched, while the encrypted payloads are replaced with plaintext tile data.
  5. Decoder Intake: The AV1 decoder receives a fully valid, syntactically complete AV1 elementary bitstream. The decoder parses the clear OBU headers, extracts the tile configurations, and decodes the now-unencrypted tile group payloads into uncompressed video frames.

Boundary Alignment Requirements

To prevent decoding failures, the AV1 specification and encryption standards (such as the Alliance for Open Media's AV1 Bitstream Storage in ISOBMFF) enforce strict alignment rules:

  • OBU Header Isolation: An encryption block cannot straddle an OBU header. All OBU headers, extension headers, and OBU size fields must fall entirely within BytesOfClearData.
  • Cipher Block Alignment: For cipher modes that operate on 16-byte blocks (such as AES-CBCS), protected regions must be aligned appropriately. If partial blocks occur at the end of an encrypted payload, pattern protection rules or clear trailing bytes handle the residual data without corrupting subsequent OBU headers.
  • Tile Independence: Because AV1 supports multi-threaded tile decoding, sub-sample boundaries are frequently aligned to tile boundaries, enabling parallel decryption and parsing across multiple decoder cores.