使用MinGW来编译ffmpeg-2.8并支持libfaac
1.1、MinGW在线安装1、Windows上安装编译环境
在http://www.mingw.org/下载安装文件。
下载后获得mingw-get-setup.exe安装文件,推荐使用自动安装的方法来安装MinGW/MSys。
安装过程中会下载必要的基础核心包。默认安装在C:\MinGW,也可以自己选择安装路径。可以直接选择如图1.1所示的工具进行安装。
图1.1
安装完MinGw后需要做的工作:
(1)把C:\MinGW\msys\1.0\bin; C:\MinGW\bin路径添加到系统环境变量中
(2)第一次打开C:\MinGW\msys\1.0\msys.bat后会自动生成 home\电脑名称\(如我的用户目录为:home\ wuyuhua \) 目录。(注:如果打开只是闪了一下就重启电脑)
(3)在home\电脑名称\ 目录下新建三个目录: install\、install\bin、source\
install:所有源码包和一些安装包的安装目录。
bin:放置一些系统命令程序以及后面安装过来的命令可执行程序。
source:专门用来放置FFmpeg以及相关工具的源码。
(4)把新建的homt\ wuyuhua \install\bin文件添加到shell路径中,打开C:\MinGW\msys\1.0\msys.bat,输入如下命令(注意:每次重启都需要如此操作):
export PATH=":/home/awuyu/install/bin:$PATH" echo $PATH #查看文件是否在路径中 |
1.2、安装YASM
YASM不是安装环境所必须的组件,它具有优化编译的功能,因此推荐安装。
在Windows上安装的最简单方法是去http://yasm.tortall.net/Download.html下载提供的二进制文件。
你可以选择下载与32位或64位操作系统对应的YASM,然后安装在 \home\awuyu\install\bin(当然也可以安装在C:\MinGW\msys\1.0\bin目录中)。因为二进制文件的名称通常以程序版本作为后缀(如yasm-1.1.0-win32.exe),因此需要重命名为yasm.exe,然后可以使用yasm进行调用。
1.3、安装nasm
在https://www.nasm.us/pub/nasm/releasebuilds/?C=M;O=D下载nasm-2.13,并把nasm.exe文件复制到\home\awuyu\install\bin文件下。安装nasm是为了编译X264等工具。
1.4、安装pkg-config
(1)为什么安装pkg-config,可以参考
https://blog.****.net/xiabodan/article/details/22916445。简言之就是在不同的设备进行编译时能够快速的找到相应的依赖。
(2)去http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/下载相应的pkg-config和依赖库文件,下载的文件如下所示:
(3)然后把下载的pgk-config文件中bin目录下的内容拷贝home\ awuyu\install\bin目录下。
2、编译X264
x264历史版本地址:http://ftp.videolan.org/pub/pub/videolan/x264/snapshots/下载x264-snapshot-20150731-2245.tar.bz2,解压源码到\home\awuyu\source目录下,然后进行编译:
./configure --prefix=/home/awuyu/install --enable-static --enable-win32thread #配置 make #编译 make install #安装 |
如果configure没有加上--enable-win32thread则在使用FFmpeg时会出现如图2.1所示的错误。
图2.1
3、编译lib_faac
在http://www.audiocoding.com/downloads.html下载faac-1.28.tar.gz,编译命令如下:
./bootstrap ./configure --prefix=/home/awuyu/install --enable-static --disable-shared --without-mp4v2 make make install |
安装结果如图3.1所示:
图3.1
注意:为了确保FFmpeg能够使用,在编译FFmpeg时必须加上--enable-nonfree。
4、编译libmp3lame
下载lame-3.99.5.tar.gz,解压源码到\home\awuyu\source目录下,然后进行编译:
./configure --prefix=/home/awuyu/install --enable-static --disable-shared make make install |
参考http://bbezxcy.iteye.com/blog/2344335直接删除configure文件中11925行的xmmintrin.h。否则会出现如图所4.1示错误:
图4.1
5、编译libtheora
由官网可知libtheora依赖libogg、libvorbis文件,为此编译libtheora之前需要编译libogg、libvorbis文件。
5.1、编译libogg
在https://www.theora.org/downloads/下载libogg-1.3.1,
解压源码到\home\awuyu\source目录下,然后进行编译:
./configure --prefix=/home/awuyu/install #可以参考README make make install |
5.2、编译libvorbis
在https://www.theora.org/downloads/下载libvorbis-1.3.3,
解压源码到\home\awuyu\source目录下,然后进行编译:
#可以参考README ./configure --prefix=/home/awuyu/install --with-ogg=/home/awuyu/install make make install |
5.3、编译libtheora
在https://www.theora.org/downloads/下载libtheora-1.1.1,
解压源码到\home\awuyu\source目录下,然后进行编译:
#可以参考README ./configure --prefix=/home/awuyu/install --with-ogg=/home/awuyu/install --with-vorbis =/home/awuyu/install make make install |
6、编译libxvid
在https://ftp.osuosl.org/pub/blfs/conglomeration/xvidcore/
下载xvidcore-1.3.3.tar.gz,解压源码到\home\awuyu\source目录下,然后进行编译:
cd /home/awuyu/source/xvidcore-1.3.3/xvidcore/build/generic ./configure --prefix=/home/awuyu/install make make install |
7、编译libiconv
根据https://ftp.gnu.org/pub/gnu/libiconv/ 下载libiconv-1.14.tar.gz,解压源码到\home\awuyu\source目录下,然后进行编译:
./configure --prefix=/home/awuyu/install --enable-static --disable-shared make make install |
需要注释掉libiconv-1.14\srclib目录下strerror-override.c文件如图7.1所示的内容。
图7.1
8、编译fdk-aac
在https://sourceforge.net/projects/opencore-amr/files/fdk-aac/
下载fdk-aac-0.1.6.tar.gz,解压源码到\home\awuyu\source目录下,然后进行编译:
./configure --prefix=/home/awuyu/install make make install |
9、编译FFmpeg-2.8
在http://ffmpeg.org/releases/下载FFmpeg-2.8,解压源码到\home\awuyu\source目录下,然后进行编译:
./configure --prefix=/home/awuyu/install \ --extra-cflags=-I/home/awuyu/install/include \ --extra-ldflags=-L/home/awuyu/install/lib \ --enable-gpl \ --enable-version3 \ --enable-nonfree \ --enable-libx264 \ --enable-libfaac \ --enable-libmp3lame \ --enable-libtheora \ --enable-libvorbis \ --enable-libxvid \ --enable-iconv \ --enable-libfdk-aac make make install |
make后出现如图9.1所示错误。
图9.1
进入libavformat\os_support.c注释错误部分如图9.2所示。
图9.2
出现如图9.3的错误是因为刚开始用的x264(是2018年4月15日这个版本)和FFmpeg-2.8不匹配。
图9.3