CentOS7中安装ffmpeg
CentOS7安装 ffmpeg4.2
准备好C编译器等依赖
yum install -y gcc g++ cmake gcc-c++
下载和编译x264
[root@localhost download]# wget https://code.videolan.org/videolan/x264/-/archive/master/x264-master.tar.bz2
[root@localhost download]# tar -jxvf x264-master.tar.bz2
[root@localhost download]# cd ./x264-master
[root@localhost x264-master]# make clean && make uninstall
[root@localhost x264-master]# PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/ ./configure --enable-shared
[root@localhost x264-master]# make -j4 && make install
下载和编译x265
下载地址: https://www.linuxfromscratch.org/blfs/view/svn/multimedia/x265.html
[root@localhost download]# wget https://anduin.linuxfromscratch.org/BLFS/x265/x265_3.4.tar.gz
[root@localhost download]# tar -zxvf x265_3.4.tar.gz
[root@localhost download]# cd x265_3.4/source
[root@localhost source]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/x265
[root@localhost source]# make install
安装完成后显示:
下载源码和ffmpeg安装:
[root@localhost darwin]# wget https://ffmpeg.org/releases/ffmpeg-4.2.3.tar.bz2
[root@localhost darwin]# tar -jxvf ffmpeg-4.2.3.tar.bz2
[root@localhost darwin]# cd ffmpeg-4.2.3
[root@localhost ffmpeg-4.2.3]# ./configure --prefix=--prefix=/usr/local/ffmpeg \
> --enable-shared --disable-w32threads \
> --enable-pthreads --enable-gpl \
> --enable-libx264 --enable-libx265 \
> --enable-nonfree
ERROR: x265 not found using pkg-config
查看安装日志:配置x265
[root@localhost ffmpeg-4.2.3]# vi ffbuild/config.log
[root@localhost ffmpeg-4.2.3]# ll /usr/local/x265/lib/pkgconfig
total 4
-rw-r--r-- 1 root root 249 May 9 21:24 x265.pc
[root@localhost ffmpeg-4.2.3]# export PKG_CONFIG_PATH=/usr/local/x265/lib/pkgconfig
或者在 /etc/profile 中添加
export PKG_CONFIG_PATH=/usr/local/x264/lib/pkgconfig/
export PKG_CONFIG_PATH=/usr/local/x265/lib/pkgconfig:$PKG_CONFIG_PATH
查看ffmpeg信息出现错误:
错误1:将ffmpeg的安装目录添加到 /etc/ld.so.conf
[root@localhost ffmpeg]# bin/ffmpeg -v
bin/ffmpeg: error while loading shared libraries: libavdevice.so.58: cannot open shared object file: No such file or directory
错误2:将x265的安装目录添加到 /etc/ld.so.conf 目录中
[root@localhost ffmpeg]# bin/ffmpeg --version
bin/ffmpeg: error while loading shared libraries: libx265.so.192: cannot open shared object file: No such file or directory
需要编辑 /etc/ld.so.config
include ld.so.conf.d/*.conf
#增加一下内容
/usr/local/ffmpeg/lib/ #ffmpeg安装路径
/usr/local/lib #其他安装路径,比如安装x264时没有选择目录,默认则安装在当前目录下
/usr/local/x265/lib/ #x265的安装目录
执行刷新命令
ldconfig
查看ffmpeg版本:
[root@localhost ffmpeg]# bin/ffmpeg -version
ffmpeg version 4.2.3 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-44)
configuration: --prefix=/usr/local/ffmpeg --enable-libx264 --disable-w32threads --disable-debug --enable-pthreads --enable-gpl --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
libpostproc 55. 5.100 / 55. 5.100
pkg-config功能
一般来说,如果库的头文件不在/usr/include目录中,那么在编译的时候需要用-I参数指定其路径。
由于同一个库在不同系统上可能位于不同的目录下,用户安装库的时候也可以将库安装在不同的目录下,所以即使使用同一个库,由于库的路径的不同,造成了用-I参数指定的头文件的路径和在连接时使用-L参数指定lib库的路径都可能不同,其结果就是造成了编译命令界面的不统一。
可能由于编译,连接的不一致,造成同一份程序从一台机器copy到另一台机器时就可能会出现问题。
pkg-config 就是用来解决编译连接界面不统一问题的一个工具。
它的基本思想:pkg-config是通过库提供的一个.pc文件获得库的各种必要信息的,包括版本信息、编译和连接需要的参数等。需要的时候可以通过pkg-config提供的参数(–cflags, –libs),将所需信息提取出来供编译和连接使用。这样,不管库文件安装在哪,通过库对应的.pc文件就可以准确定位,可以使用相同的编译和连接命令,使得编译和连接界面统一。
它提供的主要功能有:
<1> 检查库的版本号。如果所需库的版本不满足要求,打印出错误信息,避免连接错误版本的库文件。
<2> 获得编译预处理参数,如宏定义,头文件的路径。
<3> 获得编译参数,如库及其依赖的其他库的位置,文件名及其他一些连接参数
参考文档:
https://www.cnblogs.com/shunzi115/p/14869437.html
https://www.cnblogs.com/Rui6/p/14738072.html

浙公网安备 33010602011771号