FFmpeg 7.0 版本移除了 6.0 之前已弃用的 API,无法向下兼容。所以编译的版本选择FFmpeg 6.1.1。
一、安装Visual Studio2022
可参考另外一篇文章:Windows安装Visual Studio2022 + QT5.15开发环境_qt5.15.2 vs2022-CSDN博客
二、安装MSYS2
百度网盘链接:https://pan.baidu.com/s/1DWarXxYEXn5HsLPc32eY_g?pwd=imcs
提取码:imcs
安装完成之后,先把安装⽬录(默认路径 c:\msys64
)下的msys2_shell.cmd中注释掉的 rem set MSYS2_PATH_TYPE=inherit 改成 set MSYS2_PATH_TYPE=inherit ,这是为了将vs的环境继 承给MSYS2
添加国内镜像,下载源码用
修改C:\msys64\etc\pacman.d中mirrorlist.msys,在## Primary下面添加清华大学的源镜像
Server = https://mirrors.tuna.tsinghua.edu.cn/msys/$arch/
三、安装编译环境
1、右键使用管理员身份打开x64 Native Tools Command Prompt for VS 2022
进入msys64
的安装目录,执行msys2_shell.cmd -use-full-path
这样会打开MSYS2 的终端:
MSYS2窗口打开后,先把基本的环境安装好
#pacman -Syu 一键安装和升级所有的库
pacman -Syu
#安装编译ffmpeg所需的包
pacman -S gcc
pacman -S make
pacman -S pkg-config
pacman -S diffutils
pacman -S yasm
pacman -S nasm
#避免与msvc的link冲突
mv /usr/bin/link.exe /usr/bin/link.exe.bak
2、安装git:
pacman -S git
3、下载源码
- x264地址:git clone http://git.videolan.org/git/x264.git 或 git clone https://code.videolan.org/videolan/x264.git
- x265地址:git clone https://bitbucket.org/multicoreware/x265_git.git
- fdk-aac地址:git clone --depth 1 https://gitee.com/mirrors/fdk-aac.git
ffmpeg下载地址往后看(此处可忽略)
新建D:\build文件夹并将源代码复制至此
四、编译依赖库
1、编译x264
--enable-shared:编译成动态库(建议)
--enable-static:编译成静态库
D:\build\x264目录下新建build.sh(-j 线程数量,根据自己电脑情况调整)
#!/bin/sh
OPTIONS="--enable-shared"
BUILD_DIR="./../build64"
CC=cl ./configure $OPTIONS --prefix=$BUILD_DIR/
make -j16
make install
make clean
在msys2窗口中cd进入x264目录编译
cd /d/build/x264
sh build.sh
编译完后输出如下文件 :
2、编译x265
D:\build\x265_git\build\msys-cl目录下修改make-Makefiles-64bit.sh
#!/bin/sh
# This is to generate visual studio builds with required environment variables set in this shell, useful for ffmpeg integration
# Run this from within an MSYS bash shell
INSTALL_DIR="./../../../build64/"
target_processor='x64'
path=$(which cl)
if cl; then
echo
else
echo "please launch 'visual studio command prompt' and run '..\vcvarsall.bat amd64'"
echo "and then launch msys bash shell from there"
exit 1
fi
if [[ $path == *$target_processor* ]]; then
echo
else
echo "64 bit target not set, please launch 'visual studio command prompt' and run '..\vcvarsall.bat amd64 | x86_amd64 | amd64_x86'"
exit 1
fi
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DCMAKE_CXX_FLAGS="-DWIN32 -D_WINDOWS -W4 -GR -EHsc" -DCMAKE_C_FLAGS="-DWIN32 -D_WINDOWS -W4" ../../source
if [ -e Makefile ]
then
nmake
fi
nmake install
在msys2窗口中cd进入x265_git/build/msys-cl目录编译
cd /d/build/x265_git/build/msys-cl
sh make-Makefiles-64bit.sh
编译完后输出如下文件 :
3、编译fdk-aac
安装cmake-gui,下载地址:
点击Finish,然后修改输出目录
用Visual Studio2022(有问题请用管理员权限)打开生成的工程fdk-aac.sln
依次编译生成fdk-aac、INSTALL
编译完成后输出如下:
4、编译SDL2 (ffplay需要,不编译ffplay请跳过)
git clone --depth 1 https://github.com/libsdl-org/SDL.git -b SDL2
Visual Studio2022(用管理员权限)打开生成的工程SDL2.sln
依次编译生成SDL2、INSTALL
五、编译FFmpeg
修改D:\build\build64\lib\pkgconfig内的fdk-aac.pc、x264.pc、x265.pc、sdl2.pc内prefix值
进入目录D:\build\build64\lib,将 libx264.dll.lib 重命名为 libx264.lib ,libx265.lib 重命名为 x265.lib
下载FFmpeg源码
方式一:git clone --depth 1 https://github.com/FFmpeg/FFmpeg.git -b release/6.1
方式二:下载地址:https://ffmpeg.org/download.html#releases
修改fftools/opt_common.c 源码文件, 注释掉 CC_IDENT 所在行,如下所示:
static void print_program_info(int flags, int level)
{
const char *indent = flags & INDENT? " " : "";
av_log(NULL, level, "%s version " FFMPEG_VERSION, program_name);
if (flags & SHOW_COPYRIGHT)
av_log(NULL, level, " Copyright (c) %d-%d the FFmpeg developers",
program_birth_year, CONFIG_THIS_YEAR);
av_log(NULL, level, "\n");
//av_log(NULL, level, "%sbuilt with %s\n", indent, CC_IDENT);
av_log(NULL, level, "%sconfiguration: " FFMPEG_CONFIGURATION "\n", indent);
}
修改fftools/ffprobe.c 源码文件, 注释掉 CC_IDENT 所在行,如下所示:
static void ffprobe_show_program_version(WriterContext *w)
{
AVBPrint pbuf;
av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
writer_print_section_header(w, NULL, SECTION_ID_PROGRAM_VERSION);
print_str("version", FFMPEG_VERSION);
print_fmt("copyright", "Copyright (c) %d-%d the FFmpeg developers",
program_birth_year, CONFIG_THIS_YEAR);
//print_str("compiler_ident", CC_IDENT);
print_str("configuration", FFMPEG_CONFIGURATION);
writer_print_section_footer(w);
av_bprint_finalize(&pbuf, NULL);
}
在msys中切换到ffmpeg目录
cd /d/build/ffmpeg/
配置pkg-config
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/d/build/buil64d/lib/pkgconfig
CC=cl ./configure --prefix=/d/build/build64/ffmpeg \
--toolchain=msvc \
--arch=x64 \
--enable-cross-compile \
--enable-gpl \
--enable-nonfree \
--enable-libfdk-aac \
--enable-libx264 \
--enable-libx265 \
--enable-filter=delogo \
--enable-debug \
--disable-optimizations \
--enable-shared \
--enable-sdl2 \
--extra-cflags="-I/d/build/build64/include" \
--extra-ldflags="-L/d/build/build64/lib"
编译:make -j16
安装:make install
生成动态库及可执行程序即大功告成。
标签:Windosw,acc,git,FFmpeg,--,编译,enable,build,https From: https://blog.csdn.net/u012959478/article/details/140662619