Introduction to H.265/HEVC
High Efficiency Video Coding (HEVC/H.265) provides 50% better compression than H.264 at equivalent quality. This guide covers implementation strategies for embedded surveillance systems.
Codec Architecture Overview
H.265 introduces several improvements over H.264:
| Feature | H.264 | H.265 |
|---|---|---|
| Block size | 16x16 max | 64x64 max (CTU) |
| Intra prediction | 9 modes | 35 modes |
| Motion compensation | Quarter-pel | Quarter-pel + bi-prediction |
| Transform | 4x4, 8x8 | 4x4 to 32x32 |
| Loop filter | Deblocking | Deblocking + SAO |
Hardware Encoder Integration
V4L2 Stateful Encoder API
Linux systems use V4L2 for hardware codec access:
// Open encoder device
int fd = open("/dev/video-enc", O_RDWR);
// Set output format (encoded H.265)
struct v4l2_format fmt = {0};
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
fmt.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_HEVC;
fmt.fmt.pix_mp.width = 1920;
fmt.fmt.pix_mp.height = 1080;
ioctl(fd, VIDIOC_S_FMT, &fmt);
// Set input format (raw YUV)
fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
fmt.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_NV12;
ioctl(fd, VIDIOC_S_FMT, &fmt);Encoder Parameters
Critical encoding parameters for surveillance applications:
- Profile: Main or Main 10 (for HDR)
- Level: 5.1 supports 4K@60fps
- Tier: High tier for higher bitrates
- Slice structure: Single slice for low latency
- Entropy coding: CABAC only (no CAVLC)
H.265 Main profile is sufficient for most surveillance applications. Main 10 is only needed for 10-bit color depth or HDR content.
Rate Control Modes
H.265 encoders support various rate control strategies:
| Mode | Description | Surveillance Use |
|---|---|---|
| CBR | Constant bitrate | NVR recording, bandwidth planning |
| VBR | Variable bitrate | Quality-critical scenes |
| CQP | Constant QP | Testing, benchmarking |
| CVBR | Capped VBR | Balanced quality/bandwidth |
Smart Encoding Features
Region of Interest (ROI)
ROI encoding allocates more bits to important areas:
// Define ROI region
struct v4l2_ext_control ctrl = {0};
ctrl.id = V4L2_CID_MPEG_VIDEO_ROI;
ctrl.size = sizeof(struct v4l2_enc_roi);
struct v4l2_enc_roi roi = {
.left = 100,
.top = 100,
.width = 400,
.height = 300,
.qp_delta = -10 // Higher quality
};
ctrl.ptr = &roi;Smart Codec (H.265+)
Vendor-specific extensions reduce bandwidth for static scenes:
- Background modeling: Encode static regions at lower quality
- Skip frame insertion: Insert skip frames for unchanging scenes
- Dynamic GOP: Extend GOP during low-motion periods
- Typical savings: 50-70% bandwidth reduction for typical surveillance
Decoder Considerations
Client-side H.265 decoding requirements:
- Hardware acceleration essential for 4K playback
- Intel Quick Sync, NVIDIA NVDEC, ARM Mali widely supported
- Browser support limited (Safari, Edge; Chrome via extensions)
- VLC, FFmpeg provide software fallback
Bitrate Guidelines
| Resolution | Frame Rate | Recommended Bitrate |
|---|---|---|
| 1080p | 30 fps | 2-4 Mbps |
| 1080p | 60 fps | 4-6 Mbps |
| 4K | 30 fps | 8-12 Mbps |
| 4K | 60 fps | 15-20 Mbps |
Conclusion
H.265 implementation in embedded systems requires careful attention to hardware capabilities, rate control, and client compatibility. When properly configured, H.265 delivers significant storage and bandwidth savings while maintaining video quality.