在CentOS 7.4下构建 ffmpeg 开发环境

			              	┌────────────────────────────────────┐
			              	│RELEASE NOTES for FFmpeg 4.4 "Rao"  │
			             	└────────────────────────────────────┘
			
			                        基于 FFMPEG 4.4 编译

直接安装

centos7

sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm

centos6

sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el6/x86_64/nux-dextop-release-0-2.el6.nux.noarch.rpm
sudo yum install ffmpeg ffmpeg-devel -y

ffmpeg -h
ffmpeg -i input.mp4 output.avi

编译安装

1.下载源码

wget http://www.ffmpeg.org/download.html#releases

2.依赖安装 并卸载冗余

yum install autoconf automake bzip2 cmake freetype-devel gcc gcc-c++ git libtool make mercurial pkgconfig zlib-devel cmake hg numactl numactl-devel freetype freetype-devel freetype-demos
yum remove ffmpeg ffmpeg-devel nasm -y

2.安装文件夹

mkdir ffmpeg
mkdir needed

3.前置安装,否则编译报错

ERROE libfdk_aac not found问题↓
libfdk_aac安装:

cd needed
wget  https://udomain.dl.sourceforge.net/project/opencore-amr/fdk-aac/fdk-aac-2.0.2.tar.gz
cd fdk-aac-2.0.2/
./configure
make && make install

3.编译ffmpeg(安装目录prefix自定义,不需要则会到默认目录):

wget http://www.ffmpeg.org/download.html#releases
tar -xvf ffmpeg-4.4.tar.gz
cd ffmpeg-4.4
./configure --prefix="/usr/local/dujnLib/ffmpeg"
make && make install

4.结果:

[root@localhost ffmpeg]# pwd
/usr/local/dujnLib/ffmpeg
[root@localhost ffmpeg]# ls
bin  include  lib  share
[root@localhost ffmpeg]#

5.调试程序编译
编译调试(以源码中doc/examples/metadata.c为例):
==>【 pkg-config 是linux下的一个命令,能够方便编译,例如如下编译命令 】

export PKG_CONFIG_PATH=/usr/local/dujnLib/ffmpeg/lib/pkgconfig:$PKG_CONFIG_PATH
gcc metadata.c -o getMetadata `pkg-config  --libs --cflags libavformat`

6.结果:
说明–>PKG_CONFIG_PATH指定pkg-config将要读取的配置文件,这里在
/usr/local/dujnLib/ffmpeg/lib/pkgconfig目录,即目标编译lib目录下的pkgconfig中,自行配置即可。

[root@localhost ffmpeg]# ls
bin  compile.sh  doc  include  lib  metadata.c  README.txt  share  tree.mp4
[root@localhost ffmpeg]# cat compile.sh
#!/bin/sh
export PKG_CONFIG_PATH=/usr/local/dujnLib/ffmpeg/lib/pkgconfig:$PKG_CONFIG_PATH
gcc metadata.c -o getMetadata `pkg-config  --libs --cflags libavformat`
[root@localhost ffmpeg]# ./compile.sh
[root@localhost ffmpeg]# ./getMetadata tree.mp4
major_brand=isom
minor_version=512
compatible_brands=isomiso2avc1mp41
encoder=Lavf55.33.100
[root@localhost ffmpeg]#

::>【 pkg-config 工作本质是对编译项的封装 】

[root@localhost ffmpeg]# pkg-config  --libs --cflags libavformat
-I/usr/local/dujnLib/ffmpeg/include  -pthread -L/usr/local/dujnLib/ffmpeg/lib -lavformat -lavcodec -lz -lswresample -lavutil -lm
[root@localhost ffmpeg]#

==> 【 根据官网有如下库可供选择 】
( libavutil、libavcodec、libavformat、libavdevice、libavfilter、libswscale、libswresample )

libavutil is a library containing functions for simplifying programming, including random number generators, data structures, mathematics routines, core multimedia utilities, and much more.

libavcodec is a library containing decoders and encoders for audio/video codecs.

libavformat is a library containing demuxers and muxers for multimedia container formats.

libavdevice is a library containing input and output devices for grabbing from and rendering to many common multimedia input/output software frameworks, including Video4Linux, Video4Linux2, VfW, and ALSA.

libavfilter is a library containing media filters.

libswscale is a library performing highly optimized image scaling and color space/pixel format conversion operations.

libswresample is a library performing highly optimized audio resampling, rematrixing and sample format conversion operations.

学习文档:https://zhuanlan.zhihu.com/p/41070610

猜你喜欢

转载自blog.csdn.net/weixin_44328568/article/details/120362381