ffmpeg 7.0 + vs2022 +windows编译

后面有总结:

安装msys2

打开 (这一步非常重要不然就得指定vs的环境)

bash 复制代码
x64 Native Tools Command Prompt for VS 2022

运行

在x64 Native Tools Command Prompt for VS 2022命令行中切换到msys2安装目录中

打开

bash 复制代码
msys2_shell.cmd

运行 安装

bash 复制代码
pacman -S diffutils make pkg-config yasm
bash 复制代码
$ pacman -S diffutils make pkg-config yasm
warning: diffutils-3.10-1 is up to date -- reinstalling
warning: make-4.4.1-2 is up to date -- reinstalling
warning: pkgconf-2.1.1-1 is up to date -- reinstalling
warning: yasm-1.3.0-3 is up to date -- reinstalling
resolving dependencies...
looking for conflicting packages...

Packages (4) diffutils-3.10-1  make-4.4.1-2  pkgconf-2.1.1-1  yasm-1.3.0-3

Total Installed Size:  5.36 MiB
Net Upgrade Size:      0.00 MiB

:: Proceed with installation? [Y/n] y
(4/4) checking keys in keyring                               [###############################] 100%
(4/4) checking package integrity                             [###############################] 100%
(4/4) loading package files                                  [###############################] 100%
(4/4) checking for file conflicts                            [###############################] 100%
(4/4) checking available disk space                          [###############################] 100%
:: Processing package changes...
(1/4) reinstalling diffutils                                 [###############################] 100%
(2/4) reinstalling make                                      [###############################] 100%
(3/4) reinstalling pkgconf                                   [###############################] 100%
(4/4) reinstalling yasm                                      [###############################] 100%
:: Running post-transaction hooks...
(1/1) Updating the info directory file...

之后切换到ffmpeg源码目录下:

下载源码:

https://github.com/FFmpeg/FFmpeg.git

切换到目录下

执行:

bash 复制代码
./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --enable-shared --disable-ffprobe --toolchain=msvc

关闭ffprobe方式:

下面有不关闭。

bash 复制代码
$ ./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --enable-shared --disable-ffprobe --toolchain=msvc
cl.exe is unable to create an executable file.
If cl.exe 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.

这个报错是因为没有指定 用vs环境变量编译,要么打开上面的x64 Native Tools Command Prompt for VS 2022

要么手动添加环境变量或指定到msys2中。

建议打开

完事之后:

bash 复制代码
Enabled indevs:
dshow                   gdigrab                 lavfi                   vfwcap

Enabled outdevs:

License: nonfree and unredistributable

多线程编译:

数字8、根据cpu内核自行决定

bash 复制代码
make -j 8 && make install

报错:

bash 复制代码
E:\A\program\github\FFmpeg\config.h(1): warning C4828: 文件包含在偏移 0x21d 处开始的字符,该字符在当前源字符集中无效(代码页 65001)。
fftools/opt_common.c(206): error C2001: 常量中有换行符
fftools/opt_common.c(206): fatal error C1907: 无法从以前的错误中恢复;正在停止编译
make: *** [ffbuild/common.mak:81: fftools/opt_common.o] Error 2
make: *** Waiting for unfinished jobs....
LD      libavcodec/avcodec-61.dll
  正在创建库 libavcodec/avcodec.lib 和对象 libavcodec/avcodec.exp

在fftools/opt_common.c(206)

注释掉

cpp 复制代码
    //av_log(NULL, level, "%sbuilt with %s\n", indent, CC_IDENT);

C:\msys64\usr\local\ffmpeg

下有所有的库

编译带不关闭ffprobe

bash 复制代码
$ ./configure --prefix=/usr/local/ffmpeg--enable-gpl --toolchain=msvc

报错:

bash 复制代码
前源字符集中无效(代码页 65001)。
fftools/ffprobe.c(434): warning C4267: "=": 从"size_t"转换到"int",可能丢失数据
fftools/ffprobe.c(653): warning C4267: "函数": 从"size_t"转换到"int",可能丢失数据
fftools/ffprobe.c(2624): warning C4267: "函数": 从"size_t"转换到"int",可能丢失数据
fftools/ffprobe.c(2625): warning C4267: "函数": 从"size_t"转换到"int",可能丢失数据
fftools/ffprobe.c(4082): warning C4129: "A": 不可识别的字符转义序列
fftools/ffprobe.c(4082): warning C4129: "p": 不可识别的字符转义序列
fftools/ffprobe.c(4082): warning C4129: "g": 不可识别的字符转义序列
fftools/ffprobe.c(4082): warning C4129: "F": 不可识别的字符转义序列
fftools/ffprobe.c(4082): warning C4129: "w": 不可识别的字符转义序列
fftools/ffprobe.c(4082): warning C4129: "s": 不可识别的字符转义序列
fftools/ffprobe.c(4082): fatal error C1001: 内部编译器错误。
(编译器文件"D:\a\_work\1\s\src\vctools\Compiler\CxxFE\sl\p1\c\preprocessor.cpp",第 3705 行)
 要解决此问题,请尝试简化或更改上面所列位置附近的程序。
如果可以,请在此处提供重现步骤: https://developercommunity.visualstudio.com
请选择 Visual C++
"帮助"菜单上的"技术支持"命令,或打开技术支持帮助文件来获得详细信息。
make: *** [ffbuild/common.mak:81: fftools/ffprobe.o] Error 2
make: *** Waiting for unfinished jobs....

关闭 ffprobe.c 4082行代码:

cpp 复制代码
//print_str("compiler_ident", CC_IDENT);

静态库编译:

bash 复制代码
./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --toolchain=msvc --enable-static

静态库添加debug调试信息:--extra-cflags="-g"

msvc是-Zi

bash 复制代码
./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --toolchain=msvc --enable-static --extra-cflags="-Zi"
bash 复制代码
./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --toolchain=msvc --enable-static --extra-cflags="-g"

编译 FFmpeg 通常需要一些步骤和配置,特别是在 Windows 环境下。下面是一个整理后的步骤,以便在 Windows 中使用 Visual Studio 2022 编译 FFmpeg:

前提条件:

  • 安装 Visual Studio 2022。
  • 安装 MSYS2。
  • 下载 FFmpeg 源代码。

步骤:

  1. 安装 MSYS2

    • 打开 x64 Native Tools Command Prompt for VS 2022。
    • 执行 msys2_shell.cmd
  2. 安装必要的依赖项

    bash 复制代码
    pacman -S diffutils make pkg-config yasm
  3. 下载 FFmpeg 源代码

    bash 复制代码
    git clone https://github.com/FFmpeg/FFmpeg.git
  4. 配置 FFmpeg

    bash 复制代码
    cd FFmpeg
    ./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --enable-shared --disable-ffprobe --toolchain=msvc

    如果想要开启 ffprobe,可以使用下面的配置:

    bash 复制代码
    ./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --toolchain=msvc

    若要编译静态库并添加调试信息,可以使用以下配置:

    bash 复制代码
    ./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --toolchain=msvc --enable-static --extra-cflags="-g"
  5. 编译 FFmpeg

    bash 复制代码
    make -j 8 && make install
  6. 处理可能的错误

    • 如果编译时出现错误,可以根据错误信息调整配置或修复代码。
    • 例如,在 fftools/ffprobe.c 中的某些行可能需要注释掉以避免错误。
    • 根据具体情况,可能需要修改其他文件或配置。
  7. 验证安装

    • 确保编译完成且没有错误。
    • C:\msys64\usr\local\ffmpeg 下应该可以找到所有生成的库文件。

通过这些步骤,你应该能够在 Windows 环境中成功编译 FFmpeg。记得根据具体情况调整配置和处理可能的错误。

相关推荐
应用市场25 分钟前
构建自定义命令行工具 - 打造专属指令体
开发语言·windows·python
东方佑27 分钟前
从字符串中提取重复子串的Python算法解析
windows·python·算法
FFZero11 小时前
【C++/Lua联合开发】 (二) Lua调用C++函数
c++·junit·lua
CoderCodingNo2 小时前
【GESP】C++四级真题 luogu-B4068 [GESP202412 四级] Recamán
开发语言·c++·算法
一个不知名程序员www2 小时前
算法学习入门---双指针(C++)
c++·算法
Maple_land2 小时前
常见Linux环境变量深度解析
linux·运维·服务器·c++·centos
Larry_Yanan2 小时前
QML学习笔记(四十四)QML与C++交互:对QML对象设置objectName
开发语言·c++·笔记·qt·学习·ui·交互
Want5953 小时前
C/C++大雪纷飞①
c语言·开发语言·c++
Mr_WangAndy3 小时前
C++设计模式_行为型模式_策略模式Strategy
c++·设计模式·策略模式·依赖倒置原则
LoveXming3 小时前
Chapter11—适配器模式
c++·设计模式·适配器模式·开闭原则