Installing FFMPEG for Raspberry Pi


FFMPEG is one of those tools I use when I just want to quickly hack together a video and don’t need fancy things like editing, titles, or a user-interface. Compiling on a regular computer isn’t easy, but compiling for the Raspberry Pi takes a little more patience and care. I also wanted to include support for H264 video, which needs to be installed before compiling FFMPEG.

There are lots of examples on the web, but what worked for me was a combination of a few of them, so here’s what I did. Note many of these commands may require  sudo appended before (commands like git , ./configure, and make )

    Run the following commands, one at a time.
    Anything else you would like to install should be done now, before compiling FFMPEG. This includes MP3, AAC, etc.
    Add lines similar to the  --enable-libx264  for anything else installed above. This may take a REALLY long time, so be patient.

    As Malcshour notes, if you have a Model B+ you can use make -j4  instead of just make  to take advantage of all four cores!

    To test your new install, simply run the command ffmpeg . If you don’t get any errors, you’re all good. What did I do with my new tool? I built a bot that generates random guitar chords.


Did you find this post helpful or interesting? A small donation goes a long way towards helping produce this content. If you can't, please share what you've done with others!Donate via Flattr

34 thoughts on “Installing FFMPEG for Raspberry Pi”

  1. It should be pretty easy. This guide says to use the following commands (one-by-one in the Terminal):

    tar xzvf lame-3.99.tar.gz
    cd lame-3.99
    make install

  2. For anyone getting

    “Cloning into ‘ffmpeg’…
    fatal: The remote end hung up unexpectedly”


    git clone git:// ffmpeg


  3. Took more than 3 hours to compile ffmpeg on a Raspberry PI Model A+, i went to sleep after so i don’t know the exact time it took, but that VERY long process for this machine. And I’m only talking about «sudo make» for ffmpeg… Installing h264 took me almost 2 hours too…

    So don’t expect to do this quickly if you don’t have a day to spend on this.

    Also, like Alex said, the ffmpeg source git repo is now:

    git clone git:// ffmpeg
    instead of:
    git clone git://

    Many thanks Jeff, for the tutorial.

  4. I’m getting “illegal hardware instruction” error when trying to use ffmpeg. Also same error occurs if I run compiled x264 binary.

  5. Hmm, not sure what’s causing that. That means you’re trying to compile for a device with different hardware than the Pi. Are you definitely including the --arch=armel command? Unfortunately, this could also be an issue in the newest version of FFMPEG as well.

  6. PS: If someone has this error:
    “ar: libavcodec/libavcodec.a: No space left on device
    library.mak:40: recipe for target ‘libavcodec/libavcodec.a’ failed
    make: *** [libavcodec/libavcodec.a] Error 1”

    Don’t worry to run “sudo raspi-config” and select the first option “expend Filesystem”. this will use the whole SD card size. Then reboot your RPI and run once again the command: sudo make, etc. (sorry for my English, I’m french)

  7. Followed the steps to the letter and things seemed to work without error messages. However, when I type ffmpeg at the end of it all, I get the message

    -bash: ffmpeg: command not found

    Any ideas??

  8. Hmm. Have you tried rebooting the Pi and then trying it again? It might take a restart to show up. Otherwise, I might just try installing again and see what happens. Error messages on the Pi don’t always appear, even when there is an error.

  9. Sorry, when i use “make”, i have this error…

    libavdevice/lavfi.c: In function \u2018lavfi_read_packet\u2019:
    libavdevice/lavfi.c:433:9: warning: \u2018avpicture_get_size\u2019 is deprecated (declared at ./libavcodec/avcodec.h:4828) [-Wdeprecated-declarations]
    size = avpicture_get_size(frame->format, frame->width, frame->height);
    libavdevice/lavfi.c:437:9: warning: \u2018data\u2019 is deprecated (declared at ./libavcodec/avcodec.h:3614) [-Wdeprecated-declarations]
    memcpy(, frame->data, 4*sizeof(frame->data[0]));
    libavdevice/lavfi.c:438:9: warning: \u2018linesize\u2019 is deprecated (declared at ./libavcodec/avcodec.h:3616) [-Wdeprecated-declarations]
    memcpy(pict.linesize, frame->linesize, 4*sizeof(frame->linesize[0]));
    libavdevice/lavfi.c:440:9: warning: \u2018avpicture_layout\u2019 is deprecated (declared at ./libavcodec/avcodec.h:4820) [-Wdeprecated-declarations]
    avpicture_layout(&pict, frame->format, frame->width, frame->height,

  10. Just a quick tip:
    If you have a Model B+ (4-Cores) you can do “make -j4” instead of just “make” to make it use all four cores instead of just one.
    Speeds up the process quite a bit!

    Thanks for that great article!

  11. I guess I will that since my Pi always has some ressources to spare.
    Also, it’s the Pi 2 B that has 4 cores, not the B+.

  12. Can I play a preview of the video after ffmpeg finishes?
    Using R-Pi Model B
    It does a great job, but when recording finishes, I put omxplayer av.mkv command after the ffmpeg command (using python), but omxplayer plays the av.mkv file form my previous attempt. It looks like omxplayer may be starting before ffmpeg finishes saving the new av.mkv file.
    Any suggestions? (I am fairly new to Pi and python, so have mercy!)

  13. Are you trying to do this as one script (ie write to ffmpeg and then play)? If so, omxplayer is probably starting to run before ffmpeg finishes – since ffmpeg writes to streams, they can be played even when they’re not done. I would look at the Python subprocess module (which might be what you’re using) and specifically Popen’s communicate() method.

  14. you said the b+ has 4 cores it does not the pi 2 and pi 3 does and thats where you would use -j 4 command on make and make install

  15. git clone git://
    fatal: could not create work tree dir ‘xx’.: Permission denied

    What do I do to this?

  16. You’re probably trying to clone into a directory you don’t have permission to write to. You should either use the cd command to move into a different directory, or use the sudo command and enter your password to get access (ie: sudo git clone git://

  17. Running the ffmpeg configure script (after installing libx264) I’m getting ‘ERROR: libx264 not found’. Anyone else getting this? I’m sure there’s something I’m doing wrong here.
    Thanks for the excellent tutorial. Does ffplay use the RPI 3’s GPU acceleration for playing rtsp streams? Trying to get over the omxplayer latency issue.

  18. Hmm, this is an error from installing H264 support. You could try running ffmpeg with a different codec and see if that works to confirm. I would suggest uninstalling everything and starting again.

  19. Before I try:
    What OS are you using?
    Do you manage to play ffmpeg in HD?
    Thanky for this great post!

  20. Hi Michael,

    I’m encoding – not playing ;-) I use stock Raspbian jessie with latest rpi-update:

    hje@picam:~$ cat /etc/issue
    Raspbian GNU/Linux 8 \n \l
    hje@picam:~$ uname -a
    Linux picam 4.4.8-v7+ #880 SMP Fri Apr 22 21:55:04 BST 2016 armv7l GNU/Linux

    Compilation was easy, the only thing I changed was commenting out a line in libavcodec/utils.c (line 1956). Return code seems to be codec->encode2(avctx, avpkt, frame, got_packet_ptr);
    // av_assert0(ret <= 0);

    I'm using it to create daily timelapse videos from my webcam. The webcam creates 1280×720 images every 10 seconds via uvccapture. In the past I used gstreamer for encoding but these videos couldn't be played over html5 embedded tag. IMHO gstreamer maybe ok for a professional AV system – but not for a tiny embedded system such like Raspberry. So I’m very happy now that ffmpeg can do the job and I don’t need this stupidly overloaded gstreamer shit anymore…

  21. Hi,

    I’ve used Technoid’s valuable instructions to rebuild my custom ffmpeg, incorporating hardware h264 encoding.
    After commenting out line 1956 in libavcodec/utils.c [ av_assert0(ret <= 0); ], I'm able to run ffmpeg with the new encoder.

    Unfortunately the results when transcoding video are somewhat underwhelming. The resultant file is massively compressed, and always 1MB regardless of which switches I pass (constant rate factor, scaling, audio codec etc)

    A discussion on github suggests that it's very early days for the hardware h264 encoder, but I wondered if anyone else has had better results?

    For the record, encoding a 30 second audio video file of an Atari ST demo screen:

    Hardware: Raspberry Pi 3, overclocked to 1350mhz

    Encoder: omx_h264
    Resultant file: very poor framerate, blurry
    File size: 1MB
    Encoding speed – solid 10 fps, c. 22% cpu (total across all cores)
    /home/pi/bin/ffmpeg -i hatari_bmp-atg-megademo_stretch-scroller.avi -c:v h264_omx -crf 1 -r 25 -pix_fmt yuv420p -vf scale=-1:ih*2 -c:a aac output-hard264.mp4

    Encoder: libx264
    Resultant file: video and audio quality are flawless
    File size: 38MB
    Encoding speed: 7 -10 fps, c 93% cpu across all cores
    /home/pi/bin/ffmpeg -i hatari_bmp-atg-megademo_stretch-scroller.avi -c:v libx264 -crf 1 -r 25 -pix_fmt yuv420p -vf scale=-1:ih*2 -c:a aac output-standard_h264.mp4

  22. Thanks Jeff & teknoid!
    The installation described worked without any problems on a Pi3 with Raspbian Jessie (via Noobs v1.9.1 form 10. May 2016).

    But actually I misunderstood the whole topic, as ffmpeg here strictly means the video conversion tool and not the codec for video playing as I had thought!

    My goal is to make one of the seamless video loopers play ProRes/FFmpeg content in something like 1920×1200 px. My content has very clean gradients which easily get messed up by the common compression methods. I´ll keep fiddling around…
    Or does anybody here have advise for
    – playback of ffmpeg
    – best seamless video looper
    (both for RaspberryPi 3) ?

Leave a Reply

Your email address will not be published. Required fields are marked *