media-autobuild_suite
在提交 issue 之前,请检查该问题是否直接源于执行该套件。这里不是 Doom9、reddit、stackoverflow 或任何其他用于讨论所编译内容的一般性问题的论坛。此脚本仅用于构建它们,仅此而已。
此源代码也在 GitLab 上进行了镜像。
套件中的大多数 git 源使用 GitHub,因此如果 GitHub 宕机,则在该时间运行套件可能毫无用处。
下载
有关编译器环境的信息,请参阅 wiki,那里也有一个如何编译您自己工具的示例。
包含的工具和库
关于 FFmpeg 外部库的信息
-
FFmpeg(共享或静态)及其以下库(均为可选,但默认编译,除非另有说明):
- 轻量级构建:
- amd amf 编码器(内置)
- cuda(内置)
- cuda-llvm(内置)
- cuvid(内置)
- ffnvcodec(git)
- libaom(git)
- libdav1d(git)
- libfdk-aac(git)
- 若非 LGPL,则需要非自由许可证
- libmp3lame(mingw-w64)
- libopus(mingw-w64)
- libvorbis(mingw-w64)
- libvpx(git)
- libx264(git)
- libx265(git)
- nvdec(内置)
- nvenc(内置)
- 带 gmp 的 schannel(mingw-w64)
- 如果未启用 openssl、libtls、mbedtls 或 gnutls,则默认启用
- gmp 可通过 --enable-gcrypt 切换为 gcrypt(mingw-w64)
- sdl2(git tag)(ffplay 所需)
- 默认启用,如不需要请使用 --disable-sdl2
- 模拟 Zeranoe 的构建(在轻量级构建基础上)
- avisynthplus(需要安装 avisynth dll)
- fontconfig(最新发行版)
- 以下 TLS 库(包括 schannel)中只能同时启用一个:
- openssl(mingw-w64)
- 如果三个选项中都存在,则优先于 gnutls 和 libtls
- 需要非 GPL 许可证
- libtls(来自 libressl)(最新发行版)
- 需要非 GPL 许可证
- mbedtls(mingw-w64)
- openssl(mingw-w64)
- 轻量级构建:
-
如果选择 GPLv3 许可证,则优先使用 gnutls - gnutls (3.8.13) - libass (git) - 默认使用 DirectWrite 后端 - 如果启用 --enable-fontconfig,则包含 fontconfig 后端 - 配合 harfbuzz (git) - libbluray (git) - BD-J 支持需要安装 Java JDK - 编译后的 BD-J 支持可能仅需 JRE(未测试) - libfreetype (latest release) - libgsm (mingw-w64) - libmfx (git) - libmodplug (mingw-w64) - libopencore-amr(nb/wb) (mingw-w64) - libopenjpeg2 (mingw-w64) - libopenmpt (git tag) - librav1e (git) - libsnappy (mingw-w64) - libsoxr (git) - libspeex (mingw-w64) - libsrt (git) - libsvtav1 (git) - libtheora (mingw-w64) - libtwolame (mingw-w64) - libvidstab (git) - libvmaf (git) - libvo-amrwbenc (0.1.3) - libwebp (git) - libxml2 (mingw-w64) - libxvid (git) - libzimg (git)
- 完整构建(除 Zeranoe 外)
- chromaprint (mingw-w64)
- cuda filters (需要安装 CUDA SDK)
- 需要非自由许可证
- decklink (12.5.1)
- 需要非自由许可证
- frei0r (git)
- ladspa (mingw-w64)
- libaribb24 (git)
- libaribcaption (git)
- libbs2b (3.1.0)
- libcaca (mingw-w64)
- 完整构建(除 Zeranoe 外)
-
libcdio (mingw-w64) - libcodec2 (git) - libdavs2 (git) - libflite (git) - libfribidi (git) - libgme (git) - libilbc (git) - libjxl (git) - libkvazaar (git) - libmysofa (git) - 用于 sofalizer 滤镜 - libopenh264 (官方二进制文件) - librist (git) - librtmp (git) - librubberband (git) - libssh (mingw-w64) - libsvthevc (git) (使用非上游补丁) - libsvtvp9 (git) (使用非上游补丁) - libtesseract (git) - libuavs3d (git) - libxavs (git) - libxavs2 (git) - libzmq (mingw-w64) - libzvbi (git) - openal (git) - opencl (来自系统) - opengl (来自系统) - vapoursynth (R78) - vulkan (git)
-
其他工具
- aom (git)
- av1an (git)
- 需要已安装或便携版的 64 位 Python 3.12.x 和 Vapoursynth
- bmx (git)
- curl (git) 使用 WinSSL/LibreSSL/OpenSSL/mbedTLS/GnuTLS 后端
- cyanrip (git)
- dav1d (git)
- dssim (git)
- exhale (git)
- faac (git)
- fdk-aac (git)
- ffmbc (git) (不支持)
- flac (git)
- gifski (git)
- 包含可选的内置视频支持 (ffmpeg 6.1)
- haisrt 工具 (git)
- jo (git)
- jpeg-xl 工具 (git)
- jq (git)
- kvazaar (git)
- lame (3.100)
- libaacs (git) (共享)
- libavif (git) 包含以下编码器/解码器:
- aom (enc/dec)
- dav1d (仅 dec)
- rav1e (仅 enc)
- svt-av1 (仅 enc)
- libheif (git) 包含以下编码器/解码器:
- x265 (仅 enc)
- kvazaar (仅 enc)
- libde265 (仅 dec)
- aom (enc/dec)
- dav1d (仅 dec)
- svt-av1 (仅 enc)
- vvenc & vvdec
- uvg266 (仅 enc)
- libjpeg (enc/dec)
- openh264 (仅 dec)
- 未压缩
- libbdplus (git) (共享)
- mediainfo cli (git)
- mp4box (git)
- mplayer (svn) (不支持)
- mpv (git) 除 ffmpeg 库外还包含:
- 基础构建 (ffmpegChoice=2 或 3)
- ANGLE 头文件 (git)
- 需要从其他地方获取 ANGLE 共享库 (例如 Chrome, Firefox) 以支持 gpu-context=angle
- ANGLE 头文件 (git)
- 基础构建 (ffmpegChoice=2 或 3)
-
lcms2 (git) - libass (git) - libbluray (git) - BD-J 支持需要安装 Java JDK - 编译后的 BD-J 支持可能只需要 JRE(未测试) - luajit (git) - mujs (git) - rubberband (git snapshot) - uchardet (mingw-w64) - vulkan, shaderc, spirv-cross, libplacebo (git) - vapoursynth (R78) - 完整构建 (ffmpegChoice=4) - dvdnav (git) - libarchive (mingw-w64) - 共享 libmpv - openal (git)
- opus-tools (git)
- rav1e (git)
- ripgrep (git)
- rtmpdump (git)
- sox (git)
- speex (git)
- svt-av1 (git)
- svt-hevc (git)
- tesseract (git)
- uvg266 (git)
- vlc (git) (broken)
- vvenc & vvdec (git)
- vorbis-tools (git)
- vpx (VP8 and VP9 8, 10 and 12 bit) (git)
- vvc tools (git)
- webp tools (git)
- x264 (8 and 10 bit, with l-smash [mp4 output], lavf and ffms2) (git)
- x265 (8, 10 and 12 bit) (git)
- xvc (git) (unsupported)
- xvid (git)
- zlib (git or mingw-w64)
- minizip, miniunzip (git)
- zlib (Chromium fork, git)
- minizip, minigzip (git)
- zlib (Cloudflare fork, git)
- minigzip (git)
- zlib-ng (git)
- minizip, minigzip (minizip-ng, git)
- zlib-rs (git)
需求
- Windows 64 位(已在 Win10 和 Win11 64 位上测试)
- 不支持 32 位主机。
- NTFS 驱动器
- 完整的 32 位和 64 位构建需要 23GB 以上的磁盘空间,64 位需要 18GB 以上
- 4GB 以上 RAM
- 至少 Powershell 4,目前不支持 Powershell core
- Powershell 5.1 可在此处下载 here
信息
本工具灵感来自 Roger Pack (rdp) 的优秀 Linux 交叉编译工具: https://github.com/rdp/ffmpeg-windows-build-helpers
它基于 msys2,并在 Windows 10 和 11 下进行了测试。 https://www.msys2.org/
我使用了来自 nu774 的一些 jscript 部分: https://github.com/nu774/fdkaac_autobuild
感谢他们所有人!
此 Windows 批处理脚本为在 Windows 下构建 ffmpeg 和其他媒体工具设置了一个 Mingw-w64/GCC 编译器环境。 在构建环境后,它会获取并编译所有工具。所有工具均进行静态编译,无需外部 .dll(有一些可选例外)
使用方法:
- 下载该文件,并将其解压到目标文件夹或
git clone项目。编译器和工具将安装在那里。请确保使用路径较短且不含空格字符的文件夹。一个好的位置可能是:C:\mabs - 双击 media-autobuild_suite.bat 文件
- 选择是否要为 Windows 32 位、64 位或两者进行编译
- 选择是否要编译非自由工具,如 "fdk-aac"
- 选择要使用的 CPU(核心)数量
- 稍等片刻,希望过一会儿你能在 local[32|64]\bin-(audio|global|video) 下找到所有 "*.exe" 工具
该脚本会在 /build/media-autobuild_suite.ini 处写入一个 .ini 文件,因此你只需在第一次选择想要构建的内容时进行这些选择。
该脚本不会创建任何注册表项或系统变量,当你不再需要它时,可以删除该文件夹,你的系统将保持干净。从头开始构建所有内容大约需要 3 小时,具体取决于使用了多少个 CPU 核心以及启用了哪些选项。
查看 forcing-recompilations 以获取有关如何强制重新构建所有库/二进制的文档。
编译完成后,为了节省一些空间,你可以删除 /build 中的所有源文件夹(以 "-git" 或 "-svn" 结尾的文件夹除外)。.bat 中有一个选项,可以让脚本自动删除这些文件夹。为了节省更多空间,你可以在编译后删除 /msys64。如果在删除 /msys64 后运行该套件,它将重新下载。
玩得开心!
Troubleshooting
如果编译过程中出现错误,请按照以下步骤操作:
- 通过下载最新版本并用新文件替换所有文件,确保你正在使用此套件的最新版本;
- 如果你知道是哪个部分崩溃了,删除 /build 中该项目的文件夹并重新运行脚本(例如:如果 x264 失败,尝试删除 /build 中的 x264-git 文件夹);
- 如果仍然不起作用,创建一个 issue 并将脚本给出的
logs.zip的 URL 粘贴到其中,或者自行将文件附加到 issue 页面。 - 如果该问题无法被套件的贡献者复现,那么问题很可能出在你这边。如果 /msys64 和 /local[32|64] 存在,请删除它们。/build 通常可以保留,并且能节省时间;
- 如果该问题可以复现,可能是包本身的问题,或者贡献者会找到一种可能使其正常工作的方法。
- 如果你使用
--enable-cuda-nvcc进行编译,请参阅 关于 CUDA SDK 的说明
各个文件的作用
media-autobuild_suite.bat
- 此文件用于设置 msys2 系统和编译器环境。对于常规使用,您只需启动此文件。每次启动此批处理文件时,它都会执行整个流程,但首次之后,它仅检查某些变量并运行 MinGW 环境的更新。之后,它仅编译从 git 获取更新的工具。
/build/media-autobuild_suite.ini
- 此文件在首次启动后生成,并保存您已选择的设置。在下一次运行之前,您可以对其进行编辑。
/build/media-suite_compile.sh
- 这是编译脚本,它构建我们所需的所有库和工具,例如 ffmpeg;mplayer;等等。你也可以查看它,了解如何编译你自己的工具。通常你可以复制代码并粘贴到 mintty 终端中(除了
make -j $cpuCount,这里你需要填入你的 CPU 核心数)。你不需要启动此脚本,它由批处理脚本调用。
/build/media-suite_update.sh
- 此脚本在你每次运行批处理文件时都会执行。它会检查来自 msys2 的 pacman 等的更新。
/build/media-suite_helper.sh
- 此脚本包含 compile 和 update 使用的辅助函数,用户如有需要也可以
source这些函数。
/build/media-suite_deps.sh
- 此脚本包含
build/media-suite_compile.sh所使用的每个 git 仓库的 URL。这些 URL 可以附加#branch=BRANCH、#commit=COMMITHASH或#tag=TAG,分别用于从分支、提交或标签进行构建。它们也可以被替换,以从 fork 的仓库进行构建(例如,将SOURCE_REPO_SVTAV1=https://gitlab.com/AOMediaCodec/SVT-AV1.git更改为SOURCE_REPO_SVTAV1=https://github.com/gianni-rosato/svt-av1-psy.git)。
/build/media-suite_deps_extra.sh
- 此文件用于覆盖
media-suite_deps.sh中的 URLS,或添加可在额外脚本中使用的新变量。如果该文件存在,它将被media-suite_compile.sh和media-suite_update.sh加载。 - 此文件不打算被提交到版本控制中,而是由用户创建和编辑。
/build/ffmpeg_options.txt & /build/mpv_options.txt
- 如果你选择自行选择 FFmpeg/mpv 可选库的选项,这些文件将包含在编译前发送给 FFmpeg/mpv 的 configure 脚本的选项。你可以按需编辑它们,以获取包含或不包含任何可用功能的自定义 FFmpeg/mpv(如果该套件支持)。
可选用户文件
/local32|64/etc/custom_profile & $HOME/custom_build_options
- 在此处添加针对_你的_特定环境所需的任何通用/平台调整。参见
/local32|64/etc/profile2.local了解用法示例。
自定义补丁
使用自定义补丁不受官方支持,如果你确实使用了自定义补丁,请不要期望从本套件获得太多支持。请前往补丁作者处或相关论坛寻求帮助
- 假设你,读者,具备足够的 bash 知识,以便理解一些基本术语。如果没有,请查阅你不了解的内容。
- 强烈建议查看 编译脚本 中你希望修改的确切软件包,并将函数与 辅助脚本 进行交叉参考,以了解实际执行的操作。
- 虽然建议使用辅助脚本中提供的函数,但没有任何限制阻止你使用实际的命令。
-
若要使用自定义补丁,请在 build 文件夹中创建一个文件名为
<repository's name>_extra.sh的脚本。- 对于 ffmpeg,文件夹名称为 ffmpeg-git,但仓库名称为 ffmpeg:
ffmpeg_extra.sh。 - 对于 game-music-emu,文件夹名称为 game-music-emu-0.6.2,但仓库名称为 game-music-emu:
game-music-emu_extra.sh - 区分大小写,因此对于文件夹名称 SVT-VP9-git(仓库名称 SVT-VP9),脚本文件名应为:
SVT-VP9_extra.sh
- 对于 ffmpeg,文件夹名称为 ffmpeg-git,但仓库名称为 ffmpeg:
-
除非另有说明,命令将在克隆/解压后的文件夹中运行。(flac_extra.sh 将在 flac-git 中运行命令)
若要引用克隆的文件夹本身(flac-git ffmpeg-git),可以使用变量 ${REPO_DIR}。
若要引用生成的 build 文件夹,则需要使用 ${REPO_DIR}/build-${bits} 来引用 64 位构建的 build-64bit 文件夹或 32 位构建的 build-32bit 文件夹。
- 对于某些软件包,build 文件夹可能略有不同(例如共享 ffmpeg 的
build-shared-${bits}或轻量级构建的build-light-${bits}等。请至少尝试编译一次以查看生成了哪些文件夹,或查看 compile script)
如果同时为 32 位和 64 位构建,可以使用 if [[ $bits = 64bit ]]; then <command>; fi 来限制某些命令仅在构建 64 位时运行。
请注意某些软件包具有独特的构建过程(x265、x264 及其他一些软件包),因此务必检查 compile script
示例脚本:/build/aom_extra.sh 用于 aom-git
#!/bin/bash
# Don't automatically run cmake || configure
touch do_not_reconfigure
# Commands to run before running cmake
_pre_cmake(){
# Installs libwebp
do_pacman_install libwebp
# Downloads the patch and then applies the patch
do_patch "https://gist.githubusercontent.com/1480c1/9fa9292afedadcea2b3a3e067e96dca2/raw/50a3ed39543d3cf21160f9ad38df45d9843d8dc5/0001-Example-patch-for-learning-purpose.patch"
# Change directory to the build folder
cd_safe "build-${bits}"
# Run cmake with custom options. This will override the previous cmake commands.
# $LOCALDESTDIR refers to local64 or local32
cmake .. -G"Ninja" -DCMAKE_INSTALL_PREFIX="$LOCALDESTDIR" \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang \
-DBUILD_SHARED_LIBS=off -DENABLE_TOOLS=off
}
_post_cmake(){
# post cmake and post configure will be unavailable due to "touch do_not_reconfigure"
# as the do_not_reconfigure flag will skip the post commands.
}
# Commands to run before building using ninja
_pre_ninja(){
# Change directory to the build folder (Absolute path or relative to aom-git)
cd_safe "build-${bits}"
# applies a local patch (Absolute or relative to aom-git)
do_patch "My-Custom-Patches/test-diff-files.diff"
# run a custom ninja command.
ninja aom_version_check
# Not necessary, but just for readability sake
cd_safe ..
}
示例脚本:/build/ffmpeg_extra.sh 用于 ffmpeg-git
#!/bin/bash
# Force to the suite to think the package has updates to recompile.
# Alternatively, you can use "touch recompile" for a similar effect.
touch custom_updated
_pre_configure(){
#
# Apply a patch from ffmpeg's patchwork site.
do_patch "https://patchwork.ffmpeg.org/patch/12563/mbox/" am
#
# Apply a local patch inside the directory where is "ffmpeg_extra.sh"
patch -p1 -i "$LOCALBUILDDIR/ffmpeg-0001-my_patch.patch"
#
# Add extra configure options to ffmpeg (ffmpeg specific)
# If you want to add something to ffmpeg not within the suite already
# you will need to install it yourself, either through pacman
# or compiling from source.
FFMPEG_OPTS+=(--enable-libsvthevc)
#
}
_post_make(){
# Don't run configure again.
touch "$(get_first_subdir -f)/do_not_reconfigure"
# Don't clean the build folder on each successive run.
# This is for if you want to keep the current build folder as is and just recompile only.
touch "$(get_first_subdir -f)/do_not_clean"
}
有关可能的指令列表,请参阅 unset_extra_script 中的 media-suite_helper.sh。
请注意,它们未来可能会发生变化。
关于 CUDA SDK 的说明
这是针对 cuda-nvcc 的,而非 NVENC,默认情况下由 ffmpeg 构建
要使 --enable-cuda-nvcc 正常工作,您需要安装 NVIDIA 的 CUDA SDK,并确保 CUDA_PATH 变量已在系统范围内设置(通常在安装 CUDA SDK 时默认设置),并且已安装 VS2017 或更高版本,其中应包含 vswhere.exe。
如果由于某种原因 CUDA_PATH 未设置和/或 vswhere.exe 未安装,您需要使用上述用户文件导出 CUDA_PATH 变量路径,并手动导出正确的 PATH,包括转换为 MSVC cl.exe 的绝对 cygpath 路径。
如果您使用默认位置等安装了 SDK,并且启用了 8.3 短路径,或者您安装到没有空格的目录中,则无需执行以下操作
如果您没有理解上述任何词语,请假设一切正常并希望编译首次成功,否则请尝试将 SDK 和 MSVC 重新安装到没有空格的路径中。
只有在 mintty 终端中运行以下命令时生成了包含空格的路径,或者您禁用了 8.3 短路径时,您才需要担心。
cygpath -sm "$CUDA_PATH"
如果运行上述命令生成的路径中包含空格,则需要禁用 cuda 或将 cuda sdk 重新安装到不含空格的路径。
安装 CUDA SDK 时不应手动禁用任何组件,因为随意禁用可能导致编译失败
例如,如果需要手动设置 CUDA_PATH 并在 PATH 中包含 MSVC cl.exe 和 nvcc.exe 的二进制文件,请在 /local64/etc/custom_profile 中的文本文件内添加以下 bash 脚本片段:
# adapt these to your environment
_cuda_basepath="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA"
_cuda_version=10.0
_msvc_basepath="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC"
_msvc_version=14.15.26726
_msvc_hostarch=x64
_msvc_targetarch=x64
# you shouldn't need to change these unless your environment is weird or you know what you're doing
export CUDA_PATH=$(cygpath -sm "${_cuda_basepath}")/${_cuda_version}
export PATH=$PATH:$(dirname "$(cygpath -u "\\${_msvc_basepath}\\${_msvc_version}\bin\Host\\${_msvc_hostarch}\\${_msvc_targetarch}\cl.exe")")
export PATH=$PATH:$CUDA_PATH/bin