SuperMan-Lfj / blog

Apache License 2.0
1 stars 0 forks source link

Windows 上编译ffmpeg #56

Open SuperMan-Lfj opened 1 year ago

SuperMan-Lfj commented 1 year ago

1. 下载并安装Visual Studio 2019 和WinSDK

vs2019用社区版就行: https://learn.microsoft.com/zh-cn/visualstudio/releases/2019/release-notes 安装时,选择C++桌面开发;同时在组件中搜索'clang',选择出来的两个组件。 然后安装就行。安装之后:

WinSDK从这里下载: https://developer.microsoft.com/zh-cn/windows/downloads/windows-sdk/ 安装就行。安装完之后,将SDK的路径添加到系统的环境变量中: 比如这个路径:E:\Windows Kits\10

2. 下载msys2

https://www.msys2.org/ 安装完之后,运行 msys2_shell.cmd 依次运行:

pacman -S make
pacman -S yasm
pacman -S diffutils
pacman -S pkg-config
pacman -S git
pacman -S rsync

运行完之后关闭窗口。

3. 配置MSVC到path中

使用x64 Native Tools Command Prompt for VS 2019 打开msys2_shell.cmd,

打开msys2_shell.cmd 都必须通过上面这种方式打开!!!这样才会继承msvc的环境变量

如果想编译x86的架构,则用x86 Native Tools Command Prompt for VS 2019

然后把下面一行添加到.bash_profile文件的最后,

export PATH="/E/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64":$PATH

如果想编译x86的架构,则改成Hostx86/x86

再 运行source .bash_profile命令 再运行 cl ,如果失败,则编辑msys2_shell.cmd,修改rem set MSYS2_PATH_TYPE=inherit 去掉rem. 然后重新打开msys2_shell.cmd。 cl运行成功的话,会有

用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.29.30147 版
版权所有(C) Microsoft Corporation。保留所有权利。

用法: cl [ 选项... ] 文件名... [ /link 链接选项... ]

4. clone ffmpeg到msys64目录下,并编译

切换分支,configure

./configure --target-os=win64 --toolchain=msvc --arch=x86_64 --enable-shared --disable-static --prefix=output ......

如果想编译x86的架构, --target-os=win32 --arch=x86

make  -j16 && make install