Question

I'm attempting to install an up to date version of ffmpeg on an elastic beanstalk instance on amazon servers. I've created my config file and added these container_commands:

    container_commands:
        01-ffmpeg:
            command: wget -O/usr/local/bin/ffmpeg http://ffmpeg.gusari.org/static/64bit/ffmpeg.static.64bit.2014-03-05.tar.gz
            leader_only: false
        02-ffmpeg:
            command: tar -xzf /usr/local/bin/ffmpeg
            leader_only: false
        03-ffmpeg:
            command: ln -s /usr/local/bin/ffmpeg /usr/bin/ffmpeg
            leader_only: false

Command 01 and 03 seems to work perfectly but 02 doesn't seem to work so ffmpeg doesn't unzip. Any ideas what the issue might be?

Thanks, Helen

Was it helpful?

Solution

A kind person at Amazon helped me out and sent me this config file that works, hopefully some other people will find this useful:

# .ebextensions/packages.config
packages:
  yum:
    ImageMagick: []
    ImageMagick-devel: []
commands:
  01-wget:
    command: "wget -O /tmp/ffmpeg.tar.xz https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz"
  02-mkdir:
    command: "if [ ! -d /opt/ffmpeg ] ; then mkdir -p /opt/ffmpeg; fi"
  03-tar:
    command: "tar xvf /tmp/ffmpeg.tar.xz -C /opt/ffmpeg"
  04-ln:
    command: "if [[ ! -f /usr/bin/ffmpeg ]] ; then ln -sf /opt/ffmpeg/ffmpeg-4.2.2-amd64-static/ffmpeg /usr/bin/ffmpeg; fi"
  05-ln:
    command: "if [[ ! -f /usr/bin/ffprobe ]] ; then ln -sf /opt/ffmpeg/ffmpeg-4.2.2-amd64-static/ffprobe /usr/bin/ffprobe; fi"
  06-pecl:
    command: "if [ `pecl list | grep imagick` ] ; then pecl install -f imagick; fi"

Edit:
The above code works for me today 2020-01-03, in Elastic Beanstalk environment Python 3.6 running on 64bit Amazon Linux/2.9.17.
https://johnvansickle.com/ffmpeg/ is linked from the official ffmpeg site.
(The former static build from Gusari does not seem available anymore.)

Warning:
The above will always download the latest release when you deploy. You're also depending on johnvansickle's site being online (to deploy), and his URL not changing. Two alternative approaches would be:

  • Download the .tar.xz file to your own CDN, and let your deployment download from your own site. (That way, if John's site has a moment of downtime while you're deploying, you're unaffected. And you won't be surprised by the ffmpeg version changing without you realising.)
  • Specify a version number like https://johnvansickle.com/ffmpeg/old-releases/ffmpeg-4.2.2-amd64-static.tar.xz.

OTHER TIPS

You can use a static build from ffmpeg gusari and the sources syntax to automagically download and extract the binaries from a static build tar to /usr/local/bin. Here's an extremely simple example that has worked for me:

sources:
    /usr/local/bin: https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-64bit-static.tar.xz

The version is not specified in the first command "01-wget ..." however, it is specified when linking the files. Since the publication of this the release has been changed from "ffmpeg-3.3.1-64bit-static" to "ffmpeg-3.3.3-64bit-static" there are two solutions to fix this problem:

  1. specify the version for wget
  2. strip the containing directory on unpacking.

    03-tar: command: "tar xvf /tmp/ffmpeg.tar.xz -C /opt/ffmpeg --strip 1"

Here is the full script:

packages:
  yum:
    ImageMagick: []
    ImageMagick-devel: []
commands:
  01-wget:
    command: "wget -O /tmp/ffmpeg.tar.xz https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-64bit-static.tar.xz"
  02-mkdir:
    command: "if [ ! -d /opt/ffmpeg ] ; then mkdir -p /opt/ffmpeg; fi"
  03-tar:
    command: "tar xvf /tmp/ffmpeg.tar.xz -C /opt/ffmpeg --strip 1"
  04-ln:
    command: "if [[ ! -f /usr/bin/ffmpeg ]] ; then ln -s /opt/ffmpeg/ffmpeg /usr/bin/ffmpeg; fi"
  05-ln:
    command: "if [[ ! -f /usr/bin/ffprobe ]] ; then ln -s /opt/ffmpeg/ffprobe /usr/bin/ffprobe; fi"
  06-pecl:
    command: "if [ `pecl list | grep imagick` ] ; then pecl install -f imagick; fi"

add the following to your .ebextensions/packages.config

packages:
  yum:
    ImageMagick: []

sources:
  /usr/local/bin: http://ffmpeg.org/releases/ffmpeg-4.1.tar.gz

Check cloud-init logs for messages. On a Linux instance, that would be:

grep "03-ffmpeg" /var/log/eb-cfn-init.log

Also, you can log to another file to make errors easier to find:

