系统相关
首页 > 系统相关> > windows10-msys2-msvc编译ffmpeg4.4.2

windows10-msys2-msvc编译ffmpeg4.4.2

作者:互联网

  1. 下载msys2

在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

测试

echo $LIB
  1. 准备环境

双击运行 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
  1. 下载ffmpeg
wget https://ffmpeg.org/releases/ffmpeg-4.4.2.tar.xz
手动解压
  1. 编译
./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
  1. 使用
#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;
}


参考:
window10_ffmpeg-msys2-msvc编译 - 弦外之音

Windows MSVC2019 MSYS2编译ffmpeg_xuexixhp的技术博客_51CTO博客

标签:comment,msys2,ffmpeg,lib,--,pacman,windows10,pragma,msvc
来源: https://www.cnblogs.com/baigoogledu/p/16621451.html