8

在 Ubuntu 12.04 上安装 ffmpeg

我收到以下错误

libavcodec/libavcodec.a(libx264.o): In function `X264_init':
/root/ffmpeg/libavcodec/libx264.c:492: undefined reference to `x264_encoder_open_125'
collect2: ld returned 1 exit status
make: *** [ffmpeg_g] Error 1

我正在按照 http://ffmpeg.org/trac/ffmpeg/wiki/UbuntuCompilationGuide中的说明进行操作

有人知道这个错误吗?

4

3 回答 3

9

对于已经通过包管理系统安装了 x264 的人来说,这是一个典型的问题。您至少可以通过两种方式解决此问题:

  1. 通过包管理系统从系统中卸载已经存在的 x264:

    # apt-get remove x264
    

    从源代码编译您的新 x264

  2. 不要卸载 x264 包,而是编译你的新 x264然后编译你的 ffmpeg,告诉它使用新编译的 x264 库,通过指定你编译的 x264 库所在的目录,使用提到的LD_LIBRARY_PATH环境变量:

    LD_LIBRARY_PATH=/path/to/my/compiled/x264/library ./configure --enable-libx264 ...
    

可以在这些链接上找到更多信息:

于 2013-06-18T16:56:11.323 回答
0

通常,该错误意味着libx264.so链接器获取的库二进制文件与头文件中的版本不匹配x264.h。请参阅此头文件中的以下代码行:

/* Force a link error in the case of linking against an incompatible API version.
 * Glue #defines exist to force correct macro expansion; the final output of the macro
 * is x264_encoder_open_##X264_BUILD (for purposes of dlopen). */
#define x264_encoder_glue1(x,y) x##y
#define x264_encoder_glue2(x,y) x264_encoder_glue1(x,y)
#define x264_encoder_open x264_encoder_glue2(x264_encoder_open_,X264_BUILD)

解决方案通常不需要自己构建libx264,只要确保自己安装libx264-dev正确,不干扰其他版本,其他版本也可能在/usr/local/lib等。

我对版本 155 有同样的问题: undefined reference to 'x264_encoder_open_155'. 就我而言,这是因为我有/usr/lib/x86_64-linux-gnu一份不合适的副本libx264.so(我自己制作并在那里复制不干净)。所以我所要做的就是sudo apt-get install --reinstall libx264-dev

于 2020-10-17T21:01:36.347 回答
0

添加头文件和库路径

gcc x264_test1.c -o x264_encoder -I/usr/local/include -L/usr/local/lib -lpthread -lm -lx264

于 2018-10-15T06:41:33.630 回答