3

I'm trying to compile ffmpeg as a standalone binary (because I want to use it in AWS lambda)

I can get things to work fine on the server where I'm compiling, but if I copy the binary and run it from another server, I get:

./ffmpeg: error while loading shared libraries: libvdpau.so.1: cannot open shared object file: No such file or directory

So it sounds like something didn't made it into the binary. From what I've read, I've to compile ffmpeg with the flags --disable-shared and --enable-static, which I've done:

PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
  --prefix="$HOME/ffmpeg_build" \
  --pkg-config-flags="--static" \
  --extra-cflags="-I$HOME/ffmpeg_build/include" \
  --extra-ldflags="-L$HOME/ffmpeg_build/lib" \
  --bindir="$HOME/bin" \
  --disable-shared \
  --enable-static \
  --enable-gpl \
  --enable-libass \
  --enable-libfreetype \
  --enable-libmp3lame \
  --enable-libvpx \
  --enable-libx264
PATH="$HOME/bin:$PATH" make
make install
make distclean
hash -r

Is there something I'm missing?

Guig
  • 9,891
  • 7
  • 64
  • 126

3 Answers3

4

Even though I didn't succeed to compile everything in one binary, I've been able to upload the dependencies to AWS lambda by doing:

copy all dependencies in a folder

I wrote a python script to do that. The script relies on lld to list the dependencies.

#!/usr/bin/env python
import subprocess
import os
from shutil import copyfile

def copyLibraries(bin, destination):
  if not os.path.exists(destination):
    os.makedirs(destination)

  output = subprocess.Popen(["ldd", bin], stdout=subprocess.PIPE).communicate()[0]
  for l in output.split('\n'):
    if len(l.split("=> ")) > 1:
      lib_location = l.split("=> ")[1].split(" ")[0].strip()
      if lib_location != "":
        real_location = os.path.realpath(lib_location)

        lib_name = real_location.split('/')[-1]

        copyfile(real_location, destination + lib_name)

        if os.path.islink(lib_location):
          link_name = lib_location.split('/')[-1]
          if link_name != lib_name:
            os.symlink(real_location, destination + link_name)

copyLibraries("/home/ubuntu/bin/ffmpeg", "/home/ubuntu/libs/")

AWS lambda

  • include the ffmpeg binary as well as the libs folder in the lambda zipped code.
  • in the lambda code, include the corresponding paths. In node.js this can be done as:

.

process.env['PATH'] = process.env['PATH'] +
  ':' +    process.env['LAMBDA_TASK_ROOT'] +
  ':' + process.env['LAMBDA_TASK_ROOT'] + '/bin' +
  ':' + process.env['LAMBDA_TASK_ROOT'] + '/lib';
Guig
  • 9,891
  • 7
  • 64
  • 126
  • i an set process.env['PATH'] same as above given but got error Error: spawn EACCES and i am using aws lamda function and text on aws cli – Pramod Gehlot Dec 01 '18 at 10:40
3

Add --extra-ldexeflags="-static" to get a standalone ffmpeg.

1

--enable-static and --disable-shared only affect libav* binaries. It doesn't prevent linker to use necessary shared object files.

For a pure static lib, this is going to be tricky and mess. You have to build every static lib you need, then try to add additional ldflags to configure.

Another alternative is some tools packing those libs/elfs/binaries into a big one. Some of them are listed here: Pack shared libraries into the elf

Community
  • 1
  • 1
halfelf
  • 9,737
  • 13
  • 54
  • 63
  • Ok I'll try that. Thanks a lot! I'm trying to use that with AWS lambda and I need to upload a binary with everything if I want to use external programs... – Guig Oct 12 '16 at 17:45