command: ln -s /usr/local/bin/ffmpeg /usr/bin/ffmpeg >> /var/log/my-init.log

Untested, but shouldn't it be

tar xzf /usr/local/bin/ffmpeg

without a minus?

In case there are others out there that prefers compiling from source, herewith steps I've actioned to do so (this worked for me using a Java Application with Maven)

  1. Inside your project root directory, create a ".ebextensions" folder containing a file name of your convenience but it must have the extension of ".config" (see example picture) example-ebextensions-config-file
  2. Specify the following as the contents of the .ebextensions/yourfilename.config file
packages:
    yum:
        autoconf: []
        automake: []
        cmake: []
        freetype-devel: []
        gcc: []
        gcc-c++: []
        git: []
        libtool: []
        make: []
        nasm: []
        pkgconfig: []
        zlib-devel: []
        ImageMagick: []
        ImageMagick-devel: []
commands:
    01-mkdir:
        command: |
            if [ ! -d /opt/bin ] ; then mkdir -p /opt/bin; fi
            if [ ! -d /opt/ffmpeg ] ; then mkdir -p /opt/ffmpeg; fi
            if [ ! -d /opt/ffmpeg/ffmpeg-5.1-build ] ; then mkdir -p /opt/ffmpeg/ffmpeg-5.1-build; fi
    02-wget:
        command: |
            if [ ! -d /opt/ffmpeg/ffmpeg-5.1 ] ; then
                if [ ! -d /tmp/ffmpeg-5.1.tar.gz ] ; then wget -O /tmp/ffmpeg-5.1.tar.gz https://ffmpeg.org/releases/ffmpeg-5.1.tar.gz; fi
                tar xvf /tmp/ffmpeg-5.1.tar.gz -C /opt/ffmpeg
            fi
    03-configure:
        cwd: /opt/ffmpeg/ffmpeg-5.1
        command: |
            if [[ ! -f /opt/bin/ffmpeg ]] ; then
                PKG_CONFIG_PATH="/opt/ffmpeg/ffmpeg-5.1-build/lib/pkgconfig" \
                ./configure \
                --prefix="/opt/ffmpeg/ffmpeg-5.1-build" \
                --pkg-config-flags="--static" \
                --bindir="/opt/ffmpeg/ffmpeg-5.1-build/bin" \
                --enable-gpl \
                --enable-libx264 \
            fi
    04-make:
        cwd: /opt/ffmpeg/ffmpeg-5.1
        command: |
            if [[ ! -f /opt/bin/ffmpeg ]] ; then
                make && make install
            fi
    05-link:
        command: if [[ ! -f /usr/bin/ffmpeg ]] ; then ln -sf /opt/ffmpeg/ffmpeg-5.1-build/bin/ffmpeg /usr/bin/ffmpeg; fi

Herewith a summary of the steps that will be executed when your update is deployed to elastic beanstalk

  1. Packages will be configured on your instance e.g in case your instance doesn't have cmake, it will be installed as per the "packages" section as per the configuration in .ebextensions/yourfilename.config file
  2. Once all dependencies are resolved, the commands section will execute (I've discovered that they don't depend on one another e.g. if step#1 fails, step#2 will still be executed)
  3. Command 01: Creates directories where your files will be unarchived to (amongst other things)
  4. Command 02: Downloads the tar from the release website, places it into your instance's temp folder then unarchives it into your instance's /opt/ffmpeg/ folder. It's worth mentioning that the archive contains a folder "ffmpeg-5.1". Thus, when it's unarchived, you'll have a directory "/opt/ffmpeg/ffmpeg-5.1". This entire step won't execute if the folder "/opt/ffmpeg/ffmpeg-5.1" already exists i.e. this step was most likely executed during a previous deploy/update to your instance
  5. Command 03 & Command 04: Configures ffmpeg. You can checkout the ffmpeg documentation for different configurations as per your requirement
  6. Command 05: Creates a symlink from the installation directory to your usr/bin folder. This is required as the /opt directory is not managed by your ec2-user (requires root access) and therefor when you run ffmpeg from /opt or its subdirectories, your Java application may throw an Access Denied or Permission relates issues

This one worked fine with me, installed last ffmpeg version on AWS Elastic Beanstalk, just generate a folder with the name .ebextensions and name this file as: ffmpeg.config

# .ebextensions/ffmpeg.config

packages:
  yum:
    autoconf: []
    automake: []
    cmake: []
    freetype-devel: []
    gcc: []
    gcc-c++: []
    git: []
    libtool: []
    make: []
    nasm: []
    pkgconfig: []
    zlib-devel: []
sources:
  /usr/local/src: http://ffmpeg.org/releases/ffmpeg-4.2.9.tar.bz2
commands:
  ffmpeg_install:
      cwd: /usr/local/src/ffmpeg-4.2.9
      command: sudo ./configure --prefix=/usr && make && make install
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top