Module 6 · Lesson 60 of 108

Hardware codecs, streaming, and debugging

Select a hardware codec or software fallback, choose a video transport, and diagnose GStreamer failures with negotiated caps, debug logs, and topology graphs.

  • Beginner to advanced
  • 9 min read
  • 20 min lab
What you will need

Ubuntu 24.04 in WSL2 or a VM with GStreamer tools, the base and good plugin sets, and Graphviz. A target board is optional for hardware codec testing.

Your place in the module
By the end you can 4 objectives
  • Identify hardware codec factories and verify their formats on a target.
  • Compare stateful and stateless V4L2 decoding by where codec state is managed.
  • Choose among RTSP/RTP, HLS, and WebRTC for a given viewer and latency requirement.
  • Capture a GStreamer debug log and annotate a pipeline topology graph.
Video coming soonHardware codecs, streaming, and debugging
The video for this lesson is being recorded. Read the lesson below in the meantime.
Recall first from Building capture, display, and app pipelines
  • The encoder produces H.264, the muxer builds the MP4 container, and filesink writes it.
  • The display sink must match the session and the target's display access.
  • RTP carries packetized media, while RTSP controls a streaming session.
01

Select a codec on the target

4 min read

Pipelines that work in a demo still need hardware codecs, streaming, and debugging to ship; this lesson covers all three.

The Linux kernel documents two V4L2 decoder interfaces because devices expect different inputs. A stateful H.264 decoder accepts a compressed stream in its supported representation. A stateless H.264 decoder expects coded data and decoding parameters supplied by user space. Two devices can therefore advertise H.264 decoding and require different GStreamer elements. That difference matters when moving a working pipeline from a development machine to a board. V4L2 stateful decoder interface and V4L2 stateless decoder interface.

A can reduce the CPU work required for compression or decompression. Encoding and decoding are separate capabilities. Check each direction independently, along with codec, profile, resolution, and raw pixel format. Also check what the camera delivers. If it already outputs H.264 that the receiver accepts, a parser and an RTP payloader may be enough to forward it without transcoding.

Hardware codec accessGStreamer pipelineCodec elementV4L2 driverVideo hardwareThe codec element submits work through thedriver.GStreamer pipelineCodec elementV4L2 driverVideo hardwareThe codec element submits workthrough the driver.
A GStreamer codec element connects the application to the kernel driver and the video hardware.

Run discovery on the target, ideally under the same account that will run the application. On a board with v4l-utils installed, v4l2-ctl --list-devices shows the device names and nodes that the kernel exposes. gst-inspect-1.0 video4linux2 and gst-inspect-1.0 v4l2codecs show the GStreamer plugins and their registered features when available. A listed device node can belong to a camera or another media function. Look for the exact encoder or decoder factory you need, then inspect it by name to read its sink and source pad templates. Templates show advertised capabilities. The negotiated caps from a running pipeline show what a particular connection actually selected.

Start with one known input stream or one raw format that the element accepts. For a decoder, send the decoded frames to fakesink to test whether the codec runs independently of a display. If that succeeds and adding the display fails, compare the decoder output and sink input, including any caps features for special memory types. Two elements may agree on pixel format and still require different memory handling. Hardware decoding alone does not guarantee that the rest of the pipeline can use those buffers directly.

Choose a software fallback explicitly. avdec_h264 is a software H.264 decoder from the GStreamer libav plugin, available through gstreamer1.0-libav on Ubuntu. x264enc is a software H.264 encoder from the ugly plugin set, available through gstreamer1.0-plugins-ugly. Inspect the installed factory before relying on it. A working fallback can keep development moving in a VM, where the target VPU is usually unavailable. If the target also needs a fallback, test it with the intended input and decide whether it can sustain the selected resolution and frame rate. Record which codec element actually ran so a successful fallback cannot be mistaken for hardware acceleration.

Going deeperStateful and stateless V4L2 codecs in GStreamer

A V4L2 memory-to-memory decoder uses an OUTPUT queue for coded input from user space and a CAPTURE queue for decoded output returned to user space. The names describe direction from the application's perspective. In the stateful interface, the driver and hardware or firmware handle stream parsing and maintain decoding state behind that interface. GStreamer may still use a parser such as h264parse to supply the stream format and buffer alignment that the decoder expects.

