当前位置: 首页 > 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.lryc.cn/news/607190.html

相关文章:

  • 电子电气架构 --- 软件项目变更管理
  • Squid服务配置代理
  • 荣耀平板儿童限制
  • 温度影响的材料合成与生长-属于动力学控制还是热力学控制
  • 美团进军折扣超市,外卖未平、超市大战再起?
  • 什么是三防平板电脑?三防平板有什么作用?
  • Qt-----初识
  • Cesium性能优化
  • android MVC/MVP/MVVM/MVI架构发展历程和编写范式
  • W3D引擎游戏开发----从入门到精通【10】
  • 蚂蚁开源团队发布的2025大模型开源开发生态发展情况速览
  • androidstudio调试apt
  • Ubuntu 系统下使用 lsusb 命令识别 USB 设备及端口类型详解
  • LS-DYNA 分析任务耗时长,企业如何科学提升许可证使用效率?
  • Flask 中的应用上下文和请求上下文
  • [AI8051U入门第十二步]W5500-Modbus TCP从机
  • SQLFlash:一款由AI驱动的SQL优化工具
  • leetcode热题——全排列
  • 《平台经济法律风险合规发展》研讨会在北京召开
  • Fiddler中文版使用指南 提升开发流程的一站式抓包与调试体验
  • Day17--二叉树--654. 最大二叉树,617. 合并二叉树,700. 二叉搜索树中的搜索,98. 验证二叉搜索树
  • 如何在 Mac OS 上安装 Cursor
  • 【目标检测】芯片缺陷识别中的YOLOv12模型、FP16量化、NMS调优
  • Lombok常用注解及功能详解
  • Redis学习18-分布式锁
  • Vue 3.5 defineModel:让组件开发效率提升 10 倍
  • 暑期算法训练.12
  • 【VSCode】常用插件推荐(持续更新~)
  • 从资源闲置到弹性高吞吐,JuiceFS 如何构建 70GB/s 吞吐的缓存池?
  • C 实现难度过高的俄罗斯方块