ToB企服应用市场:ToB评测及商务社交产业平台

标题: fedora 安装 ffmpeg 过程记录 [打印本页]

作者: 写过一篇    时间: 6 天前
标题: fedora 安装 ffmpeg 过程记录
  1. 参考博客:
  2.     1. linux(centos)安装 ffmpeg,并添加 libx264库:https://blog.csdn.net/u013015301/article/details/140778199
  3. ffmpeg 执行时如添加参数 -vcodec libx264,会出现错误:Unknown encoder 'libx264’的错误,缺少libx264库,需要安装该库,安装步骤如下:
  4.     $ 代表普通用户 # 代表root权限
  5. 确认 linux版本为 fedora:
复制代码
  1. cat /etc/*-release
  2.     Amazon Linux release 2023.5.20240819 (Amazon Linux)
  3.     NAME="Amazon Linux"
  4.     VERSION="2023"
  5.     ID="amzn"
  6.     ID_LIKE="fedora"    // !!!!!!
  7.     VERSION_ID="2023"
  8.     PLATFORM_ID="platform:al2023"
  9.     PRETTY_NAME="Amazon Linux 2023.5.20240819"
  10.     ANSI_COLOR="0;33"
  11.     CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2023"
  12.     HOME_URL="https://aws.amazon.com/linux/amazon-linux-2023/"
  13.     DOCUMENTATION_URL="https://docs.aws.amazon.com/linux/"
  14.     SUPPORT_URL="https://aws.amazon.com/premiumsupport/"
  15.     BUG_REPORT_URL="https://github.com/amazonlinux/amazon-linux-2023"
  16.     VENDOR_NAME="AWS"
  17.     VENDOR_URL="https://aws.amazon.com/"
  18.     SUPPORT_END="2028-03-15"
  19.     Amazon Linux release 2023.5.20240819 (Amazon Linux)
复制代码
  1.    
  2. 2. 安装步骤
  3.     此步骤包含安装nasm、x264和ffmpeg。
  4.     2.1 安装nasm
  5.         2.1.1 下载nasm
  6.             下载地址:wget https://www.nasm.us/pub/nasm/releasebuilds/2.14/nasm-2.14.tar.gz
  7.         2.1.2 解压
  8.             tar -zxvf nasm-2.14.tar.gz
  9.         2.1.3 进入nasm目录
  10.             cd nasm-2.14
  11.         2.1.4 执行nasm配置
  12.             执行:./configure
  13.         2.1.5 编译nasm
  14.             执行:make
  15.         2.1.6 安装nasm
  16.             sudo make install
  17.         2.1.7 查看是否安装成功
  18.             nasm -v
  19.     2.2 x264 安装
  20.         2.2.1 下载x264
  21.             下载地址:git clone https://code.videolan.org/videolan/x264.git
  22.         2.2.2 进入x264目录
  23.             cd x264
  24.         2.2.3 执行x264配置
  25.             注:如果不将include和lib安装在/usr/local目录,之后运行ffmpeg命令时可能仍然报错误
  26.             ./configure --prefix=/usr/x264/ --includedir=/usr/local/include --libdir=/usr/local/lib --enable-shared
  27.         2.2.4 编译x264
  28.             执行:
  29.                 make
  30.         2.1.6 安装x264
  31.             make install
  32.         2.1.7 x264配置环境变量
  33.             编辑bashrc文件,执行:
  34.                 vim ~/.bashrc
  35.             在最后PATH添加环境变量:
  36.                 export PATH="/usr/local/nasm/bin:$PATH"
  37.                 export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
  38.             保存退出。
  39.             设置生效,执行:source ~/.bashrc
  40.         2.1.8 验证是否安装成功
  41.             pkg-config --libs x264
  42.     2.3 安装 ffmpeg
  43.         2.3.1 下载ffmpeg
  44.             下载地址:wget https://ffmpeg.org//releases/ffmpeg-6.1.tar.gz
  45.         2.3.2 解压
  46.             tar -zxvf ffmpeg-6.1.tar.gz
  47.         2.3.3 进入ffmpeg目录
  48.             cd ffmpeg-6.1
  49.         2.3.4 执行ffmpeg配置
  50.             ./configure --enable-gpl --enable-libx264 --enable-shared --extra-ldflags=-L/usr/local/lib --extra-cflags=-I/usr/local/include
  51.         2.3.5 编译ffmpeg
  52.             执行:
  53.                 make
  54.         2.3.6 安装ffmpeg
  55.             sudo make install
  56.         2.3.7 配置环境变量
  57.             编辑/etc/profile文件,执行:
  58.                 vi /etc/profile
  59.             在文件的最后位置添加环境变量:
  60.                 export PATH=$PATH:/usr/local/ffmpeg/bin
  61.             刷新资源,使其生效,执行:source /etc/profile
  62.         2.3.8 验证是否安装成功
  63.             ffmpeg -version
  64.         2.3.9 ffmpeg卸载
  65.             使用root用户登录
  66.             停止ffmpeg进程
  67.                 sudo pkill ffmpeg
  68.             卸载ffmpeg
  69.                 sudo yum remove ffmpeg
  70.             删除ffmpeg的配置文件和数据
  71.                 sudo rm -rf /usr/local/etc/ffmpeg /usr/local/share/ffmpeg /usr/local/share/doc/ffmpeg /usr/local/share/man/man1/ffmpeg*
  72. 3 遇到过的异常
  73.     3.1 ERROR: x264 not found using pkg-config
  74.             说明后缀指定的地址不对,这里x264有三个包,根据大家安装的地址确定 后缀的地址。
  75.             如上文安装的 包
  76.             ./configure --prefix=/usr/x264/ --includedir=/usr/local/include --libdir=/usr/local/lib --enable-shared
  77.             那么 咱们的包就是 /usr/local/include,/usr/local/lib
  78.             这里有了后,还需要一个pkg-config 包,这样,就能解决这个报错了。用来存放x264.pc
  79.             我们的pkg-config 包 可以看下地址 /usr/local/lib/pkgconfig
  80.             解决方案1:
  81.                 vim /etc/profile
  82.                 末尾加入内容export PKG_CONFIG_PATH=/usr/local/x264/lib/pkgconfig,具体看各位自己x264的安装路径
  83.                 source /etc/profile
  84.                 然后再./configure ...就没问题了
  85.             解决方案2:
  86.                 这个错误信息表示在运行 ./configure 配置脚本时,检测到 libx264 库没有被找到。这可能是由于缺少 libx264 库或者没有正确安装 libx264 的开发包引起的。
  87.                 执行:
  88.                     sudo yum install pkgconfig
  89.                     export PKG_CONFIG_PATH="/path/to/libx264/lib/pkgconfig"
  90.     3.2 libavcodec/libavcodec.so: undefined reference to `x264_param_cleanup’
  91.         这个错误表明在链接 libavcodec 库时,编译器无法找到或解析 x264_param_cleanup 函数。这可能是由于 libx264 版本不匹配或编译选项不正确引起的。
  92.         以下是一些建议:
  93.             (1)检查 libx264 版本:确保你的 libx264 版本与 ffmpeg 兼容。有时,特定版本的 ffmpeg 可能需要特定版本的 libx264。尽量使用较新的版本。
  94.             (2)重新编译 libx264:如果你手动编译了 libx264,请尝试重新编译并安装,确保编译选项正确。可以尝试使用以下步骤:
  95.                 bashCopy code
  96.                 cd path/to/x264/source
  97.                 make distclean
  98.                 ./configure --enable-shared
  99.                 make
  100.                 sudo make install
  101.                 然后,重新编译 ffmpeg。
  102.             (3)检查 libx264 的链接选项:确保在链接 libavcodec 时,正确引用了 libx264 库。你可以在编译 ffmpeg 时,通过 lx264 或 llibx264 选项来指定链接 libx264 库。
  103.             例如,你可以在 ffmpeg 的 configure 阶段添加 --extra-libs=-lx264:
  104.                 ./configure --enable-libx264 --extra-libs=-lx264
  105.                 然后,继续编译 ffmpeg。
  106.     3.3 No package ‘x264’ found
  107.         pkg-config --modversion x264
  108.         Package x264 was not found in the pkg-config search path.
  109.         Perhaps you should add the directory containing `x264.pc’
  110.         to the PKG_CONFIG_PATH environment variable
  111.         No package ‘x264’ found
  112.         (1)设置 PKG_CONFIG_PATH:
  113.             如果找到了 libx264.pc 文件,请将其路径添加到 PKG_CONFIG_PATH 环境变量中。例如:
  114.             bashCopy code
  115.             export PKG_CONFIG_PATH=/path/to/directory/containing/libx264.pc:$PKG_CONFIG_PATH
  116.             请将 /path/to/directory/containing/ 替换为实际的目录路径。
  117.             如果 libx264.pc 文件在 /usr/lib/pkgconfig/ 中,可以运行:
  118.             bashCopy code
  119.             export PKG_CONFIG_PATH=/usr/lib/pkgconfig:$PKG_CONFIG_PATH
  120.         (2)重新运行 configure:
  121.             在重新运行 ./configure 之前,请确保清理之前的编译残留:
  122.             bashCopy code
  123.             make distclean
  124.             然后重新运行 configure:
  125.         bashCopy code
  126.         ./configure --enable-gpl --enable-shared --enable-libx264
  127.         3.4 x264 安装好了,可以看到版本信息,但是pkg-config --libs x264 查询报错
  128.         x264 --version
  129.         x264 0.164.3173 4815cca
  130.         (libswscale 5.5.100)
  131.         built on Feb  1 2024, gcc: 4.8.5 20150623 (Red Hat 4.8.5-44)
  132.         x264 configuration: --chroma-format=all
  133.         libx264 configuration: --chroma-format=all
  134.         x264 license: GPL version 2 or later
  135.         libswscale license: nonfree and unredistributable
  136.         WARNING: This binary is unredistributable!
  137.         [root@VM-16-10-centos x264]# pkg-config --libs libx264
  138.         Package libx264 was not found in the pkg-config search path.
  139.         Perhaps you should add the directory containing `libx264.pc'
  140.         to the PKG_CONFIG_PATH environment variable
  141.         No package 'libx264' found
  142.         [root@VM-16-10-centos x264]# pkg-config --libs x264
  143.         Package x264 was not found in the pkg-config search path.
  144.         Perhaps you should add the directory containing `x264.pc'
  145.         to the PKG_CONFIG_PATH environment variable
  146.         No package 'x264' found
  147.         在这种情况下,问题可能是 x264.pc 文件不在默认的 pkg-config 搜索路径中。通常来说,x264.pc 文件应该在 lib 或 lib/pkgconfig 目录下。
  148.         如果找到 x264.pc 文件,请将其路径添加到 PKG_CONFIG_PATH 环境变量中:
  149.         export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
  150.         根据你的输出,pkg-config 仍然无法找到 libx264 的信息。在这种情况下,有几个可能的原因:
  151.         (1)libx264 的 .pc 文件不存在或未正确安装: .pc 文件是由 libx264 的开发包提供的,用于告诉 pkg-config 如何链接到该库。确保你已经安装了 libx264 的开发包,或者手动指定 libx264 的路径。
  152.         (2)PKG_CONFIG_PATH 未正确设置: 确保 PKG_CONFIG_PATH 包含 libx264 的 .pc 文件所在的目录。你可以通过运行以下命令来设置:
  153.             bashCopy code
  154.             export PKG_CONFIG_PATH=/path/to/libx264/pkgconfig:$PKG_CONFIG_PATH
  155.             其中 /path/to/libx264/pkgconfig 是包含 libx264.pc 文件的目录路径。
  156.         (3)libx264 的库文件不在默认的库加载路径中: 尝试将 libx264 的库路径添加到 LD_LIBRARY_PATH 中:
  157.             bashCopy code
  158.             export LD_LIBRARY_PATH=/path/to/libx264/lib:$LD_LIBRARY_PATH
  159.             其中 /path/to/libx264/lib 是包含 libx264.so 文件的目录路径。
  160.             请注意,确保替换上述命令中的 /path/to/libx264 为你系统上 libx264 的实际路径。完成这些步骤后,再次运行 pkg-config 或者 ./configure,看看问题是否解决。
  161. 3.5 ffmpeg: error while loading shared libraries: libavdevice.so.60: cannot open shared object file: No such file or directory
  162.     // 首先查找 libavdevice.so.60
  163.     sudo find / -name libavdevice.so.60
  164.     //查找发现 path
  165.     /usr/local/lib
  166.     // 配置文件中是否存在,换行追加对应路径
  167.     vim /etc/ld.so.conf
  168.     // include ld.so.conf.d/*.conf
  169.     // /usr/local/lib
  170.     // wq!保存退出
  171.     // 更新库配置
  172.     sudo ldconfig
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4