参考:Linux下FFmpeg之ffplay编译 - 灰信网(软件开发博客聚合)
Linux 编译ffmpeg 生成ffplay - 王纲 - 博客园
Linux下编译安装SDL2_DS小龙哥的专栏-CSDN博客_linux sdl2
1、安装SDL
若编译ffmpeg想要生成ffplay,则需要先安装SDL
安装SDL有两种方式,一种是下载源码编译,参考Linux下编译安装SDL2_DS小龙哥的专栏-CSDN博客_linux sdl2
另一种方式是使用 sudo apt-get install libsdl2-dev 命令直接安装,这里采用apt-get的方式
2、下载ffmpeg
下载网址:Download FFmpeg
3、解压缩
tar -vxf ffmpeg-4.2.2.tar.bz2
4、配置,生成Makefile
./configure --enable-shared --disable-yasm --prefix=/usr/local/ffmpeg
如果执行结果不对,可以根据提示信息,并查看帮助,解决问题
./configure --help
执行完./configure之后会有如下信息,可以看到最终会生成ffmpeg、ffplay、ffprobe三个程序
runoob@ubuntu:~/work/my_project/ffmpeg/ffmpeg-4.2.2$ ./configure --enable-shared --disable-yasm --prefix=/usr/local/ffmpeg
install prefix /usr/local/ffmpeg
source path .
C compiler gcc
C library glibc
ARCH x86 (generic)
big-endian no
runtime cpu detection yes
standalone assembly no
x86 assembler nasm
MMX enabled yes
MMXEXT enabled yes
3DNow! enabled yes
3DNow! extended enabled yes
SSE enabled yes
SSSE3 enabled yes
AESNI enabled yes
AVX enabled yes
AVX2 enabled yes
AVX-512 enabled yes
XOP enabled yes
FMA3 enabled yes
FMA4 enabled yes
i686 features enabled yes
CMOV is fast yes
EBX available yes
EBP available yes
debug symbols yes
strip symbols yes
optimize for size no
optimizations yes
static yes
shared yes
postprocessing support no
network support yes
threading support pthreads
safe bitstream reader yes
texi2html enabled no
perl enabled yes
pod2man enabled yes
makeinfo enabled no
makeinfo supports HTML no
External libraries:
alsa libxcb libxcb_xfixes xlib
iconv libxcb_shape sdl2 zlib
External libraries providing hardware acceleration:
Libraries:
avcodec avdevice avfilter avformat avutil swresample swscale
Programs:
ffmpeg ffplay ffprobe
5、编译安装
make
make install
6、安装之后在/usr/local/ffmpeg会看到有三个目录
bin 执行文件目录
lib 静态,动态链接库目录
include 编程用到的头文件
runoob@ubuntu:/usr/local/ffmpeg$ ls ./bin
ffmpeg ffplay ffprobe
runoob@ubuntu:/usr/local/ffmpeg$ ls ./lib
libavcodec.a libavdevice.a libavfilter.a libavformat.a libavutil.a libswresample.a libswscale.a pkgconfig
libavcodec.so libavdevice.so libavfilter.so libavformat.so libavutil.so libswresample.so libswscale.so
libavcodec.so.58 libavdevice.so.58 libavfilter.so.7 libavformat.so.58 libavutil.so.56 libswresample.so.3 libswscale.so.5
libavcodec.so.58.54.100 libavdevice.so.58.8.100 libavfilter.so.7.57.100 libavformat.so.58.29.100 libavutil.so.56.31.100 libswresample.so.3.5.100 libswscale.so.5.5.100
runoob@ubuntu:/usr/local/ffmpeg$ ls ./include/
libavcodec libavdevice libavfilter libavformat libavutil libswresample libswscale
为了防止执行程序找不到库文件,
可以将/usr/local/ffmpeg/lib目录设置到LD_LIBRARY_PATH环境变量,
或者查看/usr/local/ffmpeg/lib下所有的链接,并在/usr/lib下建立同样的链接。如下。
ln -s /usr/local/ffmpeg/lib/libavcodec.so /usr/lib/libavcodec.so
ln -s /usr/local/ffmpeg/lib/libavdevice.so /usr/lib/libavdevice.so
ln -s /usr/local/ffmpeg/lib/libavfilter.so /usr/lib/libavfilter.so
ln -s /usr/local/ffmpeg/lib/libavformat.so /usr/lib/libavformat.so
ln -s /usr/local/ffmpeg/lib/libavutil.so /usr/lib/libavutil.so
ln -s /usr/local/ffmpeg/lib/libswresample.so /usr/lib/libswresample.so
ln -s /usr/local/ffmpeg/lib/libswscale.so /usr/lib/libswscale.so
ln -s /usr/local/ffmpeg/lib/libavcodec.so /usr/lib/libavcodec.so.55
ln -s /usr/local/ffmpeg/lib/libavdevice.so /usr/lib/libavdevice.so.55
ln -s /usr/local/ffmpeg/lib/libavfilter.so /usr/lib/libavfilter.so.3
ln -s /usr/local/ffmpeg/lib/libavformat.so /usr/lib/libavformat.so.55
ln -s /usr/local/ffmpeg/lib/libavutil.so /usr/lib/libavutil.so.52
ln -s /usr/local/ffmpeg/lib/libswresample.so /usr/lib/libswresample.so.0
ln -s /usr/local/ffmpeg/lib/libswscale.so /usr/lib/libswscale.so.2
7、编译测试程序
gcc -o ffmpegtest ffmpegtest.c -I/usr/local/ffmpeg/include -L/usr/local/ffmpeg/lib -lavformat -lavcodec -lavtuil
8、执行程序
./ffmpegtest
或直接执行/usr/local/ffmpeg/lib目录下的./ffmpeg进行测试。
9、ffmpeg正常安装后执行ffmpeg时出现如下错误:
ffmpeg: error while loading shared libraries: libavdevice.so.53: cannot open shared object file: No such file or directory
解决办法:
vi /etc/ld.so.conf
加入:/usr/local/lib
执行ldconfig