You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下用MSYS2 MinGW-64编译FFmpeg持续失败求解决

问题

我尝试在Windows 11系统上编译FFmpeg库以集成到音频处理项目中,执行步骤如下:

  • 安装MSYS2
  • 更新MSYS2:依次执行pacman -Syu和pacman -Su
  • 安装依赖包:pacman -S make pkg-config gcc yasm nasm git diffutils
  • 克隆FFmpeg源码:git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
  • 进入FFmpeg目录:cd ffmpeg
  • 执行配置脚本:./configure --prefix=/usr/local --disable-shared --enable-static
  • 编译FFmpeg:make

编译立即报错终止,尝试FFmpeg旧版本(直至4.1.11版)仍出现类似错误,该版本错误信息如下:

/tmp/cc7SrMT5.s: Assembler messages:
/tmp/cc7SrMT5.s:356: Error: operand type mismatch for shr' /tmp/cc7SrMT5.s:421: Error: operand type mismatch for shr'
/tmp/cc7SrMT5.s:479: Error: operand type mismatch for shr' /tmp/cc7SrMT5.s:640: Error: operand type mismatch for shr'
/tmp/cc7SrMT5.s:707: Error: operand type mismatch for shr' /tmp/cc7SrMT5.s:774: Error: operand type mismatch for shr'
/tmp/cc7SrMT5.s:870: Error: operand type mismatch for shr' /tmp/cc7SrMT5.s:957: Error: operand type mismatch for shr'
/tmp/cc7SrMT5.s:1059: Error: operand type mismatch for shr' /tmp/cc7SrMT5.s:1216: Error: operand type mismatch for shr'
/tmp/cc7SrMT5.s:1361: Error: operand type mismatch for shr' /tmp/cc7SrMT5.s:1453: Error: operand type mismatch for shr'
/tmp/cc7SrMT5.s:1568: Error: operand type mismatch for shr' /tmp/cc7SrMT5.s:1728: Error: operand type mismatch for shr'
/tmp/cc7SrMT5.s:2114: Error: operand type mismatch for shr' /tmp/cc7SrMT5.s:2265: Error: operand type mismatch for shr'
/tmp/cc7SrMT5.s:2602: Error: operand type mismatch for shr' /tmp/cc7SrMT5.s:2720: Error: operand type mismatch for shr'
/tmp/cc7SrMT5.s:2819: Error: operand type mismatch for `shr'
make: *** [ffbuild/common.mak:60: libavformat/adtsenc.o] Error 1

请问为何无法成功编译FFmpeg?是否有对应的解决方法?

原因分析与解决方法

原因

这类operand type mismatch for 'shr'错误,本质是GCC生成的汇编代码与当前使用的汇编器不兼容。通常是因为MSYS2环境中安装的GCC版本较新,而旧版FFmpeg(如4.1.11)的代码未适配新GCC的汇编语法;或是汇编器(gas)与GCC版本不匹配,导致无法正确解析生成的指令。

解决方法

1. 指定兼容的GCC版本编译

若坚持使用旧版FFmpeg,可安装低版本GCC并指定其编译:

  • 安装低版本GCC(例如gcc9):
    pacman -S gcc9
    
  • 配置FFmpeg时指定使用该版本编译器:
    CC=gcc-9 ./configure --prefix=/usr/local --disable-shared --enable-static
    
  • 再执行make编译。

2. 使用新版FFmpeg源码

新版FFmpeg已修复这类兼容性问题,建议切换到最新稳定版编译:

  • 进入FFmpeg目录后,切换到最新稳定分支:
    git checkout n6.1
    
  • 重新执行配置和编译步骤:
    ./configure --prefix=/usr/local --disable-shared --enable-static
    make
    

3. 禁用汇编优化(兜底方案)

若上述方法无效,可在配置时禁用FFmpeg的汇编优化,强制使用纯C代码编译:

./configure --prefix=/usr/local --disable-shared --enable-static --disable-asm

该方法会降低编译后库的性能,但能绕过汇编指令兼容性问题。

内容的提问来源于stack exchange,提问作者machine_1

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 17:35:03