之前也编译成功过。就是编译过程与LINUX相差太大,很多库没有编译进去。于是又进行了一番搜索,发现是有可能象LINUX一样编译所有依赖库。

  结果编译后,还是无法加载。我就纳闷了:这是怎么回事?

  • 下载安装msys2

​MSYS2​

  • 安装编译工具

打开MSYS2 MINGW64,输入以下命令:

pacman -Syu --noconfirm
pacman -Sy --noconfirm git mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmark mingw-w64-x86_64-diffutils mingw-w64-x86_64-autotools mingw-w64-x86_64-gdb mingw-w64-x86_64-nasm mingw-w64-x86_64-yasm
pacman -S cmake
pacman -Syu

期间可能会退出,重新打开窗口,再次输入。

  • 编译环境变量
#!/bin/bash
set -eo pipefail

export LOCAL_PATH=$(pwd)
export BUILD_PATH=$LOCAL_PATH/ffmpeg_build_msys2
export PKG_CONFIG_PATH=$BUILD_PATH/lib/pkgconfig
export LD_LIBRARY_PATH=$BUILD_PATH/lib
export CFLAGS=-I$BUILD_PATH/include
export CPPFLAGS=-I$BUILD_PATH/include
export LDFLAGS=-L$BUILD_PATH/lib
export PATH=$BUILD_PATH/bin:$PATH

export CHOST=x86_64
export HOST=x86_64-w64-mingw32
export BASH_PATH=/mingw64/bin
export CC=$BASH_PATH/gcc
export CXX=$BASH_PATH/g++
export AR=$BASH_PATH/ar
export RANLIB=$BASH_PATH/ranlib
export STRIP=$BASH_PATH/strip

# pacman -Syu --noconfirm
# pacman -Sy --noconfirm git mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmark mingw-w64-x86_64-diffutils mingw-w64-x86_64-autotools mingw-w64-x86_64-gdb mingw-w64-x86_64-nasm mingw-w64-x86_64-yasm
# pacman -S cmake
# pacman -Syu

./build-ffmpeg-items.sh
  • 编译

之后就可以使用LINUX编译脚本了,参考:

​LINUX FFMPEG编译详细过程记录(最全)_柳鲲鹏的博客-​

比如吾LINUX脚本是这样的:

#!/bin/bash

. ./lib-ffmpeg.sh
get_ffmpeg_lib_dir


CLEAN_FLAG=1

export PATH=${DEST_LIB_PATH}/bin:${PATH}
export PKG_CONFIG_PATH=${DEST_LIB_PATH}/lib/pkgconfig

# rm -rf ${DEST_DIR}

for item in \
fdk-aac-2.0.2.tar.gz \
ffmpeg-4.4.1.tar.bz2 \
fontconfig-2.13.94.tar.xz \
freetype-2.11.1.tar.xz \
fribidi-1.0.11.tar.gz \
g729-master.zip \
gperf-3.1.tar.gz \
gsm-1.0.19.tar.gz \
ilbc-master.zip \
jpegsrc.v9d.tar.gz \
lame-3.100.tar.gz \
libass-0.15.2.tar.gz \
libpng-1.6.37.tar.xz \
libtool-2.4.6.tar.gz \
libvpx-1.11.0.tar.gz \
libxml2-2.9.12.tar.gz \
libyuv-master.zip \
nasm-2.15.05.tar.xz \
ogg-1.3.5.tar.gz \
openal-soft-1.21.1.tar.gz \
opencore-amr-0.1.5.tar.gz \
openh264-2.1.1.tar.gz \
opus-1.3.1.tar.gz \
SDL2-2.0.14.tar.gz \
speexdsp-SpeexDSP-1.2.0.tar.gz \
speex-Speex-1.2.0.tar.gz \
theora-1.1.1.tar.gz \
vo-amrwbenc-0.1.3.tar.gz \
vorbis-1.3.7.tar.gz \
which-2.21.tar.gz \
x264-stable.tar.bz2 \
x265-3.4.tar.gz \
yasm-1.3.0.tar.gz \
zlib-1.2.11.tar.gz
do
echo ${item}
tar_xf_ffmpeg_item ${item}
done

if [ ! -d ${LINK_LIB_DIR} ]; then
mkdir ${LINK_LIB_DIR}
fi

ROOT_DIR=`pwd`

for item in \
libtool-2.4.6 \
nasm-2.15.05 yasm-1.3.0 \
which-2.21 \
zlib-1.2.11 \
libxml2-2.9.12 \
fdk-aac-2.0.2 \
freetype-2.11.1 fontconfig-2.13.94 \
fribidi-1.0.11 \
g729-master \
gperf-3.1 \
gsm-1.0-pl19 \
ilbc-master \
lame-3.100 \
libass-0.15.2 \
jpeg-9d libpng-1.6.37 \
libvpx-1.11.0 \
ogg-1.3.5 \
openal-soft-1.21.1 \
opencore-amr-0.1.5 \
opus-1.3.1 \
speexdsp-SpeexDSP-1.2.0 speex-Speex-1.2.0 \
theora-1.1.1 \
vo-amrwbenc-0.1.3 \
vorbis-1.3.7 \
libyuv-master \
SDL2-2.0.14 \
openh264-2.1.1 \
x264-stable \
x265-3.4 \
ffmpeg-4.4.1
do
cd ${ROOT_DIR}
cp -rf ${LINK_LIB_DIR} ${item}/${LINK_LIB_DIR}

build_ffmpeg_item ${item}

cd ${ROOT_DIR}
rm -rf ${item}/${LINK_LIB_DIR}

cp ${DEST_LIB_PATH}/lib/* ${LINK_LIB_DIR}

done