In stateless decoding, user space parses codec headers, tracks reference pictures, and supplies the compressed data with controls describing the decode operation. Those controls can include parameters for decoding the current picture and identifying the reference buffers it needs. The Media Request API associates the controls with the coded input buffer for that operation. The hardware still performs decoding. The distinction is who maintains the information needed to submit each operation.

GStreamer's video4linux2 plugin provides elements such as v4l2src and can register stateful memory-to-memory codec factories, for example v4l2h264dec or v4l2h264enc when a suitable device is exposed. The separate v4l2codecs plugin provides stateless decoders such as v4l2slh264dec on systems with a matching device. Plugin installation, device capabilities, and permissions affect what is registered and usable. A working v4l2src confirms that a capture path works. Inspect and test the codec independently.

02

Choose how viewers receive video

3 min read

Start with the viewer. A control-room client on the same network, a browser used for a live conversation, and a large audience watching an event have different requirements. Decide how much delay each viewer can tolerate, what client software is available, and what should happen when the connection loses packets or slows down.

Live video delivery choicesRTSP/RTPHLSWebRTCTypical viewerCamera clientHTTP playerInteractivepeerMedia deliveryRTP packetsHTTP mediasegmentsEncryptedreal-timemediaDelay factorsJitter andtransportPublishingand bufferingNetwork andbuffering
Three delivery choices for live video, with different client and buffering requirements.

RTSP and RTP are common in camera deployments. RTSP controls the session, including setup and playback. RTP carries the encoded media packets, with sequence numbers and timestamps that help the receiver order and play them. An RTSP session can use RTP over UDP or interleave RTP over the RTSP TCP connection. UDP allows later packets to arrive even when an earlier packet was lost. A receiver can hold packets briefly in a jitter buffer to handle irregular arrival. TCP delivers bytes in order, so a lost segment can delay media that arrived after it. In GStreamer, rtph264pay packetizes H.264 for RTP. Publishing an RTSP URL also requires a server, such as an application built with GStreamer's RTSP server library. A receiver can open that URL with rtspsrc and use rtph264depay for an H.264 RTP stream.

HLS delivers playlists and media segments over HTTP. A player refreshes the live playlist and requests the media it lists. If you publish multiple bitrate variants, a compatible player can switch between them as conditions change. HTTP delivery can use ordinary web distribution and caching infrastructure. Conventional live HLS adds delay while media is segmented, published, and buffered by the player. Low-Latency HLS reduces the wait by making smaller units of media available sooner and requires support along the delivery path. HLS fits audiences who can accept buffering in exchange for playback that can adapt to changing network capacity.

WebRTC fits interactive viewing, such as a browser operator who must see the effect of a control input promptly. It includes real-time media transport with encryption and mechanisms for establishing a connection through NAT. A deployment also needs signaling to exchange session descriptions and connection candidates. Some connections require a TURN relay. In GStreamer, webrtcbin supplies WebRTC functionality, while the application handles signaling with the remote peer. The viewer and sender must negotiate a codec they both support.

Latency and picture quality depend on more than the delivery protocol. An encoder can buffer frames for lookahead or frame reordering. Reducing that buffering can improve responsiveness at the cost of compression efficiency. Shortening the interval between independently decodable pictures can help viewers join sooner and help playback recover after loss, but those pictures can require more bits. A larger receiver jitter buffer can absorb more variation in packet arrival at the cost of later playback. Under a fixed bitrate limit, leaving more bits for frequent recovery pictures can leave fewer bits for detail elsewhere.

When you compare transports, trace where the delay accumulates. If a local decoded preview is already delayed, smaller receiver buffers cannot recover the time spent before transmission. If the preview is prompt and the remote player is slow, check the receiver's buffering and, for HLS, when media becomes available in the live playlist. Keep the source and encoding settings fixed when comparing delivery options so you can attribute the observed change.

03

Diagnose the pipeline with caps, logs, and graphs

3 min read

First establish whether the pipeline can be constructed, whether it can negotiate a format, and whether the receiver gets playable media. An absent element factory can stop construction. A caps mismatch can prevent linking or stop streaming during negotiation. A pipeline can also negotiate successfully and later fail while opening a device or receiving a stream. The element that reports an error may be upstream of the cause, so record its message and examine the nearby evidence before replacing it.

