0X00、下载ffmpeg源码
我们可以在ffmpeg官网下载源码,下载地址http://ffmpeg.org/download.html,目前最新版本是4.2.2。
0X01、生成makefile
把下载的源码放到linux系统中 ,我这里是放在/opt/目录下。
[root@localhost opt]# ls -l
drwxr-xr-x. 18 root root 4096 5月 8 21:07 ffmpeg-4.2.2
进入到ffmpeg-4.2.2目录,内容如下:
[root@localhost ffmpeg-4.2.2]# ls -l
总用量 648
-rw-r--r--. 1 root root 78834 1月 1 05:35 Changelog
drwxr-xr-x. 12 root root 264 5月 18 22:09 compat
-rw-r--r--. 1 root root 251982 1月 1 05:35 configure
-rw-r--r--. 1 root root 418 11月 2 2018 CONTRIBUTING.md
-rw-r--r--. 1 root root 18092 3月 29 2016 COPYING.GPLv2
-rw-r--r--. 1 root root 35147 3月 29 2016 COPYING.GPLv3
-rw-r--r--. 1 root root 26526 3月 29 2016 COPYING.LGPLv2.1
-rw-r--r--. 1 root root 7651 3月 29 2016 COPYING.LGPLv3
-rw-r--r--. 1 root root 274 3月 29 2016 CREDITS
drwxr-xr-x. 4 root root 4096 5月 18 22:09 doc
drwxr-xr-x. 2 root root 127 5月 18 22:09 ffbuild
drwxr-xr-x. 2 root root 256 5月 18 22:09 fftools
-rw-r--r--. 1 root root 596 1月 1 05:35 INSTALL.md
drwxr-xr-x. 14 root root 40960 5月 18 22:10 libavcodec
drwxr-xr-x. 3 root root 4096 5月 18 22:10 libavdevice
drwxr-xr-x. 6 root root 16384 5月 18 22:10 libavfilter
drwxr-xr-x. 3 root root 16384 5月 18 22:10 libavformat
drwxr-xr-x. 6 root root 4096 5月 18 22:10 libavresample
drwxr-xr-x. 12 root root 8192 5月 18 22:10 libavutil
drwxr-xr-x. 2 root root 222 5月 18 22:10 libpostproc
drwxr-xr-x. 6 root root 4096 5月 18 22:10 libswresample
drwxr-xr-x. 7 root root 4096 5月 18 22:10 libswscale
-rw-r--r--. 1 root root 3825 1月 1 05:35 LICENSE.md
-rw-r--r--. 1 root root 29540 1月 1 05:35 MAINTAINERS
-rw-r--r--. 1 root root 5633 1月 1 05:35 Makefile
drwxr-xr-x. 2 root root 158 5月 18 22:10 presets
-rw-r--r--. 1 root root 1790 1月 1 05:35 README.md
-rw-r--r--. 1 root root 6 1月 1 05:35 RELEASE
-rw-r--r--. 1 root root 830 1月 1 05:35 RELEASE_NOTES
drwxr-xr-x. 7 root root 4096 5月 18 22:10 tests
drwxr-xr-x. 3 root root 4096 5月 18 22:10 tools
-rw-r--r--. 1 root root 6 1月 1 05:35 VERSION
执行configure生成makefile,上边看到configure文件是没有执行权限的,我们通过chmod命令加上执行权限。
[root@localhost ffmpeg-4.2.2]# chmod a+x configure
然后执行以下命令:
[root@localhost ffmpeg-4.2.2]# ./configure --prefix=/opt/ffmpeg --enable-debug=3 --disable-static --enable-shared
nasm/yasm not found or too old. Use --disable-x86asm for a crippled build.
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.
–prefix指定安装路径,–enable-debug用于gcc产生调试信息,–disable-static不生成静态库,否则默认生成的是静态库,–enable-shared生成共享库。
注意到上边执行出错了,nasm/yasm not found or too old,这是因为ffmpeg用到了汇编编译器,我们系统中没有安装导致。可以在http://yasm.tortall.net/Download.html下载源码。
安装如下,我这里按照默认安装,源码还是解压在/opt目录下:
[root@localhost opt]# cd yasm-1.3.0/
[root@localhost yasm-1.3.0]# chmod a+x configure
[root@localhost yasm-1.3.0]# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
......省略其余部分
[root@localhost yasm-1.3.0]# make -j 4
gcc -I. \
-c -o genperf.o `test -f tools/genperf/genperf.c || echo './'`tools/genperf/genperf.c
......省略其余部分
[root@localhost yasm-1.3.0]# make install
make install-recursive
......省略其余部分
[root@localhost yasm-1.3.0]# ls -l /usr/local/lib
总用量 5384
-rw-r--r--. 1 root root 5511524 5月 8 20:56 libyasm.a
安装完成后再次执行./configure:
[root@localhost ffmpeg-4.2.2]# ./configure --prefix=/opt/ffmpeg --enable-debug=3 --disable-static --enable-shared
install prefix /opt/ffmpeg
......省略其余部分
License: LGPL version 2.1 or later
[root@localhost yasm-1.3.0]#
0X02、make编译
执行make编译。
[root@localhost ffmpeg-4.2.2]# make -j 4
make: execvp: ./ffbuild/version.sh: 权限不够
GEN libavutil/libavutil.version
/bin/sh: ./ffbuild/libversion.sh: 权限不够
......省略其余部分
对没有权限的使用chmod增加权限后再次make。
[root@localhost ffmpeg-4.2.2]# make -j 4
CC libavdevice/avdevice.o
CC libavdevice/fbdev_enc.o
CC libavdevice/lavfi.o
......省略其余部分
LD libswresample/libswresample.so.
LD libswscale/libswscale.so.
LD libavcodec/libavcodec.so.
LD libavformat/libavformat.so.
LD libavfilter/libavfilter.so.
LD libavdevice/libavdevice.so.
LD ffmpeg_g
LD ffprobe_g
STRIP ffprobe
STRIP ffmpeg
[root@localhost yasm-1.3.0]#
0X03、安装
执行make install安装。
[root@localhost ffmpeg-4.2.2]# make install
INSTALL libavdevice/libavdevice.so
STRIP install-libavdevice-shared
......省略其余部分
[root@localhost yasm-1.3.0]#
安装完成后,可以在/opt/ffmpeg目录下看到相关文件。
[root@localhost ffmpeg]# ls -l
总用量 4
drwxr-xr-x. 2 root root 35 5月 8 21:08 bin
drwxr-xr-x. 9 root root 137 5月 8 21:08 include
drwxr-xr-x. 3 root root 4096 5月 8 21:08 lib
drwxr-xr-x. 4 root root 31 5月 8 21:08 share
[root@localhost ffmpeg]# cd bin/
[root@localhost bin]# ls -l
总用量 376
-rwxr-xr-x. 1 root root 239520 5月 8 21:08 ffmpeg
-rwxr-xr-x. 1 root root 140280 5月 8 21:08 ffprobe
[root@localhost bin]# cd ../lib/
[root@localhost lib]# ls -l
总用量 19176
lrwxrwxrwx. 1 root root 14 5月 8 21:08 libavcodec.so -> libavcodec.so.
-rwxr-xr-x. 1 root root 13171784 5月 8 21:08 libavcodec.so.
lrwxrwxrwx. 1 root root 15 5月 8 21:08 libavdevice.so -> libavdevice.so.
-rwxr-xr-x. 1 root root 57816 5月 8 21:08 libavdevice.so.
lrwxrwxrwx. 1 root root 15 5月 8 21:08 libavfilter.so -> libavfilter.so.
-rwxr-xr-x. 1 root root 2903376 5月 8 21:08 libavfilter.so.
lrwxrwxrwx. 1 root root 15 5月 8 21:08 libavformat.so -> libavformat.so.
-rwxr-xr-x. 1 root root 2365176 5月 8 21:08 libavformat.so.
lrwxrwxrwx. 1 root root 13 5月 8 21:08 libavutil.so -> libavutil.so.
-rwxr-xr-x. 1 root root 478352 5月 8 21:08 libavutil.so.
lrwxrwxrwx. 1 root root 17 5月 8 21:08 libswresample.so -> libswresample.so.
-rwxr-xr-x. 1 root root 117144 5月 8 21:08 libswresample.so.
lrwxrwxrwx. 1 root root 14 5月 8 21:08 libswscale.so -> libswscale.so.
-rwxr-xr-x. 1 root root 530832 5月 8 21:08 libswscale.so.
drwxr-xr-x. 2 root root 158 5月 8 21:08 pkgconfig
[root@localhost lib]#
测试如下,说明安装完成。
[root@localhost bin]# export LD_LIBRARY_PATH=/opt/ffmpeg/lib/:$LD_LIBRARY_PATH
[root@localhost bin]# echo $LD_LIBRARY_PATH
/opt/ffmpeg/lib/:
[root@localhost bin]# ./ffmpeg
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8 (GCC)
configuration: --prefix=/opt/ffmpeg --enable-debug=3 --disable-static --enable-shared
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
Use -h to get full help or, even better, run 'man ffmpeg'