ARM64 Ubuntu 22.04编译ffmpeg-sys-next v6.0.1时libavdevice缺失求助
编译ffmpeg-sys-next v6.0.1失败:pkg-config找不到libavdevice库
环境与问题背景
- 系统:ARM64架构Ubuntu 22.04 LTS
- 开发场景:基于
ffmpeg-next包(底层为Rust版FFmpeg)开发MP4与GIF互转程序,通过解码、编码数据包实现格式转换 - 错误触发:执行
cargo build时,ffmpeg-sys-next v6.0.1的自定义构建脚本执行失败,核心错误为pkg-config无法找到libavdevice库
错误日志
error: failed to run custom build command for `ffmpeg-sys-next v6.0.1` Caused by: process didn't exit successfully: `/home/parallels/Downloads/file-conversion-rs/target/debug/build/ffmpeg-sys-next-1aa9b27d2be5c242/build-script-build` (exit status: 101) --- stdout cargo:rerun-if-env-changed=LIBAVUTIL_NO_PKG_CONFIG cargo:rerun-if-env-changed=PKG_CONFIG_aarch64-unknown-linux-gnu # 省略重复的stdout内容 cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR --- stderr thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: `PKG_CONFIG_ALLOW_SYSTEM_CFLAGS="1" PKG_CONFIG_ALLOW_SYSTEM_LIBS="1" "pkg-config" "--libs" "--cflags" "libavdevice"` did not exit successfully: exit status: 1 error: could not find system library 'libavdevice' required by the 'ffmpeg-sys-next' crate --- stderr Package libavdevice was not found in the pkg-config search path. Perhaps you should add the directory containing `libavdevice.pc' to the PKG_CONFIG_PATH environment variable No package 'libavdevice' found ', /home/parallels/.cargo/registry/src/github.com-1ecc6299db9ec823/ffmpeg-sys-next-6.0.1/build.rs:733:22 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
已尝试的操作
- 执行
sudo apt install libavdevice安装失败 - 直接安装ffmpeg包
- 参考GitHub同类问题解决方案,仍无法完成编译
解决方案
1. 安装libavdevice开发包
Ubuntu官方仓库中,libavdevice的开发包(包含pkg-config所需的.pc文件)名为libavdevice-dev,执行以下命令安装:
sudo apt update sudo apt install libavdevice-dev
2. 验证库是否被pkg-config识别
安装完成后,执行以下命令验证:
pkg-config --libs --cflags libavdevice
若输出包含-lavdevice等链接参数,则说明库已被正确识别。
3. 重新编译项目
回到项目目录,重新执行编译命令:
cargo build
备选方案:禁用不必要的FFmpeg组件
如果你的MP4/GIF互转功能不需要avdevice模块,可以修改Cargo.toml,仅启用所需的FFmpeg组件,避免依赖未安装的库:
[dependencies] ffmpeg-next = { version = "6.0.1", default-features = false, features = ["avutil", "avformat", "avcodec", "swscale", "swresample"] }
根据实际功能需求调整features列表,确保只包含必需的组件。
内容的提问来源于stack exchange,提问作者mox
相关产品推荐
相关产品推荐

