当前位置: 首页 > news >正文

Windows编译安装ffmpeg和sdl

1. 下载  MSYS2
下载官网 https://www.msys2.org/ (https://github.com/msys2/msys2-installer/releases/download/2025-06-22/msys2-x86_64-20250622.exe),建议使用迅雷下载
2.安装  MSYS2
安装过程中 “install”环节如果会很慢,可以先“back”,然后在 “install”
3.配置快速的下载源
3.1 # 编辑 64位 MinGW 源配置(最常用)
nano /etc/pacman.d/mirrorlist.mingw64
{清华大学镜像(推荐):
# 对于 mirrorlist.mingw64(64位) ===实际配置的内容
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/x86_64/ 

# 对于 mirrorlist.mingw32(32位)
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/i686/

# 对于 mirrorlist.msys(核心环境) ===实际配置的内容
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/msys/$arch/
}

{中国科学技术大学镜像(备选): ===暂时没有配置
# 对于 mirrorlist.mingw64(64位)
Server = https://mirrors.ustc.edu.cn/msys2/mingw/x86_64/

# 对于 mirrorlist.mingw32(32位)
Server = https://mirrors.ustc.edu.cn/msys2/mingw/i686/

# 对于 mirrorlist.msys(核心环境)
Server = https://mirrors.ustc.edu.cn/msys2/msys/$arch/
}


3.2 # 编辑 MSYS2 核心源配置 备用 (实际操作中没有配置)
nano /etc/pacman.d/mirrorlist.msys

3.3 # 编辑 32位 MinGW 源配置(如需)备用
nano /etc/pacman.d/mirrorlist.mingw32

3.4. # 强制刷新源并更新系统(首次可能仍需几分钟,后续会更快)
pacman -Syu

4. 在 MSYS2 终端中执行以下命令,安装编译 FFmpeg 所需的基础工具(编译器、汇编器、版本控制等):安装编译工具(64位为例,32位将x86_64替换为i686)
pacman -S --needed  mingw-w64-x86_64-gcc  mingw-w64-x86_64-make   mingw-w64-x86_64-nasm  git  mingw-w64-x86_64-pkg-config make
说明:
mingw-w64-x86_64-gcc \       # GCC编译器(64位)
mingw-w64-x86_64-make \      # Make构建工具
mingw-w64-x86_64-nasm \      # 汇编器(FFmpeg推荐用nasm)
git \                         # 拉取FFmpeg源码
mingw-w64-x86_64-pkg-config  # 用于检测依赖库

5. 安装 FFmpeg 依赖库(可选)FFmpeg 支持多种编解码器(如 H.264、H.265、AAC 等),需提前安装对应依赖库(根据需求选择):# 常用依赖(64位):
pacman -S --needed   mingw-w64-x86_64-x264  mingw-w64-x86_64-x265 mingw-w64-x86_64-fdk-aac mingw-w64-x86_64-openssl   mingw-w64-x86_64-libvpx mingw-w64-x86_64-libvorbis
说明
mingw-w64-x86_64-x264 \      # H.264编码器
mingw-w64-x86_64-x265 \      # H.265编码器
mingw-w64-x86_64-fdk-aac \   # AAC编码器(需启用非自由协议)
mingw-w64-x86_64-openssl \   # 支持HTTPS(如RTSP/RTMP加密)
mingw-w64-x86_64-libvpx \    # VP8/VP9编码器
mingw-w64-x86_64-libvorbis   # Vorbis编码器

6. 获取 FFmpeg 源码
通过git拉取最新 FFmpeg 源码(或从官网下载稳定版源码包):
bash
# 克隆FFmpeg源码仓库(最新开发版)
git clone https://git.ffmpeg.org/ffmpeg.git

# 进入源码目录
cd ffmpeg
git checkout n7.1.1

6.2
./configure --prefix=/c/ffmpeg_build --enable-shared --enable-static --enable-gpl --enable-version3 --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-openssl --disable-doc --disable-debug --arch=x86_64 --target-os=mingw32  --enable-nonfree

  说明
--prefix=/c/ffmpeg_build \  # 安装路径(自定义,如C:\ffmpeg_build)
--enable-shared \           # 生成动态库(.dll)
--enable-static \           # 生成静态库(.a)
--enable-gpl \              # 启用GPL协议(需包含x264/x265等GPL库时必须)
--enable-version3 \         # 启用版本3许可证
--enable-libx264 \          # 启用x264(H.264编码)
--enable-libx265 \          # 启用x265(H.265编码)
--enable-libfdk-aac \       # 启用fdk-aac(高质量AAC编码)
--enable-openssl \          # 启用HTTPS支持
--disable-doc \             # 禁用文档(加速编译)
--disable-debug \           # 禁用调试模式(减少库体积)
--arch=x86_64 \             # 架构(64位)
--cross-prefix=x86_64-w64-mingw32- \  # 交叉编译前缀(自动识别可省略)
--target-os=mingw32         # 目标系统
--enable-nonfree  # 新增:允许非自由组件(解决与 libfdk-aac 的冲突)
关键选项说明:
--enable-shared:生成动态库(avcodec-59.dll等),需用于运行时;
--enable-static:生成静态库(avcodec.a等),用于链接到程序;
--enable-gpl:若使用 x264/x265(GPL 协议),必须启用,否则编译失败;
如需精简库,可添加--disable-encoders/--disable-decoders排除不需要的编解码器。

