windows10-msys2-msvc编译ffmpeg4.4.2
在msys2安装目录下创建文件
msys2_ffmpeg.bat
call "D:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
set MSYS2_PATH_TYPE=inherit
msys2_shell.cmd
双击运行msys2_ffmpeg.bat, 测试配置, 输出msvc的lib则配置生效
$ echo $LIB
输出:
D:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.32.31326\ATLMFC\lib\x64;D:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.32.31326\lib\x64;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64;D:\Windows Kits\10\lib\10.0.19041.0\ucrt\x64;D:\Windows Kits\10\\lib\10.0.19041.0\\um\x64
- 准备环境
双击运行 msys2_ffmpeg.bat
pacman -S diffutils make pkg-config yasm nasm
说明
pacman -S nasm #汇编工具,安装
pacman -S yasm #汇编工具,安装
pacman -S make #项目编译工具,必须安装
pacman -S diffutils #比较工具,ffmpeg configure 生成makefile时会用到,若不安装会警告,最好是安装
pacman -S pkg-config #库配置工具,编译支持x264和x265用到
pacman -S base-devel # 安装基本开发组件
pacman -S binutils #包含ld等命令
pacman -S automake
wget https://ffmpeg.org/releases/ffmpeg-4.4.2.tar.xz
手动解压
- 编译
./configure \
--prefix=../ffmepg-4.4-win64-msvc \
--enable-static \
--enable-gpl \
--enable-version3 \
--enable-nonfree \
--enable-shared \
--disable-doc \
--disable-pthreads \
--enable-w32threads \
--enable-ffmpeg \
--toolchain=msvc \
--arch=x86_64
make -j8
make install
- 使用
#include <stdio.h>
extern "C" {
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavfilter/buffersink.h"
#include "libavfilter/buffersrc.h"
#include "libavutil/opt.h"
#include "libavfilter/avfilter.h"
}
#pragma comment(lib, "libavcodec.a")
#pragma comment(lib, "libavdevice.a")
#pragma comment(lib, "libavfilter.a")
#pragma comment(lib, "libavformat.a")
#pragma comment(lib, "libavutil.a")
#pragma comment(lib, "libswresample.a")
#pragma comment(lib, "libswscale.a")
#pragma comment(lib, "libpostproc.a")
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "Mfuuid.lib")
#pragma comment(lib, "Strmiids.lib")
#pragma comment(lib, "Mfplat.lib")
#pragma comment(lib, "Bcrypt.lib")
#pragma comment(lib, "Secur32.lib")
int main()
{
char filepath[] = "input.mkv";
AVFormatContext* pFormatCtx = avformat_alloc_context();
av_log_set_level(AV_LOG_DEBUG);
if (avformat_open_input(&pFormatCtx, filepath, NULL, NULL) != 0) {
printf("Couldn't open input stream.\n");
return -1;
}
else {
printf("open success");
}
avformat_close_input(&pFormatCtx);
return 0;
}