FFMPEG源码编译(Windows篇)

环境:win10 64位,VS2019,MSYS(是一个小型的GNU环境,包括基本的bash,make等等。与MinGW,Cygwin等工具类似,主要是能够在windows下使用Linux的命令和库)

环境配置

1.进入vs2019的命令行编译工具

FFMPEG源码编译(Windows篇)_第1张图片

此处选择x64的工具来进行。

2.在命令行编译工具中打开MSYS

进入到msys的安装目录中修改 msys2_shell.cmd 文件,将其中的外部环境继承项 MSYS2_PATH_TYPE=inherit 的注释打开

FFMPEG源码编译(Windows篇)_第2张图片

然后打开64位编译工具,然后进入到MSYS的安装目录,并拉起msys的环境

FFMPEG源码编译(Windows篇)_第3张图片

进入到msys窗口检查是否能使用vs2019的编译命令,并将窗口的编码方式更改位GBK来消除乱码

FFMPEG源码编译(Windows篇)_第4张图片

3.在msys中安装需要的依赖库

pacman -S nasm #汇编工具
pacman -S yasm #汇编工具
pacman -S make cmake #常规编译工具
pacman -S diffutils  # 比较工具,ffmpeg configure 生成makefile时用到
pacman -S pkg-config # 库配置工具,编译支持x264和x265会用到
pacman -S git  # 从版本库下载源码

若出现无法获取安装包的情况,则需要换源,进入到msys64\etc\pacman.d 目录下有三个文件。

mirrorlist.msys:

##
## MSYS2 repository mirrorlist
##

## Primary
Server = https://repo.msys2.org/msys/$arch/
## Mirrors
Server = https://downloads.sourceforge.net/project/msys2/REPOS/MSYS2/$arch/
Server = https://www2.futureware.at/~nickoe/msys2-mirror/msys/$arch/
Server = https://mirror.yandex.ru/mirrors/msys2/msys/$arch/
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/msys/$arch/
Server = http://mirrors.ustc.edu.cn/msys2/msys/$arch/
Server = http://mirror.bit.edu.cn/msys2/msys/$arch/
Server = https://mirror.selfnet.de/msys2/msys/$arch/
Server = https://mirrors.sjtug.sjtu.edu.cn/msys2/msys/$arch/
Server = https://mirror.jmu.edu/pub/msys2/msys/$arch/
Server = https://ftp.cc.uoc.gr/mirrors/msys2/msys/$arch/
Server = https://ftp.acc.umu.se/mirror/msys2.org/msys/$arch/
Server = https://mirrors.piconets.webwerks.in/msys2-mirror/msys/$arch/
Server = https://quantum-mirror.hu/mirrors/pub/msys2/msys/$arch/
Server = https://mirrors.dotsrc.org/msys2/msys/$arch/ 
Server = https://mirror.ufro.cl/msys2/msys/$arch/
Server = https://mirror.clarkson.edu/msys2/msys/$arch/
Server = https://ftp.nluug.nl/pub/os/windows/msys2/builds/msys/$arch/
Server = https://download.nus.edu.sg/mirror/msys2/msys/$arch/
Server = https://ftp.osuosl.org/pub/msys2/msys/$arch/
Server = https://fastmirror.pp.ua/msys2/msys/$arch/


mirrorlist.mingw64:

##
## 64-bit Mingw-w64 repository mirrorlist
##

## Primary
Server = https://repo.msys2.org/mingw/x86_64/
## Mirrors
Server = https://downloads.sourceforge.net/project/msys2/REPOS/MINGW/x86_64/
Server = https://www2.futureware.at/~nickoe/msys2-mirror/mingw/x86_64/
Server = https://mirror.yandex.ru/mirrors/msys2/mingw/x86_64/
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/x86_64/
Server = http://mirrors.ustc.edu.cn/msys2/mingw/x86_64/
Server = http://mirror.bit.edu.cn/msys2/mingw/x86_64/
Server = https://mirror.selfnet.de/msys2/mingw/x86_64/
Server = https://mirrors.sjtug.sjtu.edu.cn/msys2/mingw/x86_64/
Server = https://mirror.jmu.edu/pub/msys2/mingw/x86_64/
Server = https://ftp.cc.uoc.gr/mirrors/msys2/mingw/x86_64/
Server = https://ftp.acc.umu.se/mirror/msys2.org/mingw/x86_64/
Server = https://mirrors.piconets.webwerks.in/msys2-mirror/mingw/x86_64/
Server = https://quantum-mirror.hu/mirrors/pub/msys2/mingw/x86_64/
Server = https://mirrors.dotsrc.org/msys2/mingw/x86_64/ 
Server = https://mirror.ufro.cl/msys2/mingw/x86_64/
Server = https://mirror.clarkson.edu/msys2/mingw/x86_64/
Server = https://ftp.nluug.nl/pub/os/windows/msys2/builds/mingw/x86_64/
Server = https://download.nus.edu.sg/mirror/msys2/mingw/x86_64/
Server = https://ftp.osuosl.org/pub/msys2/mingw/x86_64/
Server = https://fastmirror.pp.ua/msys2/mingw/x86_64/