6.3 如何报错
libfdk_aac is incompatible with the gpl and --enable-nonfree is not specified.

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.libera.chat.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.
可以添加   --enable-nonfree  # 新增:允许非自由组件(解决与 libfdk-aac 的冲突) 选项

6.4 如果报错
./configure --prefix=/f/ffmpeg_build --enable-shared --enable-static --enable-gpl --enable-version3 --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-openssl --disable-doc --disable-debug --arch=x86_64 --target-os=mingw32 --enable-nonfree
gcc is unable to create an executable file.
If gcc is a cross-compiler, use the --enable-cross-compile option.
Only do this if you know what cross compiling means.
C compiler test failed.

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.libera.chat.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.
解决方案:
确认终端类型(关键!)
MSYS2 有多个终端(MSYS2 MSYS、MSYS2 MinGW 64-bit、MSYS2 MinGW 32-bit),必须使用与编译架构匹配的 MinGW 终端:
如果你编译 64 位 FFmpeg,必须启动 MSYS2 MinGW 64-bit(而非默认的 MSYS2 MSYS)。
终端标题会显示 MINGW64 前缀,确保进入这种终端后再执行编译命令。
原因:MSYS2 MSYS 终端使用的是 MSYS 环境的工具链,而 MinGW 64-bit 才会加载正确的 MinGW 编译器(x86_64-w64-mingw32-gcc)。
最后进入到C:\msys64目录,启动mingw64.exe程序,重新执行  ./configure --prefix=/f/ffmpeg_build --enable-shared --enable-static --enable-gpl --enable-version3 --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-openssl --disable-doc --disable-debug --arch=x86_64 --target-os=mingw32 --enable-nonfree
6.5 如果感觉执行configure命令是卡主不动,可以进入到 ffmpeg 目录新下,执行命令查看配置日志
tail -f ffbuild/config.log   ,该日志会实时输入配置结果


6.5 configure完成后输出了 (大概执行了20多分钟)
License: nonfree and unredistributable
./configure: line 1774: cmp: command not found
./configure: line 1774: cmp: command not found
./configure: line 1774: cmp: command not found
./configure: line 1774: cmp: command not found
./configure: line 1774: cmp: command not found
./configure: line 1774: cmp: command not found
./configure: line 1774: cmp: command not found
./configure: line 1774: cmp: command not found
./configure: line 1774: cmp: command not found
./configure: line 1774: cmp: command not found
./configure: line 1774: cmp: command not found
./configure: line 1774: cmp: command not found
./configure: line 1774: cmp: command not found
./configure: line 1774: cmp: command not found
但是没有影响
6.6 make -j16 编译即可
6.7 make install 安装完成

7. SDL 编译和按钮
7.1 下载sdl(到gitlab上下载 https://github.com/libsdl-org/SDL_net )
7.1.1 使用 fastgithub 加速 gitlab (下载链接: )
7.1.2 启动 fastgithub
7.1.3 https://github.com/libsdl-org/SDL_net 选择tag为2.2.0的版本或者其他版本,本次选用的是2.2.0
7.2 编译配置
./configure --prefix=/f/sdl_2.2.0_build/
7.3 编译 
make -j16
7.4 安装
make install 

http://www.dtcms.com/a/309214.html

相关文章:

  • CG--逻辑判断1
  • 实战指南:如何将Git仓库中的特定文件夹及其历史完整迁移到另一个仓库
  • Git 各场景使用方法总结
  • java8学习笔记-Stream流
  • 在uni-app中引入本地日志插件
  • 城市数字孪生之GISBox三维顶层重建白皮书
  • 操作系统:共享内存通信(Shared Memory Systems)
  • WAIC 2025再发AI十大展望
  • WaitForSingleObject 函数参数影响及信号处理分析
  • SpringAI智能客服Function Calling兼容性问题解决方案
  • 中国信通院/华为:智能体技术和应用研究报告(2025)(转载)
  • 充电桩与照明“联动”创新:智慧灯杆破解新能源基建难题
  • AntFlow 1.0.0 正式发布:企业级开源工作流引擎,历经一年打磨,全面上线!
  • Nginx配置优先级问题导致静态资源404
  • 新书速览|Python数据分析师成长之路
  • 实战指南|虚拟电厂管理平台搭建全流程解析(一)
  • 谷歌Firebase动态链接将失效:如何选择深度链接替代方案?
  • ccf接口测试实战
  • 机器学习sklearn:编码、哑变量、二值化和分段
  • Implement recovery based on PITR using dump file and binlog
  • 用离子交换树脂做镍钴分离的工艺优势
  • Solana:解决Anchor Build编译程序报错 no method named `source_file` found for struct
  • 暑期算法训练.12
  • 练习javaweb+mysql+jsp
  • 渗透测试常用指令
  • [vue3 echarts] echarts 动态数据更新 setInterval
  • winform,DataGridView单元格点击选择日期,日期控件
  • 使用 whisper, 音频分割, 整理需求 2
  • 高防服务器租用:保障数据安全
  • 【智能Agent场景实战指南 Day 29】Agent市场趋势与前沿技术