H.264 Video

H.264 (AVC) compressed video for bandwidth-efficient streaming.

Overview

H.264 provides significant bandwidth reduction compared to uncompressed video, making it suitable for:

  • Network-constrained environments
  • Recording and storage
  • Wide device compatibility

GStreamer Backend

MediaX uses GStreamer for H.264 encoding and decoding, providing:

  • Hardware acceleration support (VAAPI, NVENC, V4L2)
  • Flexible pipeline configuration
  • Cross-platform compatibility

Hardware Acceleration Options

Backend Platform GPU/Device
VAAPI Linux Intel, AMD
NVENC Linux, Windows NVIDIA
V4L2 Linux Raspberry Pi

Transmitting H.264 Video

#include "h264/gst/vaapi/rtp_h264_payloader.h"

mediax::rtp::h264::gst::vaapi::RtpH264GstVaapiPayloader payloader;

mediax::rtp::StreamInformation stream_info;
stream_info.session_name = "h264-stream";
stream_info.hostname = "239.192.1.1";
stream_info.port = 5004;
stream_info.width = 1920;
stream_info.height = 1080;
stream_info.framerate = 30;
stream_info.encoding = mediax::rtp::ColourspaceType::kColourspaceH264Part10;

payloader.SetStreamInfo(stream_info);
payloader.Open();

// Send RGB24 frames - encoder handles conversion and compression
std::vector<uint8_t> rgb_buffer(1920 * 1080 * 3);
// Fill buffer with video frame...
payloader.Transmit(rgb_buffer.data(), true);

payloader.Close();

Receiving H.264 Video

#include "h264/gst/vaapi/rtp_h264_depayloader.h"

mediax::rtp::h264::gst::vaapi::RtpH264GstVaapiDepayloader depayloader;

mediax::rtp::StreamInformation stream_info;
stream_info.hostname = "239.192.1.1";
stream_info.port = 5004;
stream_info.width = 1920;
stream_info.height = 1080;
stream_info.encoding = mediax::rtp::ColourspaceType::kColourspaceH264Part10;

depayloader.SetStreamInfo(stream_info);
depayloader.Open();
depayloader.Start();

// Receive decoded RGB frames
std::vector<uint8_t> rgb_buffer(1920 * 1080 * 3);
depayloader.Receive(rgb_buffer.data(), 1000);

depayloader.Stop();
depayloader.Close();

Encoder Settings

Quality vs Speed Trade-offs

// These can be configured before Open()
// Higher bitrate = better quality, more bandwidth
// Lower bitrate = lower quality, less bandwidth

Typical Bandwidth Requirements

Resolution Quality Approximate Bitrate
640x480 Good 1-2 Mbps
1280x720 Good 3-5 Mbps
1920x1080 Good 6-10 Mbps
1920x1080 High 15-25 Mbps
3840x2160 Good 25-35 Mbps

RTP Payload Format

MediaX implements RFC 6184 for H.264 RTP payload format:

  • Packetization modes supported: Single NAL, Non-interleaved
  • SPS/PPS in-band signaling
  • FU-A fragmentation for large NAL units

VAAPI Setup

For Intel or AMD hardware acceleration on Linux:

# Ubuntu/Debian
sudo apt install gstreamer1.0-vaapi libva-dev

# Verify VAAPI support
vainfo

NVENC Setup

For NVIDIA hardware acceleration:

# Ubuntu/Debian
sudo apt install gstreamer1.0-plugins-bad nvidia-cuda-toolkit

# Verify NVENC support
nvidia-smi

Troubleshooting

No Hardware Acceleration

If software encoding is used instead of hardware:

  1. Check driver installation
  2. Verify GStreamer plugin availability:

bash gst-inspect-1.0 vaapih264enc gst-inspect-1.0 nvh264enc

High Latency

H.264 introduces encoding/decoding latency:

  • Use low-latency encoder presets when available
  • Reduce buffering in GStreamer pipeline
  • Consider uncompressed video for lowest latency

Support