1
--- 空白行 ---

参考博客:https://www.jianshu.com/p/1be929404528,更新为4.4版本。

一、Linux下安装ffmpeg

1
2
官网下载:http://ffmpeg.org/download.html
直接下载:wget http://www.ffmpeg.org/releases/ffmpeg-4.4.tar.gz

二、解压

1
2
tar -xjvf ffmpeg-4.4.tar.bz2
cd ffmpeg-4.4/

三、错误处理

1
2
3
4
5
6
7
8
9
10
11
[root@slave ffmpeg-4.1]# ./configure 
gcc is unable to create an executable file.
If gcc is a cross-compiler, use the --enable-cross-compile option.
Only do this if you know what cross compiling means.
C compiler test failed.

If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.

错误的意思是 yasm/nasm 包不存在或者很旧,可以使用–disable-yasm禁用这个选项编译,yasm是一款汇编器,并且是完全重写了nasm的汇编环境,接收nasm和gas语法,支持x86和amd64指令集,所以这里安装一下yasm即可。

四、安装yasm

1
2
3
4
5
6
7
8
9
官网下载:http://yasm.tortall.net/Download.html
直接下载:wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz

解压、编译、安装
tar -xvzf yasm-1.3.0.tar.gz
cd yasm-1.3.0/
./configure
make
make install

五、编译安装

1
2
3
4
5
6
./configure --enable-shared --prefix=/opt/ffmpeg

#编译过程有点长
make

make install

make install会把ffmpeg相关执行程序、头文件、lib库安装在/opt/ffmpeg/下。

耐心等待完成之后执行
cd /opt/ffmpeg/

进入安装目录,查看一下发现有bin,include,lib,share这4个目录

bin是ffmpeg主程序二进制目录

include是C/C++头文件目录

lib是编译好的库文件目录

share是文档目录

六、执行

进入/opt/ffmpeg/bin目录下执行命令:

1
./ffmpeg -version

执行该命令可能会报错:

1
libavdevice.so.57: cannot open shared object file: No such file or directory

原因是lib目录未加载到链接到系统库中
系统ld目录列表在/etc/ld.so.conf中,打开文件会发现,
里面引用了/etc/ld.so.conf.d/下面所有的.conf文件,比如mariadb-x86_64.conf

七、写入lib路径

执行命令:vim /etc/ld.so.conf.d/ffmpeg.conf

然后添加一行内容:/opt/ffmpeg/lib

之后保存并退出,然后执行 ldconfig使配置生效,

现在再次执行./ffmpeg -version 显示就正常了

八、配置环境变量

1
2
3
vim /etc/profile
PATH=/opt/ffmpeg/bin/:$PATH
source /etc/profile