How to enable hardware support for H.264 encoding on raspberry Pi 4B
Solution 1
The hardware H.264 encoder on the Raspberry Pi 4 supports only resolutions of 1920x1080 or lower. So there is no hardware support for 4k encoding.
Solution 2
The version of ffmpeg available from apt now has hardware codecs so you can just install that using:
apt install ffmpeg
You can verify their presence like this:
ffmpeg -codecs | grep 'h264_omx\|h264_v4l2m2m'
There are two ways to use the hardware codec - either by using the newer h264_v4l2m2m
or the h264_omx
OMX based one.
Note: The gpu_mem
setting in /boot/config.txt
needs to be greater than 16 - otherwise you will get an error with both codecs.
Related videos on Youtube
MSD Paul
Updated on June 04, 2022Comments
-
MSD Paul about 2 years
I am trying to enable the hardware support for H264 encoding on raspberry pi 4B model. Compiling FFmpeg source enabling the configurations
sudo ./configure --arch=armel --target-os=linux --enable-gpl --enable-omx --enable-omx-rpi --enable-nonfree
following the link, https://github.com/legotheboss/YouTube-files/wiki/(RPi)-Compile-FFmpeg-with-the-OpenMAX-H.264-GPU-acceleration
but while executing the encoding command after building and installing the ffmpeg with those configuration properly, I am getting the following error
[h264_omx @ 0x156b6e0] Using OMX.broadcom.video_encode [h264_omx @ 0x156b6e0] OMX error 80001000 [h264_omx @ 0x156b6e0] err 80001018 (-2147479528) on line 561 Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height Conversion failed!
command used:
ffmpeg -i /media/pi/pic_1_org.png -c:v h264_omx -c:a copy -b:v 1500k outputfile.mp4
I just want to encode a single 4K image into a .mp4 file using H.264 encoder. Please let me know how to resolve this issue?
-
MSD Paul over 4 yearsu correctly pointed out the fact. Can u plz also tell me how to get the exact time needed by H264_omx hardware encoder to encode a video?
-
Markus Schumann over 4 yearsI don’t think I understand your question
-
Caio V. almost 3 yearscan you please give a link with more information on this?