一、编译环境搭建
1、Msys2 安装
官网下载地址:https://www.msys2.org/
默认安装就可以了
2、Cmake安装
官网下载地址:https://cmake.org/download/
安装方法可参考:https://jingyan.baidu.com/article/da1091fb645ab4027849d6bc.html
Cmake安装64位版本,后续配置msys2中的cmake需要使用
3、修改镜像源
安装好之后,配置镜像源不然下载非常慢还经常失败,把pacman中科大和清华的镜像源放置在前面。打开msys2的安装目录进入/etc/pacman.d/文件夹下配置3个文件(mirrorlist.mingw32、mirrorlist.mingw64、mirrorlist.msys) 结果如下:
mirrorlist.mingw32的配置
##
## 32-bit Mingw-w64 repository mirrorlist
##
## Primary
## msys2.org
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/i686/
Server = http://mirrors.ustc.edu.cn/msys2/mingw/i686/
Server = https://mirror.yandex.ru/mirrors/msys2/mingw/i686/
Server = http://mirror.bit.edu.cn/msys2/mingw/i686/
Server = https://mirror.selfnet.de/msys2/mingw/i686/
Server = https://www2.futureware.at/~nickoe/msys2-mirror/mingw/i686/
Server = https://sourceforge.net/projects/msys2/files/REPOS/MINGW/i686/
Server = http://repo.msys2.org/mingw/i686/
mirrorlist.mingw64的配置
##
## 64-bit Mingw-w64 repository mirrorlist
##
## Primary
## msys2.org
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/x86_64/
Server = http://mirrors.ustc.edu.cn/msys2/mingw/x86_64/
Server = https://mirror.yandex.ru/mirrors/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://www2.futureware.at/~nickoe/msys2-mirror/mingw/x86_64/
Server = https://sourceforge.net/projects/msys2/files/REPOS/MINGW/x86_64/
Server = http://repo.msys2.org/mingw/x86_64/
mirrorlist.msys的配置
##
## MSYS2 repository mirrorlist
##
## Primary
## msys2.org
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/msys/$arch/
Server = http://mirrors.ustc.edu.cn/msys2/msys/$arch/
Server = https://mirror.yandex.ru/mirrors/msys2/msys/$arch/
Server = http://mirror.bit.edu.cn/msys2/msys/$arch/
Server = https://mirror.selfnet.de/msys2/msys/$arch/
Server = https://sourceforge.net/projects/msys2/files/REPOS/MSYS2/$arch/
Server = https://www2.futureware.at/~nickoe/msys2-mirror/msys/$arch/
Server = http://repo.msys2.org/msys/$arch/
4、更新系统各种包
打开msys2的安装目录 双击msys2_shell.cmd
1)、运行命令pacman -Syu,更新系统核心组件和各种包
2)、安装基本工具,命令:pacman -S base-devel(默认全部安装)
3)、安装编译工具64位版本,包括gcc,make等,命令:pacman -S mingw-w64-x86_64-toolchain(默认全部安装)
4)、安装汇编64位版本,cmake,SDL,sdl编译ffplay需要不编译ffplay可以不安装,命令:pacman -S yasm nasm mingw-w64-x86_64-cmake mingw-w64-x86_64-SDL2
5)、替换"msys2安装目录/mingw64/bin/cmake-gui.exe",编译x265的时候会用到,但是这个cmake-gui.exe会依赖qt的动态库,这里我们并没有安装qt,需要换成官方下载的cmake-gui.exe,如果/mingw64/share/不包含cmake-3.18文件夹把cmake安装目录下share文件夹中cmake-3.18文件夹考到/mingw64/share/中。
5、在msys2 目录下面新建一个文件,比如 msys_vs2019.bat,内容如下:
set MSYS2_PATH_TYPE=inherit
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat"
msys2_shell.cmd -mingw64
vcvars32.bat 是 vs2019安装路径下面的一个文件,其他版本的VS请配置相应的 vcvars32.bat路径,/usr/bin/link.exe改一下名,因 为会和vc的link.exe重名
双击msys_vs2019.bat启动mingw64进行编译
二、下载源代码
vs2019 git/github下载
ffmpeg git clone https://github.com/FFmpeg/FFmpeg.git
x264 git clone https://github.com/mirror/x264.git
x265 git clone https://github.com/videolan/x265.git
fdkaac git clone https://github.com/mstorsjo/fdk-aac.git
源码放在msys2的安装目录home中,可以自己调整目录
三、X264编译
1、进入x264源码文件夹 cd /home/X264
2、配置 ./configure --enable-shared --enable-static
3、编译 make -j6 机器有6个核心,所以加了-j6参数加快编译。
4、安装 make install
四、X265编译
X265 需要cmake编译
-
修改x265默认安装位置。修改x265源码目录/build/msys/make-Makefiles.sh文件,将“cmake -G "MSYS Makefiles" ../../source && cmake-gui ../../source”改为“cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=/usr/local ../../source && cmake-gui ../../source”
-
执行脚本‘./make-Makefiles.sh’,过一会弹出cmake配置界面,依次点击“Configure”,"Generate",然后关闭,回到命令行窗口。
-
编译 make -j6
-
安装 make install
五、fdk-aac 编译
1.进入fdk-aac源码文件夹 cd /home/fdk-aac
2.执行文件autogen.sh ./autogen.sh
3.配置 ./configure --enable-shared --enable-static
4.编译 make -j6
5.安装 make install
六、ffmpeg H265支持修改
参考 https://blog.csdn.net/smallhujiu/article/details/81703434
七、ffmpeg编译
-
修改pkgconfig环境变量 执行命令export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig":$PKG_CONFIG_PATH
-
进入x264源码文件夹 cd /home/hevc/ffmpeg
-
配置 ./configure --disable-x86asm --enable-libfdk-aac --enable-gpl --enable-postproc --enable-shared --prefix=./media/FFmpeg --enable-encoder=libx264 --enable-libx264 --enable-encoder=libx265 --enable-libx265 --enable-decoder=h264 --enable-decoder=hevc --enable-demuxer=flv --enable-demuxer=h264 --enable-demuxer=hevc --enable-muxer=h264 --enable-muxer=flv --enable-nonfree
-
编译 make -j6
-
安装 make install
八、参考网址:
http://www.codezd.com/experience/251.html
https://blog.csdn.net/Tui_GuiGe/article/details/90320224
https://blog.csdn.net/u013295518/article/details/90273899
https://blog.csdn.net/zhangxiuyuan/article/details/78414014
https://www.cnblogs.com/gongluck/p/10895947.html
http://www.cuplayer.com/player/PlayerCode/FFmpeg/2014/0706/1404.html