CentOS Compile ffmpeg libx264 not found

本文详细介绍了在CentOS环境下编译FFmpeg时遇到libx264未找到错误的解决方案。通过在配置过程中增加--extra-ldflags=-ldl参数来支持动态链接装入器libdl,解决了引用顺序问题,并提供了正确设置库顺序以避免后续错误的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

CentOS Compile ffmpeg libx264 not found

首先 CentOS make install x264时,只将x264可执行文件install到/usr/local/bin,还需要make install-lib-static

此时./configure --disable-yasm --enable-libx264 --enable-gpl --enable-static --enable-shared还是出现

ERROR: libx264 not found

查看config.log发现:

/ Usr/local/lib/libx264.a (opencl.o): In function `x264_opencl_load_library ':
opencl.c: (. text +0 x411): undefined reference to `dlopen '
opencl.c: (. text +0 x42b): undefined reference to `dlsym '
opencl.c: (. text +0 x448): undefined reference to `dlsym '
opencl.c: (. text +0 x465): undefined reference to `dlsym '
opencl.c: (. text +0 x482): undefined reference to `dlsym '
opencl.c: (. text +0 x49f): undefined reference to `dlsym '

### 此时增加--extra-ldflags=-ldl 支持动态链接装入器libdl(它有4个库函数 dlopen, dlerror, dlsym, dlclose)

./configure --disable-yasm --enable-libx264 --enable-gpl --enable-static --enable-shared --extra-ldflags=-ldl
configure成功。


使用库时注意顺序(在Mac上没有出现这种引用顺序问题),

LIBS += /usr/local/lib/libavformat.a
LIBS += /usr/local/lib/libavdevice.a
LIBS += /usr/local/lib/libavcodec.a
LIBS += /usr/local/lib/libavutil.a
LIBS += /usr/local/lib/libx264.a


否则会出现错误:

/usr/local/lib/libavformat.a(allformats.o): In function `av_register_all':
allformats.c:(.text+0x1b): undefined reference to `avcodec_register_all'

ac3dec.c:(.text+0x112): undefined reference to `ff_ac3_parse_header'
/usr/local/lib/libavformat.a(adtsenc.o): In function `ff_adts_decode_extradata':
adtsenc.c:(.text+0x68): undefined reference to `ff_mpeg4audio_get_config'
adtsenc.c:(.text+0x175): undefined reference to `ff_copy_pce_data'
/usr/local/lib/libavformat.a(aiffdec.o): In function `aiff_read_header':
aiffdec.c:(.text+0x5de): undefined reference to `av_get_bits_per_sample'

/usr/local/lib/libavformat.a(utils.o): In function `ff_add_index_entry.clone.2':
utils.c:(.text+0x48d8): undefined reference to `av_fast_realloc'
/usr/local/lib/libavformat.a(utils.o): In function `av_new_stream':
utils.c:(.text+0x4c37): undefined reference to `avcodec_alloc_context'
/usr/local/lib/libavformat.a(utils.o): In function `ff_interleave_add_packet.clone.3':
utils.c:(.text+0x553e): undefined reference to `av_dup_packet'

### 如何解决安装 FFmpeg 时遇到的 `libx264` 缺失问题 当尝试使用 FFmpeg 进行推流并指定编码器为 `libx264` 时,如果系统提示未知编码器或无法加载共享库,则表明缺少必要的依赖项。具体表现为: 错误信息如下: ``` Unknown encoder 'libx264' error while loading shared libraries: libx264.so.158: cannot open shared object file: No such file or directory ``` #### 安装缺失的 `libx264` 库 为了使 FFmpeg 能够识别并正常使用 H.264 编码器,在编译前需先安装对应的开发包。 对于基于 Red Hat 的发行版(如 CentOS),可以通过以下命令来获取所需的软件包: ```bash yum groupinstall "Development Tools" yum install nasm yasm zlib-devel openssl-devel ``` 接着下载最新版本的 x264 源代码,并按照官方说明完成配置与构建过程: ```bash cd /usr/src/ git clone https://code.videolan.org/videolan/x264.git cd x264 ./configure --enable-shared --prefix=/usr/local/ffmpeg make && make install ``` 注意:确保指定了正确的安装路径以便后续链接操作能够顺利进行[^1]。 #### 配置环境变量 为了让动态链接器知晓新加入的 `.so` 文件位置,建议编辑 `/etc/profile.d/custom.sh` 或者用户的 shell profile 文件(比如 `~/.bashrc`),追加 LD_LIBRARY_PATH 变量定义: ```bash export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/ffmpeg/lib source ~/.bashrc # 刷新当前终端会话中的设置 ldconfig # 更新缓存以生效更改 ``` 此时再次运行原测试用例应该不会再有类似的报错了。 #### 编译带有外部支持的 FFmpeg 版本 假设已经成功部署好了上述组件之后,继续参照文档指南去定制化地组装最终产物——即具备完整功能特性的多媒体处理工具集: ```bash cd /usr/src/ wget http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 tar jxf ffmpeg-snapshot.tar.bz2 cd ffmpeg PKG_CONFIG_PATH="/usr/local/ffmpeg/lib/pkgconfig" ./configure \ --extra-cflags="-I/usr/local/ffmpeg/include" \ --extra-libs=-L"/usr/local/ffmpeg/lib" \ --bindir=/usr/local/bin \ --enable-gpl \ --enable-libx264 make -j$(nproc) && make install ``` 通过这种方式可以确保所使用的 FFmpeg 支持最新的硬件加速特性以及广泛的格式兼容性[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值