gst-launch-1.0 -v prints verbose status information, including caps notifications. Read the caps on the two pads at the link you are investigating. Look for the media type and fields relevant to that link. Raw video caps can show format, dimensions, and frame rate. Compressed video caps can show stream format and alignment. gst-inspect-1.0 helps identify what each factory advertises when a pipeline stops before usable caps appear.

GST_DEBUG sets logging levels globally and by category. The example uses a global level of 2 for warnings and errors, and level 5 for more detail from categories matching GST_CAPS and GST_PADS. Keep verbose launch output and the debug log in separate files so you can check the negotiated values without searching through all the internal messages. GST_DEBUG_NO_COLOR=1 removes terminal color escapes from the redirected log.

GST_DEBUG_DUMP_DOT_DIR tells gst-launch-1.0 where to write DOT snapshots, including snapshots taken during state changes. Create the directory before running the command and use a fresh directory for each run. A DOT file describes the elements, pads, and links present when the snapshot was taken. Use dot from Graphviz to render it. For an application that builds its own pipeline, setting the environment variable supplies the directory, and the application must request a dump, for example with GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS.

Evidence from a pipeline runRunpipelineReadverbosecapsInspect DOTgraphTrace debugmessagesRunpipelineReadverbosecapsInspect DOTgraphTrace debugmessages
Inspect the verbose caps, category log, and DOT snapshot from the same run.

The following finite, headless pipeline works without a camera, display, or board codec. On Ubuntu, the example uses gstreamer1.0-tools, gstreamer1.0-plugins-base, and graphviz. It requests I420 from videotestsrc, then uses videoconvert to produce RGB for the downstream caps filter. fakesink consumes the result without displaying it.

bash
run_dir=$(mktemp -d)
GST_DEBUG='2,GST_CAPS:5,GST_PADS:5' \
GST_DEBUG_NO_COLOR=1 \
GST_DEBUG_DUMP_DOT_DIR="$run_dir" \
gst-launch-1.0 -v \
  videotestsrc num-buffers=30 ! 'video/x-raw,format=I420' ! \
  videoconvert ! 'video/x-raw,format=RGB' ! fakesink \
  >"$run_dir/verbose.txt" 2>"$run_dir/debug.log"

for snapshot in "$run_dir"/*.dot; do
  [ -f "$snapshot" ] || continue
  dot -Tsvg "$snapshot" -o "${snapshot%.dot}.svg"
done
ls "$run_dir"

Open the snapshot whose name ends in PAUSED_PLAYING (the transition into PLAYING) and follow the links from the source to the sink. Identify the caps filters on either side of videoconvert and confirm the formats against verbose.txt. Earlier snapshots can contain links whose final caps are not yet known. The debug log records the negotiation activity that led to those caps, while the graph shows the topology and pad details at one moment.

For comparison, remove only videoconvert ! so the I420 and RGB caps strings are adjacent. In a test on GStreamer 1.24.2, gst-launch-1.0 rejected the description before any pipeline existed and printed WARNING: erroneous pipeline: no element "video", because the launch syntax expects an element between two caps strings. No DOT file was written, so there is no PAUSED_PLAYING snapshot to open. Writing the two filters as capsfilter caps=... elements instead gives could not link capsfilter0 to capsfilter1, because no raw format satisfies both. On a real receiver, the same method helps distinguish an absent codec, a failed format negotiation, and a pipeline that plays locally but stalls during delivery.

The next lesson, Performance goals and measuring CPU, starts from a working pipeline and asks whether it can sustain the required workload on the target.

Key takeaways

  • Hardware codec availability depends on the board, kernel driver, device access, and installed GStreamer plugins.
  • Stateful V4L2 decoders manage stream state behind the driver interface, while stateless decoders receive request-specific controls from user space.
  • Encoder buffering, network buffering, and player buffering all contribute to end-to-end delay.
  • Verbose caps, debug logs, and DOT graphs show different evidence about the same pipeline.
Reflect
  1. Explain to a colleague, in two sentences: identify hardware codec factories and verify their formats on a target.
  2. Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
  3. What surprised you when you ran the commands yourself?
On a real board

Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.

References and further reading

Find your next step

↑ ↓ to move · Enter to open · Esc to close