How to use hardware encoding in ffmpeg (h264_omx) on Raspberry Pi 4 running Ubuntu

17,048

You might need to build a custom version of FFmpeg to use the hardware encoder on Raspberry Pi. Make sure the --enable-omx and --enable-omx-rpi flag is enabled when configuring the FFmpeg build (see the links below for build steps). These flags indicate that build FFmpeg with Raspberry Pi-specific OpenMAX encoder, which is silghtly different from the normal version of the OpenMAX encoder (e.g. they dependend on different .so libraries).

See also

Steps to build FFmpeg for RPi with the h264_omx encoder:

http://www.redhenlab.org/home/the-cognitive-core-research-topics-in-red-hen/the-barnyard/hardware-encoding-with-the-raspberry-pi

Why the FFmpeg binary provided from Raspbian repo doesn't support MMAL and OpenMAX codecs:

https://www.raspberrypi.org/forums/viewtopic.php?t=184425#p1166882

Share:
17,048

Related videos on Youtube

Michael Freeborn
Author by

Michael Freeborn

Updated on September 18, 2022

Comments

  • Michael Freeborn
    Michael Freeborn almost 2 years

    I'm nearly finished migrating my RPi4 4GB to Ubuntu 19.10 with Gnome - it is running better than I thought it would.

    I've got one remaining hurdle for the moment: using the h264_omx hardware encoder with ffmpeg (currently does work with the h264 software encoder). Essentially I'm trying to livestream one of my cameras to Youtube, which was working well previously on Raspbian.

    This is the command I am running:

    ffmpeg -nostdin -r 14.5 -i http://192.168.1.250:8080/html/cam_pic_new.php?pDelay=66666 -f lavfi -i anullsrc -b:v 2M -b:a 128k -c:v h264_omx -ar 22050 -f flv rtmp://a.rtmp.youtube.com/live2/<CODE>

    The output is:

    [h264_omx @ 0xaaaac8884580] libOMX_Core.so not found
    [h264_omx @ 0xaaaac8884580] libOmxCore.so not found
    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
    

    I've Googled extensively today, installing/compiling various things.

    I've tried installing libomxil-bellagio-dev and libomxil-bellagio-bin as well as numerous guides for compiling ffmpeg on RPi all to no avail. I can never seem to get past the initial C compiler test... it fails with errors such as gcc: error: missing argument to '-mcpu='.

    Anyone got any thoughts... this is really bugging me now as I can't have the Youtube stream at the moment without 70%+ CPU usage!