2025年5月20日 星期二 乙巳(蛇)年 二月廿二 设为首页 加入收藏
rss
您当前的位置:首页 > 计算机 > 系统应用 > Linux

Linux源码编译安装ffmpeg(带libx264安装)

时间:02-17来源:作者:点击数:32

1. 准备工作

ffmpeg下载地址

官网下载地址

选择要安装的版本进行下载即可。

libx264下载地址

下载地址

也可以通过git命令进行下载,方法如下:

  • # git clone https://code.videolan.org/videolan/x264.git

说明:如果需要视频转码必须要先安装libx264,否则会转码失败

2. 安装

2.1 安装libx264

  1. 解压libx264安装包
  • [root@172-16-8-145 ~]# tar -zxvf x264.tar.gz
  1. 编译
  • [root@172-16-8-145 x264]# ./configure --enable-shared
  • [root@172-16-8-145 x264]# make
  1. 安装
  • [root@172-16-8-145 x264]# make install
  1. 验证
  • [root@172-16-8-145 x264]# x264 --version
  • x264 0.161.3048 b86ae3c
  • built on Feb 18 2021, gcc: 7.3.0
  • x264 configuration: --chroma-format=all
  • libx264 configuration: --chroma-format=all
  • x264 license: GPL version 2 or later
  • [root@172-16-8-145 x264]#

能正确显示版本号说明安装成功。

2.2安装ffmpeg

  1. 解压ffmpeg安装包,我这里下载的是4.3版本
  • tar -zxvf ffmpeg-4.3.tar.gz
  1. 编译
  • [root@172-16-8-145 ffmpeg-4.3]# ./configure --enable-shared --enable-swscale --enable-gpl --enable-nonfree --enable-pic --prefix=/home/ffmpeg --enable-version3 --enable-postproc --enable-pthreads --enable-static --enable-libx264
  • [root@172-16-8-145 ffmpeg-4.3]# make

必须先安装libx264,否则这步会报错,缺少libx264的库

  1. 安装
  • [root@172-16-8-145 ffmpeg-4.3]# make install
  1. 配置环境变量

在/etc/profile文件最后增加如下内容

  • export ffmpeg_home=/home/ffmpeg
  • export PATH=${ffmpeg_home}/bin:$PATH

然后通过source使配置文件生效即可。

  1. 验证
  • [root@172-16-8-145 bin]# ffmpeg --version
  • ffmpeg version 4.3 Copyright (c) 2000-2020 the FFmpeg developers
  • built with gcc 7.3.0 (GCC)
  • configuration: --enable-shared --enable-swscale --enable-gpl --enable-nonfree --enable-pic --prefix=/home/ffmpeg --enable-version3 --enable-postproc --enable-pthreads --enable-static --enable-libx264
  • libavutil 56. 51.100 / 56. 51.100
  • libavcodec 58. 91.100 / 58. 91.100
  • libavformat 58. 45.100 / 58. 45.100
  • libavdevice 58. 10.100 / 58. 10.100
  • libavfilter 7. 85.100 / 7. 85.100
  • libswscale 5. 7.100 / 5. 7.100
  • libswresample 3. 7.100 / 3. 7.100
  • libpostproc 55. 7.100 / 55. 7.100
  • Unrecognized option '-version'.
  • Error splitting the argument list: Option not found
  • [root@172-16-8-145 bin]#

能正常显示版本号说明安装成功。

3. 常见问题:

问题现象:

  • [root@172-16-8-145 bin]# ./ffmpeg --version
  • ./ffmpeg: error while loading shared libraries: libavdevice.so.58: cannot open shared object file: No such file or directory

排查过程:

  1. 通过ldd ffmpeg命令可以看到缺少哪些库,如下:
  • [root@172-16-8-145 bin]# ldd ffmpeg
  • linux-vdso.so.1 (0x0000fffc106b0000)
  • libavdevice.so.58 => not found
  • libavfilter.so.7 => not found
  • libavformat.so.58 => not found
  • libavcodec.so.58 => not found
  • libpostproc.so.55 => not found
  • libswresample.so.3 => not found
  • libswscale.so.5 => not found
  • libavutil.so.56 => not found
  • libm.so.6 => /lib64/libm.so.6 (0x0000fffc105b0000)
  • libpthread.so.0 => /lib64/libpthread.so.0 (0x0000fffc10570000)
  • libc.so.6 => /lib64/libc.so.6 (0x0000fffc103e0000)
  • /lib/ld-linux-aarch64.so.1 (0x0000fffc106c0000)
  • [root@172-16-8-145 bin]#
  1. 通过find命令查找这些文件
  • [root@172-16-8-145 bin]# find / -name 'libavdevice.so.58'
  • /root/ffmpeg-4.3/libavdevice/libavdevice.so.58
  • /home/ffmpeg/lib/libavdevice.so.58
  • [root@172-16-8-145 bin]#

从上面的结果可以说明libavdevice.so.58库在root和home目录下,这样我们把这个目录引用一下就可以了

  1. 引用相关目录

在/etc/profile文件中的最后增加如下内容

  • export LD_LIBRARY_PATH=/home/ffmpeg/lib/

然后使文件生效

  • [root@172-16-8-145 bin]# source /etc/profile

这样问题就解决了。

方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门