0
点赞
收藏
分享

微信扫一扫

Windows MSVC2019 MSYS2编译ffmpeg

上古神龙 2022-02-25 阅读 83

你应该着重优先理解下载中的注意事项,以下操作仅包含 64位 静态库 release版本

功能:

支持264、265\hevc、alaw、pcm、aac编解码

支持MP4、avi封装

支持http rtsp file协议

支持ffprobe解析264 265码流信息

支持drawtext

操作:

MSYS2

下载:官网

cmd.exe
vcvarsall.bat amd64
msys2_shell.cmd -use-full-path
  1. 打开cmd,执行vcvarsall.bat amd64(vcvarsall.bat将会设置INCLUDE和LIB环境变量,以便cl能找到对应头文件和.lib文文件,D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat)
  2. 执行msys2_shell.cmd -use-full-path 或者 修改msys2_shell.cmd:取消这一行的注释,即修改为此:set MSYS2_PATH_TYPE=inherit(msys2命令行继承msvc的编译环境变量)
  3. msys2包含的link.exe与msvc的link.exe冲突,所以可以重命名msys2中的link.exe,当然你可以选择其他方法

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

CMake

下载:官网

  1. windows下所有库我都尽量使用msvc编译,而cmake可以很好的创建vs工程,所以支持cmake的库我都推荐使用cmake生成vs工程,然后进行编译

YASM

下载:官网

汇编编译支持

  1. 下载的YASM运行程序改名为yasm.exe,将它所在的目录加入到环境变量中

x264

CC=cl ./configure --prefix=/usr/local --enable-static --disable-cli
make
make install
  1. CC修改为cl.exe编译,静态库
  2. 特别提醒:此处需要将编译后使用的x264.h中的X264_API 定义为空,注释原有定义,然后使用#define X264_API 即可,否则编译出来的静态库在ffmpeg链接生成可执行文件时会报XXXX无法解析的错误。此处是指编译后使用时,而不是编译前 定义X264_API 为空

x265

cmake创建vs工程

  1. 新建make-solutions.bat,拷贝修改自源码build目录下
@echo off
::
:: run this batch file to create a Visual Studio solution file for this project.
:: See the cmake documentation for other generator targets
::
cmake -G "Visual Studio 16" -A x64 ..\..\source && cmake-gui ..\..\source
  1. 运行make-solutions.bat,根据需要修改,
  2. 注意修改运行库:Windows MSVC2019 MSYS2编译ffmpeg_msys2,静态库 realse模式,否则ffmpeg编译将对此库报错

fdk_aac

使用cmake,类似以上,不做重复描述

ffmpeg

./configure  --toolchain=msvc --prefix=/home/xhp/work/publibs/64/libffmpeg --arch=x86_64 --enable-gpl --enable-nonfree --disable-static --enable-shared --disable-debug --disable-everything --pkg-config-flags="--static" --extra-ldflags="" --enable-libx264 --enable-libx265 --enable-libfreetype --enable-libfdk-aac --enable-decoder=h264 --enable-decoder=hevc --enable-decoder=pcm_alaw --enable-decoder=pcm_mulaw --enable-decoder=mjpeg --enable-decoder=aac --enable-encoder=libx264 --enable-encoder=libx265 --enable-encoder=mjpeg --enable-encoder=pcm_alaw --enable-encoder=pcm_mulaw --enable-encoder=aac --enable-filter=drawtext --enable-parser=h264 --enable-parser=hevc --enable-parser=mjpeg --enable-parser=aac --enable-protocol=file --enable-protocol=data --enable-protocol=async --enable-network --enable-protocol=tcp --enable-demuxer=rtsp --enable-demuxer=mov --enable-demuxer=h264 --enable-demuxer=hevc --enable-muxer=mp4 --enable-muxer=avi --enable-muxer=mjpeg --enable-ffprobe --disable-avdevice

./configure  --toolchain=msvc --prefix=/home/xhp/work/publibs/64/libffmpeg --arch=x86_64 --enable-gpl --enable-nonfree --disable-static --enable-shared --disable-debug --disable-everything --pkg-config-flags="--static" --extra-ldflags="" --enable-libx264 --enable-libx265 --enable-libfreetype --enable-libfdk-aac --enable-decoder=h264 --enable-decoder=hevc --enable-decoder=pcm_alaw --enable-decoder=pcm_mulaw --enable-decoder=mjpeg --enable-decoder=aac --enable-encoder=libx264 --enable-encoder=libx265 --enable-encoder=mjpeg --enable-encoder=pcm_alaw --enable-encoder=pcm_mulaw --enable-encoder=aac --enable-filter=drawtext --enable-parser=h264 --enable-parser=hevc --enable-parser=mjpeg --enable-parser=aac --enable-protocol=file --enable-protocol=data --enable-protocol=async --enable-network --enable-protocol=tcp --enable-demuxer=rtsp --enable-demuxer=mov --enable-demuxer=h264 --enable-demuxer=hevc --enable-muxer=mp4 --enable-muxer=avi --enable-muxer=mjpeg --enable-ffprobe --disable-avdevice
  1. 以上configure已做了较大裁剪,满足开篇提到的功能,其他请自行修改
  2. 备注:
  1. –arch可以设置哪些值呢,直接在configure中搜索“ARCH_LIST”就可以查到
  2. MP4封装对应的启用muxer是–enable-demuxer=mov
  3. --enable-demuxer=h264 --enable-demuxer=hevc//去掉此将导致ffprobe无法探测264 265裸流数据格式

备注:

pkg-config

折磨,仔细了解这个玩意,就一点不折磨,

pkg-config --exists --print-errors xxx //找名为xxx的库,如果不存在报错,需要在PKG_CONFIG_PATH配置的搜索路径中包含有xxx.pc

export PKG_CONFIG_PATH=xxx设置该环境变量

所以增加xxx库进去,只需确认两点:PKG_CONFIG_PATH的搜索路径中是否包含该xxx.pc文件,xxx.pc文件内容中的头文件 库文件路径名称是否正确

另外一个办法:

If you are on a system without pkg-config, you can use the
configure option --pkg-config=true but you also have to
set the appropriate cflags and ldflags:
--pkg-config=true --extra-cflags=-I/usr/include/opus --extra-ldflags=-lopus


举报

相关推荐

0 条评论