Hardware h264 video encoding with libav (openmax IL)

Good new libav implements hardware video encoding with OpenMax IL implementation !
See : http://www.phoronix.com/scan.php?page=news_item&px=Libav-OMX-H264-MPEG4
I github trunck get and compile it on my RPI 3 under ubuntu mate with openmax il hardware h264 encoding :slight_smile:
I am not very good with video encoding I will make some tests next week and post here !
I hope ffmpeg will implement it soon too !
Stay tune !



This sounds like it could be interesting to people wanting to use their Raspberry Pi as a media server… Over the Internet videos often need transcoding to lower bit rates, wondering if this will make that possible. Looking forward to your test results!

I have done some tests it works great !
I download a DVD sample file in mpeg2 format and convert it to h264 mp4 video.
Encoding resultuts :

  • software encoding : ~20 frames per second
  • hardware encoding : ~145 frames per second
    So it works great !
    I have a problem with HD Videos is it not fast but I know why !
    In avconv command I can set the encoder codec but I don’t know if I can setup a video decoder codec.
    I explain when it encode the video the frames are decoded but using sofware decoding …
    I don’t know if it is a way to set it ?
    Have anyone an idea ?

forgive my ignorance, but is there something special you have to do to compile the project to tell it to use the pi’s hardware encoder?

Yes some flags when you do configure.
I will post a tutorial about it tonight or tomorrow :wink:
Stay tune !


1 Like

Hehe can’t wait! Been thinking about Pi3 as a network accessed encoder (Do NAE’s Exist? Guess it will now) for setting up streaming from my desktop as something fun. Do a bit of compression on the desktop to lower bandwidth usage, really compress it on Pi then off to twitch.tv maybe?

To install it, open a terminal :

sudo apt-get build-dep ffmpeg
git clone https://github.com/libav/libav --depth 1
cd libav/
./configure --enable-static --enable-omx-rpi --enable-mmal
make -j4

Now you can launch avconv,avplay and avprobe from the directory !

Example convert some mpeg2 DVD vidéo file :

./avconv -i TRAILER_SAMPLE.VOB -c:a copy -c:v h264_omx -b:v 404k trailer-sample.mp4

Exemple lowering byterate on h264 1080p video :

./avconv -i sample-1080.mp4 -c:a copy -c:v h264_omx -b:v 404k sample.mp4

It run fast ~25fps !!!
With software encoding it run at 8 fps !

Edit : correct some errors

If you try to resize video hd and resample it it run slow because of resizing, maybe we need some neon optimisations for that …

wonder how long until ffmpeg incorporates this code into their project. Thx for the info on how to compile

It is done in ffmpeg too in last git snapshot :slight_smile:

it’s done

  1. update to latest version: “git pull”

  2. add “–enable-omx –enable-omx-rpi” to ./configure options

  3. recompile

  4. use encoder option “-c:v h264_omx”

There seems to be a bug here when I try to convert a recording from tvheadend (Rpi2):
“Assertion ret <= 0 failed at libavcodec/utils.c:1956”
Does anybody know what’s this?

had the same problem. simply comment out that line, it works anyway :wink:

Guys (and Gals). This is totally amazing and what I’ve been TRYING to do for ages. I have a DVB-T tuner on OpenElec and I too want a way of minimising the file sizes. I’m running the above commands and I get an output but it needs a bit of tweaking as it produces several artifacts particulalry in motion. Are there any presets I’m missing, I know with libx254 there are various presets (-preset medium) but when I try doing something similar I just get erros as '-preset is unknown. I have tried increasing the bit rate to 808K, but just wondered if anyone had any other tips for making a good output copy? Any options to do double pass. The time taken is not really an issue as I plan to create some sort of script that can be run once a recording is completed! Either through TVHeadEnd or monitoring a Samba share.

Please keep this thread alive and updated. I think NAE IS now a thing! My Pi3 is on ALL the time!

this does not work on raspberry pi 3 running raspbian…

command sudo apt-get build-dep ffmpeg fails with “E: You must put some ‘source’ URIs in your sources.list” and even with ffmpeg built from git, another error comes up: Assertion ret <= 0 failed at libavcodec/utils.c:1963

alright, after modifying the source as suggested above, it runs, but transoding h264 1080i @ 15Mbps to h264_omx still kills the raspberry, CPU running at 150%, resulting in choppy video - any suggestions?

I don’t think there is presets for now and maybe there will never be.
I explain, it is a GPU compression and the implementation in ffmpeg or libav is very basic OMX encoding.
So I didn’t find anything for it.
I don’t know if the hardware (GPU) could support some presets anyway.
So the first step is hardware issue, we need to ask the foundation or broadcom if they are hardware presets and after if it exist implement it.
The only thing you can do and maybe work is change the bitrate maybe.

What king of video did you try to encode ?
Did you change the video resolution or another transformations ?

I’ll own that I’m necro-ing the thread here. It’s a bit more interesting than just that (though this would very probably rock for being able to transcode from MPEG2 -> h.264 with an MPEG2 license and that specific role…)

What if you needed an industrial device…say one of the Pi-on-Module 3’s about to show up?

What if you needed h.264 video?

It’s really broader than you think- and I have the Pi Foundation, The Pi Trading Company, and Broadcom to thank for it.