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

时间:2016-10-11 16:49:10

标签: ffmpeg compilation

我正在尝试将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

我有什么遗失的吗?

3 个答案:

答案 0 :(得分:4)

即使我没有成功编译一个二进制文件中的所有内容,我也可以通过执行以下操作将依赖项上传到AWS lambda:

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

我写了一个python脚本来做到这一点。该脚本依赖<div>列出依赖项。

<?php
//error_reporting(0);

//conexion a la base de datos
$link = mysqli_connect("localhost","root","","delher");
if ($link===false){
    die("ERROR: NO SE PUDO CONECTAR.".mysqli_connect_error());
}


//declaracion de variables
$null = NULL;
$nombre = ($_POST['nombre']);
$calle_num = ($_POST['calle_num']);
$colonia = ($_POST['colonia']);
$codigopostal = ($_POST['codigopostal']);
$ciudad = ($_POST['ciudad']);
$estado = ($_POST['estado']);
$pais = ($_POST['pais']);
$telefono_fijo = ($_POST['telefono_fijo']);
$telefono_movil = ($_POST['telefono_movil']);
$email = ($_POST['email']);
$curp = ($_POST['curp']);
$vin = ($_POST['vin']);
$marca = ($_POST['marca']);
$modelo = ($_POST['modelo']);
$linea = ($_POST['linea']);
$motor = ($_POST['motor']);
$color = ($_POST['color']);
$placas = ($_POST['placas']);

//multiquery mysqli...

//inserta campos del cliente en la tabla clientes
$sql = "INSERT INTO cliente (nombre, calle_num, colonia, codigopostal, ciudad, estado, pais, telefono_fijo, telefono_movil, email, curp) VALUES ('$nombre','$calle_num','$colonia','$codigopostal','$ciudad','$estado','$pais','$telefono_fijo','$telefono_movil','$email','$curp');";

//inserta los campos del vehiculo en la tabla vehiculo
$sql = "INSERT INTO vehiculo (vin, marca, modelo, linea, motor, color, placas) VALUES ('$vin','$marca','$modelo','$linea','$motor','$color','$placas')";





//
if(mysqli_multi_query($link,$sql)){
    echo "Orden registrada correctamente!
    En 3 segundos se redirigira a la pagina anterior.";
    header( "refresh:3; url=index.php" );
}
else{
    echo "ERROR: No se pudo ejecutar $sql." .mysql_error($link);
}




//cierra conexion
mysqli_close($link);
?>

AWS lambda

  • 在lambda压缩代码中包含ffmpeg二进制文件和libs文件夹。
  • 在lambda代码中,包含相应的路径。在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/")

答案 1 :(得分:1)

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

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

另一种选择是将一些libs / elfs / binaries打包成一个大的工具。其中一些列在此处:Pack shared libraries into the elf

答案 2 :(得分:0)

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