Hardware Accelerated Video Decoding on Raspberry Pi with FFmpeg

This article provides a comprehensive guide on how to leverage the Raspberry Pi’s GPU for hardware-accelerated video decoding using FFmpeg on Linux. By shifting the heavy lifting from the CPU to the Pi’s dedicated multimedia hardware, you can drastically reduce CPU utilization, lower system temperatures, and achieve smooth playback of high-definition video streams. Below, you will find the required prerequisites, configuration steps, and the specific FFmpeg commands needed to enable hardware acceleration.

Understanding Raspberry Pi Hardware Decoders

Different generations of the Raspberry Pi utilize different hardware decoding blocks, which dictates the codecs they support at the hardware level.

To achieve hardware acceleration in FFmpeg on modern Linux distributions like Raspberry Pi OS (Bullseye or Bookworm), you must use the standard Linux V4L2 M2M (Memory-to-Memory) codecs rather than the deprecated MMAL or OpenMAX APIs.

Verifying FFmpeg Support

Before running a decoding task, you need to ensure that your compiled version of FFmpeg includes the necessary V4L2 wrappers. You can check for available hardware-accelerated decoders by running the following command in your terminal:

ffmpeg -decoders | grep v4l2

Look for the following entries in the output list:

If these codecs do not appear, you may need to update your system packages or compile FFmpeg from the official source with the --enable-v4l2-m2m flag configured.

Executing the FFmpeg Command

To force FFmpeg to offload the decoding process to the Raspberry Pi GPU, you must explicitly declare the V4L2 M2M wrapper as an input parameter before defining your input file. This tells FFmpeg to initialize the GPU hardware pipeline immediately upon opening the stream.

Use the following command structure for an H.264 encoded video:

ffmpeg -c:v h264_v4l2m2m -i input_video.mp4 -c:v rawvideo -f null -

For an H.265 (HEVC) encoded video on a Raspberry Pi 4 or 5, substitute the codec parameter like this:

ffmpeg -c:v hevc_v4l2m2m -i input_video.mkv -c:v rawvideo -f null -

Explaining the Command Parameters

Verifying GPU Offloading

While your FFmpeg decoding command is actively running, you can open a secondary terminal window to verify that the CPU load remains low, indicating that the GPU is successfully handling the heavy lifting. Run the standard system monitor tool:

htop

If hardware acceleration is working correctly, the CPU usage per core will typically hover in the low double digits or single digits, even when processing a high-bitrate 1080p or 4K video stream. If the CPU utilization spikes toward 100% across all cores, FFmpeg has likely fallen back to software decoding due to an unsupported profile or an incorrect input codec string.