Installing FFMPEG for Raspberry Pi

ffmpegOnRaspberryPi-web

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 )

  1. INSTALL H264 SUPPORT
    Run the following commands, one at a time.
  2. INSTALL OTHER LIBRARIES/FORMATS
    Anything else you would like to install should be done now, before compiling FFMPEG. This includes MP3, AAC, etc.
  3. INSTALL FFMPEG
    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!

    DONE! TEST IT
    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.

A FEW MORE RESOURCES

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

86 Replies to “Installing FFMPEG for Raspberry Pi”

  1. I get the below error when i run make for ffmpeg

    libavfilter/libavfilter.a(allfilters.o): In function avfilter_register_all':
    /home/pi/Documents/digital_factory/FFmpeg/libavfilter/allfilters.c:381: undefined reference to
    ff_vf_paletteuse’
    /home/pi/Documents/digital_factory/FFmpeg/libavfilter/allfilters.c:381: undefined reference to ff_vf_perspective'
    /home/pi/Documents/digital_factory/FFmpeg/libavfilter/allfilters.c:381: undefined reference to
    ff_vf_phase’
    /home/pi/Documents/digital_factory/FFmpeg/libavfilter/allfilters.c:381: undefined reference to ff_vf_pixdesctest'
    /home/pi/Documents/digital_factory/FFmpeg/libavfilter/allfilters.c:381: undefined reference to
    ff_vf_pp’
    /home/pi/Documents/digital_factory/FFmpeg/libavfilter/allfilters.c:381: undefined reference to ff_vf_pp7'
    /home/pi/Documents/digital_factory/FFmpeg/libavfilter/allfilters.c:381: undefined reference to
    ff_vf_premultiply’
    /home/pi/Documents/digital_factory/FFmpeg/libavfilter/allfilters.c:381: undefined reference to ff_vf_psnr'
    /home/pi/Documents/digital_factory/FFmpeg/libavfilter/allfilters.c:381: undefined reference to
    ff_vf_pullup’
    /home/pi/Documents/digital_factory/FFmpeg/libavfilter/allfilters.c:381: undefined reference to ff_vf_qp'
    /home/pi/Documents/digital_factory/FFmpeg/libavfilter/allfilters.c:381: undefined reference to
    ff_vf_random’
    /home/pi/Documents/digital_factory/FFmpeg/libavfilter/allfilters.c:381: undefined reference to ff_vf_readeia608'
    /home/pi/Documents/digital_factory/FFmpeg/libavfilter/allfilters.c:381: undefined reference to
    ff_vf_readvitc’
    /home/pi/Documents/digital_factory/FFmpeg/libavfilter/allfilters.c:381: undefined reference to ff_vf_remap'
    /home/pi/Documents/digital_factory/FFmpeg/libavfilter/allfilters.c:381: undefined reference to
    ff_vf_removegrain’
    /home/pi/Documents/digital_factory/FFmpeg/libavfilter/allfilters.c:381: undefined reference to ff_vf_removelogo'
    /home/pi/Documents/digital_factory/FFmpeg/libavfilter/allfilters.c:381: undefined reference to
    ff_vf_repeatfields’
    /home/pi/Documents/digital_factory/FFmpeg/libavfilter/allfilters.c:381: undefined reference to ff_vf_rotate'
    /home/pi/Documents/digital_factory/FFmpeg/libavfilter/allfilters.c:381: undefined reference to
    ff_vf_sab’
    /home/pi/Documents/digital_factory/FFmpeg/libavfilter/allfilters.c:381: undefined reference to ff_vf_scale'
    /home/pi/Documents/digital_factory/FFmpeg/libavfilter/allfilters.c:381: undefined reference to
    ff_vf_scale2ref’
    collect2: error: ld returned 1 exit status
    Makefile:131: recipe for target ‘ffmpeg_g’ failed
    make: *** [ffmpeg_g] Error 1

  2. At Point 3 it gives me an error because the ffmepg dir is in capital letters.

    It should be:

    cd /usr/src
    git clone https://github.com/FFmpeg/FFmpeg.git
    cd FFmpeg
    sudo ./configure –arch=armel –target-os=linux –enable-gpl –enable-libx264 –enable-nonfree
    make
    sudo make install

  3. Hi,
    I have used these commands on RPi 3 and it worked fine.
    Now, If I want to “copy” the ffmpeg installation to another RPi3, what files should I copy so that I dont have to build the whole thing again on the new RPi3?

  4. While “sudo make” fpr ffmpeg via SSH I got the following error
    packet_write_wait: Connection to 192.168.0.35 port 22: Broken pipe
    Is there a way to resume the session? Or is the “making” continuing when the session breaks?

    CC libavcodec/vp9block.o
    CC libavcodec/vp9data.o
    CC libavcodec/vp9dsp.o
    CC libavcodec/vp9dsp_10bpp.o

    these were the last lines before it broke?
    Should I just wait a few hours and the continue with sudo make install?

  5. @HansWurst – I don’t think there’s a way to resume an SSH session that breaks like that. I think you’ll have to start over. For this install, probably better to do it locally, if possible, since it can take a really (really) long time.

  6. yeah, I realized that. So you don’t know if it continues when the session breaks? I might just try to sudo make install tomorrow in the morning. If it continued it should be done by then…

  7. My personal experience (yours may be different): I have compiled/installed OpenCV 2.x and 3.x on all versions of RPi expect the first generation A board. In all these cases except for the RPI 0 W, I relied on RDP (xrdp on RPi and Windows RDP client on the desktop). Long running sessions would be disconnected on the desktop but the RPi would chug along merrily and upon RDP re-connection I could see the “make” continuing.

    For the RPi 0 W, the board would trip at the 88% make mark consistently (for Open CV 3.2), so I resorted to SSH for this instance only and the “make” proceeded to completion. I guess it must be memory issue for this platform.

    I’ll try out your steps using RDP first. If it doesn’t work I will have to resort to SSH or even use the direct terminal connection for the first time (I bought the cable but I haven’t had a pressing need to try it out).

    Thanks again for sharing and guiding us. Regards.

  8. Make install stops with an error:
    make: *** No rule to make target ‘є’, needed by ‘ffmpeg.o’. Stop.

    What am I doing wrong? I am following the steps exactly and I have Raspberry Pi 1B.

  9. for step 2 how do i instal mp3 or mp4 acc? Im on the github site for the master ffmpeg and there is no guide to install it on a raspberry pi. can any 1 help a noob?

  10. Hi, i’m a beginner when it comes to libraries for rpi video streaming. I realise that you can find the list of available supported formats for ffmpeg on the wiki, but is there a list available of the libraries required for those formats. You talked about libaac, or libmp3.

  11. Nathan – I’m not sure, you may have to check manually for each one. It is also possible that dependencies will be installed automatically, but it’s equally possible they won’t and you’ll have to fully re-install ffmpeg again, which is a total pain.

  12. When I try to run ffmpeg command, I get error: bash: ffmpeg: command not found

    I got a lot of warnings during the installation process.

  13. Hi Jeff, I am trying to install it again.
    When i try this:
    –disable-opencl
    bash: –disable-opencl: command not found

    so I used sudo:

    (cv) pi@pi:/usr/src/x264 $ sudo –disable-opencl
    sudo: unrecognized option ‘–disable-opencl’
    usage: sudo -h | -K | -k | -V
    usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user]
    usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user]
    [command]
    usage: sudo [-AbEHknPS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p
    prompt] [-u user] [VAR=value] [-i|-s] []
    usage: sudo -e [-AknS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p
    prompt] [-u user] file …
    this is what i got.

    Thank you very much

  14. @Sumu – Hmm that’s not a full command. sudo just means run a command as the “super user” (ie with admin privileges). These kind of installs are *really* picky so be sure to follow each command exactly and in the right order.

  15. @Sumu – looks to me like you’re new to the command line? sudo on it’s own isn’t a command, it just enables you to run other commands as the admin. I’d suggest taking a look at a command line tutorial to familiarize yourself with the basics – it will make this all waaay less frustrating :)

    It looks like you’re trying to run the configure file, which should be this command (and no sudo):
    ./configure --host=arm-unknown-linux-gnueabi --enable-static --disable-opencl

  16. I receive warnings like these when i use sudo make command, while installing ffmpeg

    fftools/ffmpeg_opt.c: In function ‘add_input_streams’:
    fftools/ffmpeg_opt.c:777:13: warning: ‘codec’ is deprecated [-Wdeprecated-declarations]
    if (st->codec->lowres) {
    ^~
    In file included from fftools/cmdutils.h:30:0,
    from fftools/ffmpeg.h:28,
    from fftools/ffmpeg_opt.c:23:
    ./libavformat/avformat.h:878:21: note: declared here
    AVCodecContext *codec;
    ^~~~~
    fftools/ffmpeg_opt.c:778:17: warning: ‘codec’ is deprecated [-Wdeprecated-declarations]
    ist->dec_ctx->lowres = st->codec->lowres;
    ^~~
    In file included from fftools/cmdutils.h:30:0,
    from fftools/ffmpeg.h:28,
    from fftools/ffmpeg_opt.c:23:
    ./libavformat/avformat.h:878:21: note: declared here
    AVCodecContext *codec;
    ^~~~~

  17. I successfully compiled ffmpeg on RasPi 2. Hardware encoding worked, but after encoding for 5 to 30 minutes, ffmpeg just hang / freezed. The status line just stayed the same. After looong searching, I found out, that this was a bug, related to (afaik) new firmware. Ffmpeg just got patched like a week ago. I didn’t try to compile again, I just used the latest binary version “7:3.2.10-1~deb9u1+rpt3”, also has hardware decoding+encoding support for Pi.
    More info here: https://github.com/raspberrypi/firmware/issues/1087

  18. I just setup a new system with Raspbian, and ffmpeg is in the repository – you don’t need to build it anymore. It supports h264, of course, pretty slow, but it does work. Suggest a heat sink as well.

  19. Hi there,

    I am trying to make a camera work with HomeKit by using ffmpeg.
    I installed it via the homebridge UI but couldn’t make it work. I thought of reinstalling ffmpeg, which is how I found this website.

    Now, when I am in the terminal on my Mac (following your directions), and I type in
    git clone git://git.videolan.org/x264, I get the error code fatal: could not create work tree dir ‘x264’: Permission denied.

    I am totally new to the code line, but I am surprised that I can’t make changes in the terminal even though I am logged into my Raspberry as an admin.

    Would really appreciate your help!

    Best regards,

  20. @Lucas: my guess is that you probably need to add sudo to the start of the command. You’ll put in your password which should give you permission. Hope that works!

  21. @Lucas @Jeff
    Workaround for step 1:
    git clone git://git.videolan.org/x264
    is now
    git clone https://code.videolan.org/videolan/x264.git
    (the original page says they moved: https://git.videolan.org/)

    I also ran into a problem when running sudo make for ffmpeg during step 3, it popped up after ~2 hours of make running:


    In file included from fftools/ffmpeg.c:43:
    ./libavformat/avformat.h:884:21: note: declared here
    AVCodecContext *codec;
    ^~~~~
    LD ffmpeg_g
    /usr/bin/ld: libavformat/libavformat.a(fifo.o): in function
    fifo_init’:
    /usr/src/FFmpeg/libavformat/fifo.c:519: undefined reference to __atomic_store_8'
    /usr/bin/ld: libavformat/libavformat.a(fifo.o): in function
    fifo_write_trailer’:
    /usr/src/FFmpeg/libavformat/fifo.c:624: undefined reference to __atomic_fetch_add_8'
    /usr/bin/ld: /usr/src/FFmpeg/libavformat/fifo.c:631: undefined reference to
    __atomic_store_8′
    /usr/bin/ld: libavformat/libavformat.a(fifo.o): in function fifo_thread_write_packet':
    /usr/src/FFmpeg/libavformat/fifo.c:188: undefined reference to
    __atomic_fetch_sub_8′
    /usr/bin/ld: libavformat/libavformat.a(fifo.o): in function fifo_consumer_thread':
    /usr/src/FFmpeg/libavformat/fifo.c:457: undefined reference to
    __atomic_load_8′
    /usr/bin/ld: libavformat/libavformat.a(fifo.o): in function fifo_write_packet':
    /usr/src/FFmpeg/libavformat/fifo.c:597: undefined reference to
    __atomic_fetch_add_8′
    collect2: error: ld returned 1 exit status
    make: *** [Makefile:121: ffmpeg_g] Error 1
    `

  22. I try to run this on raspbian desktop in a vm. But at Step 3 I get an error with the “configure-command”: “gcc is unable to create an executable file. C compiler test failed.”

  23. Hi, thank you very much for these blog post.
    I get this error when i run sudo make to install the H264 support:

    libx264.a(mc-a-10.o): relocation R_ARM_MOVW_ABS_NC against a local symbol' can not be used when making a shared object; recompile with -fPIC
    libx264.a(mc-a-8.o): in function
    memcpy_table’:
    (.data.rel.ro+0x0): dangerous relocation: unsupported relocation.

    I’ve not been able to find a way around it. Please help me on how to resolve this. Thank you very much.

    My OS is Ubuntu Mate 20.04.1 armhf

Leave a Reply

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