Skip to main content

Overview

v4l2h264dec is a hardware-accelerated video decoder that uses the Video4Linux2 (V4L2) stateful decoder API to offload H.264 (AVC) video decoding to the Qualcomm Video Processing Unit (VPU). This plugin is provided and maintained by the GStreamer community. This document focuses on its usage in conjunction with Qualcomm-specific QIM SDK GStreamer plugins, along with relevant use cases and internal architectural considerations. v4l2h264dec is typically used to decode H.264 streams provided by:
  • File sources
  • RTSP sources
  • HLS/HTTP streaming sources
The element is responsible only for decoding video frames. It does not demux or parse streams on its own — those operations must be handled by peer GStreamer elements upstream (e.g., qtdemux and h264parse).

Example Pipeline

1

Download Required Files

2

Copy files to device

3

Connect to device

4

Set environment variables

Run below command on your device
5

Run the pipeline

Key Responsibilities

v4l2h264dec is responsible for:
  • Hardware acceleration — offloads H.264 decoding to the dedicated VPU
  • V4L2 state management — manages the V4L2 stateful decoder state machine (device open, buffer allocation, stream on/off)
  • Buffer I/O management — handles buffer exchange between GStreamer and the V4L2 driver using DMABuf, MMAP, or UserPtr modes
  • Format negotiation — negotiates raw output formats supported by the hardware
  • Multi-stream support — supports multiple concurrent decoder instances (subject to hardware resource limits)
  • Error handling — supports decoder error controls such as max-errors and corrupted-frame discard behavior

Hierarchy

GObject
   GstObject
      GstElement
         GstVideoDecoder
            GstV4l2VideoDec
               v4l2h264dec

Pad Templates

sink

src

The exact set of profiles and levels reported depends on what the underlying V4L2 driver enumerates via V4L2_CID_MPEG_VIDEO_H264_PROFILE and V4L2_CID_MPEG_VIDEO_H264_LEVEL.

Element Properties

I/O Mode Values

Both capture-io-mode and output-io-mode accept the same GstV4l2IOMode enumeration:

Internal Architecture

v4l2h264dec operates using two V4L2 queue objects internally:
  • Output queue (V4L2_BUF_TYPE_VIDEO_OUTPUT) — receives compressed bitstream buffers from upstream
  • Capture queue (V4L2_BUF_TYPE_VIDEO_CAPTURE) — produces decoded raw video frames for downstream

State Transitions

Dynamic Resolution Change

v4l2h264dec supports mid-stream dynamic resolution changes without requiring a pipeline restart, handled through the V4L2 source change event mechanism:
  1. At initialization, the decoder subscribes to V4L2_EVENT_SOURCE_CHANGE events on the capture queue.
  2. When the driver detects a resolution change in the bitstream, it signals the event.
  3. The decoder stops the capture queue, discards the existing buffer pool, re-negotiates format via VIDIOC_G_FMT, sets a new output state with updated dimensions, and reallocates the capture buffer pool.
This allows seamless decoding of adaptive bitrate streams and content with embedded resolution changes.

Memory and Buffer Management

DMABuf Usage

Setting capture-io-mode=4 exports decoded frame buffers as DMABuf file descriptors. These can be imported directly by waylandsink or qtivcomposer without CPU memory copies, enabling zero-copy pipelines.

Alignment Requirements

Decoded buffers follow Qualcomm hardware alignment requirements (e.g., 128-byte stride alignment).

Format Support

Standard NV12 is common. UBWC (Universal Bandwidth Compression) is supported through formats like NV12_Q08C to reduce memory bandwidth.

Latency

The decoder computes and reports pipeline latency based on the minimum number of capture buffers required by the driver and the frame duration:

Drain and Flush

  • Drain — sends V4L2_DEC_CMD_STOP to signal end-of-stream; waits for all remaining frames to be produced
  • Flush — stops both queues, resets buffer pools, and restarts streaming; used during seek operations

Usage

Ensure you have followed the prerequisites before continuing

Single RTSP Stream — Decode and Display

Demonstrates real-time RTSP stream reception, H.264 network depayloading, and hardware-accelerated decoding with DMABuf zero-copy for Wayland preview.

Four-Stream Side-by-Side Composition

Demonstrates decoding four input streams using four hardware decoder instances, arranging them in a 2×2 grid using qtivcomposer, and displaying the composed frame.