[Tutorial] - Build (or download) FFmpeg/libavcodec with MMAL support (hardware acceleration video decoding)

What is FFmpeg ?

Source wikipedia :

Why I need it ?

FFmpeg is use by a lot of sofware like vlc, firefox, mpv, chromium and a lot more !
It use libavcodec library which is part of FFmpeg which contains all decoders, encoders and parsers of each type of video/audio formats.

Okay, but why I need to build it ? It is on ubuntu mate repository !

Yes you are right, it is on ubuntu mate repository so you can install it by :

sudo apt-get install ffmpeg

But you will not have the accelerated video codecs for the raspberry pi 2 !

What are the video accelerated video codecs available if I rebuild ffmpeg ?

There is only h264_mmal decoder for h264 hardware decoding in the last repository version of unbuntu mate 15.10.1 (ffmpeg 2.7.6).
In the next version (2.8.x) there is also MMAL decoding for mpeg2 and vc1 (but I think you need licence keys from raspberry pi fondation to have this decoders working).

What can I do if I build ffmpeg ?

  • You can read HD video with ffplay.
  • You can build mpv (and maybe vlc ?) with MMAL support (hardware decoding).

How could I get it ?

You can download it livavcodec or build FFmpeg !

Download libavcodec
I build FFmpeg and upload libavcodec debian package.
Open a termnial then type :

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install ffmpeg
wget http://dl.free.fr/vvJO0tZVo -O libavcodec-ffmpeg56_2.7.6-0ubuntu0.15.10.1_armhf.deb

Check the sha1 :

echo “6c4e52bc3580e889342b0b68151c62293d396b3e libavcodec-ffmpeg56_2.7.6-0ubuntu0.15.10.1_armhf.deb” | sha1sum -c -

You must have :

libavcodec-ffmpeg56_2.7.6-0ubuntu0.15.10.1_armhf.deb: OK

If you don’t the archive is corrupted or hacked !

Go to Install libavcodec with mmal support

Build FFmpeg

If you prefer to build it, open a terminal then type :

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install ffmpeg
sudo apt-get build-dep ffmpeg
sudo apt-get install devscripts
mkdir sandbox
cd sandbox
apt-get source ffmpeg
cd ffmpeg-2.7.6

Now, we need to edit rules file :

pluma debian/rules

Then add "–enable-mmal at the end of CONFIG :

CONFIG := --prefix=/usr


Don’t forget to put a backslash (\) after --enable-x11grab !
then save the file.

Type in the terminal :

debuild -b -uc -us

If will be long maybe 2 hours when it finish :

cd …

You will have a lot of .deb file there we only need libavcodec-ffmpeg56 which contains the codecs of ffmpeg.

Install libavcodec with mmal support

sudo dpkg -i libavcodec-ffmpeg56_2.7.6-0ubuntu0.15.10.1_armhf.deb

If you do some upgrade (sudo apt-get upgrade), you will loose the package because it will be updated by the repository version.

You need to deactivate updates on this package :

sudo apt-mark hold libavcodec-ffmpeg56

If you want to update it again from the repository, you can activate updates with :

sudo apt-mark unhold libavcodec-ffmpeg56

Verify installation of libavcodec with mmal support
Now test if libavcodec with h264_mmal decoder is installed :

ffmpeg -codecs | grep h264_mmal

You will have :

DEV.LS h264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_mmal h264_vdpau ) (encoders: libx264 libx264rgb )

Enjoy :wink: