Skip to content

Lightweight H264 decoding library for V4L2 devices

Notifications You must be signed in to change notification settings

ukicomputers/v4l2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

0e08b00 · · Sep 30, 2025

History

9 Commits
Sep 30, 2025
Sep 30, 2025
Sep 30, 2025
Sep 30, 2025

Repository files navigation

v4l2

An simple, minimal, lightweight and fast, standalone H264 decode library for bare Linux environments meant to be used on very low power Raspberry Pis.

Tested (working) on Raspberry Pi Zero 2W (or any other CPU that contains VideoCore IV graphics).

You can see the demo, usage, and full walkthrough here.

Using

This library is made as a single file - drop decoder.hpp in your project, include it, and interface with it using Decoder class.

Firstly, you need to initialize Decoder by calling Decoder::initializeDecoder function. It requires video width, height, and some other parameters like setting maximal usable memory by the whole program, and changing the decoder path (where Video 4 Linux device is located, by default cases, for Raspberry Pis with video processing unit, it's /dev/video10).

Video device needs to support "single-planar" H264 input with also "single-planar" YU12 (YUV 4:2:0) 8-bit output.

To decode, just call Decoder::decode function, and pass required arguments (input/chunk content and is it EOF). Note that you can pass chunks of any size and it doesn't need to be full file or be some important content of file (you can read chunks of file - and pass chunk by chunk to the decode function). Code handles any inconsistencies. Input must be in Annex-B form (standard).

You will get for output as vector_t> (decoded YUV for each bit stored in vector). See this video for more information about the YUV format. You can later preview the output with any raw pixel preview software, such as ffplay.

After everything (when you are finished decoding), just call Decoder::unload function, or simply, destucture.

Building

decoder.hpp requires headers for V4L2 API - linux-headers need to be installed. Everything else used are standard C++/C libaries. Linking anything to library isn't required.

Running example

This includes building example provided with this project (main.cpp), or just get already compiled executable from Release page.

g++ -O3 main.cpp -o v4l2

After that, you can simply run the executable with ./v4l2. You may need to change some variables in header of main.cpp depending on your video file specification.

Note that on some systems downloaded/compiled executable needs to have permission to execute.

chmod +x ./v4l2

About

Lightweight H264 decoding library for V4L2 devices

Resources

Stars

Watchers

Forks

Languages