将 ffmpeg 编译为独立二进制文件

问题描述 投票:0回答:4

我正在尝试将

ffmpeg
编译为独立的二进制文件(因为我想在 AWS lambda 中使用它)

我可以让事情在我正在编译的服务器上正常工作,但是如果我复制二进制文件并从另一台服务器运行它,我得到:

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

所以听起来好像有些东西没有进入二进制文件。根据我读到的内容,我必须使用标志

--disable-shared
--enable-static
来编译 ffmpeg,我已经完成了:

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

我有什么遗漏的吗?

ffmpeg compilation
4个回答
4
投票

尽管我没有成功地将所有内容编译到一个二进制文件中,但我已经能够通过执行以下操作将依赖项上传到 AWS lambda:

复制文件夹中的所有依赖项

我写了一个 python 脚本来做到这一点。该脚本依赖

lld
来列出依赖项。

#!/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 压缩代码中包含 ffmpeg 二进制文件以及 libs 文件夹。
  • 在 lambda 代码中,包含相应的路径。在
    node.js
    中,可以这样做:

.

process.env['PATH'] = process.env['PATH'] +
  ':' +    process.env['LAMBDA_TASK_ROOT'] +
  ':' + process.env['LAMBDA_TASK_ROOT'] + '/bin' +
  ':' + process.env['LAMBDA_TASK_ROOT'] + '/lib';

3
投票

添加

--extra-ldexeflags="-static"
以获得独立的 ffmpeg。


1
投票

--enable-static
--disable-shared
仅影响
libav*
二进制文件。它不会阻止链接器使用必要的共享对象文件。

对于纯静态库,这将是棘手且混乱的。您必须构建所需的每个静态库,然后尝试添加其他 ldflags 进行配置。

另一种选择是一些工具将这些库/精灵/二进制文件打包成一个大文件。这里列出了其中一些:将共享库打包到 elf 中


0
投票

如果您的开发人员机器上有 Nix,您可以使用一个命令来完成此操作:

nix-build '<nixpkgs>' -A pkgsStatic.ffmpeg-full
# this might take a while, since you're compiling **everything** required by ffmpeg
# once this is done, check that the file is what you need
file ./result/bin/ffmpeg

如果您使用的是 ARM64 Linux 并且需要静态 AMD64,那就不同了。请查看Denis Gosnell 的博客了解更多详细信息。

© www.soinside.com 2019 - 2024. All rights reserved.