mirrorlist.mingw32:

##
## 32-bit Mingw-w64 repository mirrorlist
##

## Primary
Server = https://repo.msys2.org/mingw/i686/
## Mirrors
Server = https://downloads.sourceforge.net/project/msys2/REPOS/MINGW/i686/
Server = https://www2.futureware.at/~nickoe/msys2-mirror/mingw/i686/
Server = https://mirror.yandex.ru/mirrors/msys2/mingw/i686/
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/i686/
Server = http://mirrors.ustc.edu.cn/msys2/mingw/i686/
Server = http://mirror.bit.edu.cn/msys2/mingw/i686/
Server = https://mirror.selfnet.de/msys2/mingw/i686/
Server = https://mirrors.sjtug.sjtu.edu.cn/msys2/mingw/i686/
Server = https://mirror.jmu.edu/pub/msys2/mingw/i686/
Server = https://ftp.cc.uoc.gr/mirrors/msys2/mingw/i686/
Server = https://ftp.acc.umu.se/mirror/msys2.org/mingw/i686/
Server = https://mirrors.piconets.webwerks.in/msys2-mirror/mingw/i686/
Server = https://quantum-mirror.hu/mirrors/pub/msys2/mingw/i686/
Server = https://mirrors.dotsrc.org/msys2/mingw/i686/ 
Server = https://mirror.ufro.cl/msys2/mingw/i686/
Server = https://mirror.clarkson.edu/msys2/mingw/i686/
Server = https://ftp.nluug.nl/pub/os/windows/msys2/builds/mingw/i686/
Server = https://download.nus.edu.sg/mirror/msys2/mingw/i686/
Server = https://ftp.osuosl.org/pub/msys2/mingw/i686/
Server = https://fastmirror.pp.ua/msys2/mingw/i686/


重新运行 msys64\msys2.exe。测试一下软件源是否可用:

pacman -Sy

下载x264、x265和aac源码并进行编译

X264:https://www.videolan.org/developers/x264.html

X265: https://www.x265.org/

fdk-aac: https://github.com/mstorsjo/fdk-aac

1.编译x264(在MSYS下编译)

cd x264-master
CC=cl ./congfigure --enable-shared
make -j16
make install 

2.编译x265(在MSYS下调用外部环境的cmake编译)

可以先将MSYS环境中的cmake换一个名字,然后再进行以下操作,保证调用的是外部环境的cmake

cd x265_3.3/build/msys-cl
./make-Makefiles.sh
nmake install #需要在root权限下进行,在开启vs编译工具时使用管理员权限打开

FFMPEG源码编译(Windows篇)_第5张图片

安装完成后,进入到编译安装目录下,将lib库拷贝到MSYS2中的 /usr/local 目录下

同时修改 .pc文件,将其中的路径更换为 /usr/local

3.编译fdk-aac(在外部环境编译,不使用MSYS)

打开vs2019编译环境即可进行一下操作

nmake -f Makefile.vc
nmake -f Makefile.vc -prefix=.\install install

安装时,在vs2019编译工具中安装不成功,报错如下:

FFMPEG源码编译(Windows篇)_第6张图片

因此切换到MSYS2环境下进行安装

FFMPEG源码编译(Windows篇)_第7张图片

由于没有生成 .pc文件,因此需要将fdk-aac.pc.in 文件更名为fdk-acc.pc,并进行修改后,放入到/usr/local/lib/pkgconfig

prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: Fraunhofer FDK AAC Codec Library
Description: AAC codec library
Version: 
Libs: -L${libdir} -lfdk-aac
Libs.private: 
Cflags: -I${includedir}

编译ffmpeg

源码:https://ffmpeg.org/download.html

CC=cl.exe ./configure --prefix=./install --toolchain=msvc --enable-shared --disable-programs --disable-ffplay --disable-ffmpeg --disable-ffprobe --enable-libx264 --enable-gpl --enable-libfdk-aac --enable-nonfree --enable-libx265


#--prefix=./install --toolchain=msvc 指定安装路径和工具链vs
#--enable-shared 编译为动态链接库
#--disable-xxx  暂时不编译工具 
#--enable-gpl --enable-libx264 --enable-libx265 支持x264 x265
#--enable-libfdk-aac --enable-nonfree aac音频编码 aac必须包含-enable-nonfree

报错1:找不到头文件

解决:将/usr/local/lib/pkgconfig 剪切粘贴到/mingw64/lib

报错2:找不到.lib

FFMPEG源码编译(Windows篇)_第8张图片

解决:将/usr/local/lib/libx264.dll.lib 更名为 libx264.lib

报错3:找不到x265的库

FFMPEG源码编译(Windows篇)_第9张图片

解决:将/usr/local/lib/libx265.lib 重命名为x265.lib

不报错后,成功生成Makefile文件,然后执行

make -j8
make install

完成整个FFMPEG在Windos下的编译!

你可能感兴趣的:(FFMPEG,ffmpeg)