编译环境Win 64位+MSYS2
一.安装MSYS2
1.下载msys.exe,https://www.msys2.org/
2.安装msys
3.运行msys并执行命令pacman -Syu,一律输入Y同意,执行结束后会自动关闭,再次打开msys后执行pacman -Syu
4.执行下列命令安装依赖包
pacman -S make
pacman -S diffutils
pacman -S yasm
pacman -S nasm
pacman -S mingw-w64-x86_64-gcc
pacman -S mingw-w64-i686-gcc
pacman -S mingw-w64-x86_64-gtk3
pacman -S mingw-w64-i686-gtk3
pacman -S git
5.下载pkg-config,https://download.gnome.org/binaries/,把win64的exe复制到mingw64\bin下,把win32的exe复制到mingw32\bin下
6.执行下列命令修改相关后缀
cd /mingw32/bin/
cp libintl-8.dll intl.dll
cd /mingw32/i686-w64-mingw32/lib/
mv libpthread.dll.a libpthread.dll.a-org && mv libwinpthread.dll.a libwinpthread.dll.a-org
cd /mingw32/lib
mv libbz2.dll.a libbz2.dll.a-org && mv libz.dll.a libz.dll.a-org
mv libiconv.dll.a libiconv.dll.a-org && mv liblzma.dll.a liblzma.dll.a-org
cd /mingw64/bin/
cp libintl-8.dll intl.dll
cd /mingw64/x86_64-w64-mingw32/lib/
mv libpthread.dll.a libpthread.dll.a-org && mv libwinpthread.dll.a libwinpthread.dll.a-org
cd /mingw64/lib
mv libbz2.dll.a libbz2.dll.a-org && mv libz.dll.a libz.dll.a-org
mv libiconv.dll.a libiconv.dll.a-org && mv liblzma.dll.a liblzma.dll.a-org
二.准备源码
1.FFmpeg
官网下载即可
2.x264
wget https://code.videolan.org/videolan/x264/-/archive/master/x264-master.tar.bz2
tar -jxvf /home/x264-master.tar.bz2 -C /home/x264
可能tar解压失败,直接去文件路径下rar解压也行。
3.amf
wget https://github.com/GPUOpen-LibrariesAndSDKs/AMF/archive/1.4.16.1.tar.gz
tar -zxvf /home/AMF-1.4.16.1.tar.gz -C /home
cp -r /home/AMF-1.4.16.1/amf/public/include/* /usr/local/include/AMF
如果/usr/local/include/AMF不存在,手动mkdir一个。
4.ffnvcodec
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
cd nv-codec-headers
make & make install
三.编译
1.编译32位DLL
打开MSYS2 MinGW 32
编译x264
cd /home/x264-master/
./configure \
--prefix=/mingw32 \
--enable-static \
--host=msys \
--disable-cli
make clean
make -j6 #改成你的CPU核心数,6表示编译时占用6核
make install
编译成功后将看到下列打印信息
install -d /mingw64/include /mingw64/lib/pkgconfig
install -m 644 ./x264.h x264_config.h /mingw64/include
install -m 644 x264.pc /mingw64/lib/pkgconfig
install -d /mingw64/lib
install -m 644 libx264.a /mingw64/lib
gcc-ranlib /mingw64/lib/libx264.a
编译FFmpeg
在ffmpeg根目录下建立build.sh,将下面的脚本保存其中
#!/bin/bash
PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"
PREFIX="./bin-$1"
echo "Install dir: $PREFIX"
./configure \
--prefix=$PREFIX \
--extra-ldsoflags="-static-libgcc" \
--extra-cflags="-I/usr/local/include" \
--extra-ldflags="-L/usr/local/lib" \
--disable-iconv \
--disable-doc \
--disable-debug \
--disable-avdevice \
--disable-indevs \
--disable-outdevs \
--disable-postproc \
--disable-ffplay \
--disable-ffprobe \
--disable-encoders \
--disable-decoders \
--enable-small \
--enable-shared \
--enable-ffmpeg \
--enable-version3 \
--enable-nonfree \
--enable-w32threads \
--enable-avcodec \
--enable-avformat \
--enable-swresample \
--enable-swscale \
--enable-avfilter \
--enable-gpl \
--enable-amf \
--enable-nvenc \
--enable-x86asm \
--enable-libx264 \
--enable-encoder=flv \
--enable-encoder=h264_nvenc \
--enable-encoder=h264_amf \
--enable-encoder=hevc_nvenc \
--enable-encoder=hevc_amf \
--enable-encoder=libx264 \
--enable-encoder=pcm_s16le \
--enable-encoder=pcm_s24le \
--enable-encoder=aac \
--enable-encoder=ac3 \
--enable-encoder=dca \
--enable-encoder=opus \
--enable-encoder=vorbis \
--enable-encoder=srt \
--enable-encoder=ass \
--enable-encoder=subrip \
--enable-encoder=mjpeg \
--enable-encoder=gif \
--enable-decoder=mpeg4 \
--enable-decoder=flv \
--enable-decoder=h264 \
--enable-decoder=hevc \
--enable-decoder=vp9 \
--enable-decoder=h264_cuvid \
--enable-decoder=hevc_cuvid \
--enable-decoder=vp9_cuvid \
--enable-decoder=opus \
--enable-decoder=vorbis \
--enable-decoder=aac \
--enable-decoder=ac3 \
--enable-decoder=eac3 \
--enable-decoder=srt \
--enable-decoder=ass \
--enable-decoder=subrip \
--enable-decoder=pcm_s16le \
--enable-decoder=pcm_s24le \
--enable-decoder=dca \
--enable-decoder=mp3 \
--enable-decoder=flac \
--enable-decoder=ape \
--enable-decoder=mjpeg
make clean
make -j6 #改成你的CPU核心数
make install
然后返回32位终端,执行命令开始编译
#切到FFmpeg根目录
cd /home/FFmpeg-n4.3.1
#编译
./build.sh 32
执行config比较慢,如果编译成功,会在/home/FFmpeg/bin-32/bin目录下生成下列文件
avcodec.lib
avfilter.lib
avformat.lib
avutil.lib
swresample-3.dll
swscale-5.dll
avcodec-58.dll
avfilter-7.dll
avformat-58.dll
avutil-56.dll
ffmpeg.exe
swresample.lib
swscale.lib
2.编译64位DLL
打开MSYS2 MinGW 64
编译x264
cd /home/x264-master/
./configure \
--prefix=/mingw64 \
--enable-static \
--disable-cli
make clean
make -j6 #改成你的CPU核心数
make install
编译FFmpeg
直接使用1.2中的脚本
#切到FFmpeg根目录
cd /home/FFmpeg-n4.3.1
#编译
./build.sh 64
3.编译中可能出现的错误
No working C compiler found:
请确认编译是否在对应的终端中进行,编译32位必须在MSYS2 MinGW 32-bit启动的终端中进行,编译64位必须在 MSYS2 MinGW 64-bit启动的终端中进行。
ERROR: amf requested but not found:
出现次错误表示未在/usr/local/include/AMF目录下找到AMF头文件.
ERROR: nvenc requested, but not all dependencies are satisfied: ffnvcodec:
确保/usr/local/lib/pkgconfig目录下存在ffnvcodec.pc。
ERROR: libx264 not found:
x264未编译成功,确保/mingw64/lib和/mingw32/lib目录下都能找到libx264.a