ffmpeg 7.0 + vs2022 +windows编译

后面有总结:

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

x64 Native Tools Command Prompt for VS 2022

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

msys2_shell.cmd

运行 安装

pacman -S diffutils make pkg-config yasm
$ 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

切换到目录下

执行:

./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --enable-shared --disable-ffprobe --toolchain=msvc

关闭ffprobe方式:
下面有不关闭。

$ ./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中。
建议打开

完事之后:

Enabled indevs:
dshow                   gdigrab                 lavfi                   vfwcap

Enabled outdevs:

License: nonfree and unredistributable

多线程编译:

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

make -j 8 && make install

报错:

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)
注释掉

    //av_log(NULL, level, "%sbuilt with %s\n", indent, CC_IDENT);


C:\msys64\usr\local\ffmpeg
下有所有的库

编译带不关闭ffprobe

$ ./configure --prefix=/usr/local/ffmpeg--enable-gpl --toolchain=msvc

报错:

前源字符集中无效(代码页 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行代码:

//print_str("compiler_ident", CC_IDENT);

静态库编译:

./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --toolchain=msvc --enable-static

静态库添加debug调试信息:–extra-cflags=“-g”
msvc是-Zi

./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --toolchain=msvc --enable-static --extra-cflags="-Zi"
./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. 安装必要的依赖项

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

    git clone https://github.com/FFmpeg/FFmpeg.git
    
  4. 配置 FFmpeg

    cd FFmpeg
    ./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --enable-shared --disable-ffprobe --toolchain=msvc
    

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

    ./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --toolchain=msvc
    

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

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

    make -j 8 && make install
    
  6. 处理可能的错误

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

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

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

相关推荐

  1. ffmpeg 7.0 + vs2022 +windows编译

    2024-05-11 22:02:05       35 阅读
  2. WindowsVS2022 编译OpenSSL 库

    2024-05-11 22:02:05       46 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-11 22:02:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-11 22:02:05       101 阅读
  3. 在Django里面运行非项目文件

    2024-05-11 22:02:05       82 阅读
  4. Python语言-面向对象

    2024-05-11 22:02:05       91 阅读

热门阅读

  1. Idea 核心编程快捷键-简洁版

    2024-05-11 22:02:05       29 阅读
  2. 嵌入式复习提纲

    2024-05-11 22:02:05       30 阅读
  3. 学习笔记:IEEE 1003.13-2003【POSIX PSE53接口列表】

    2024-05-11 22:02:05       29 阅读
  4. Python图形界面(GUI)Tkinter笔记(目录)

    2024-05-11 22:02:05       32 阅读
  5. leetcode刷题:三数之和

    2024-05-11 22:02:05       33 阅读
  6. 思科基础命令(对标华为的HCIA知识)

    2024-05-11 22:02:05       35 阅读
  7. Goland GC

    Goland GC

    2024-05-11 22:02:05      35 阅读