FFmpeg4.3的开发环境搭建


***【在线视频教程】***

好文章,来自【福优学苑@音视频+流媒体】

使用msys2和vs2015编译FFmpeg4.3.1

系统环境:

Windows 10 64位

需要安装的软件和工具:

  Visual Studio 2015 With Update 3

  MSYS2 + mingw(gcc)

  YASM


1、MSYS2

MSYS2内部也是集成了MINGW,采用Pacman管理软件包,使用非常方便。

1、下载:http://msys2.github.io. 选择第二个:msys2-x86_64-20160921.exe

msys2-x86_64-20161025.exe,

msys2-x86_64-20180531.exe

    注意版本:不要下载新版本,否则编译过程中容易报错。

    下载地址:https://sourceforge.net/projects/msys2/files/Base/x86_64/

    下载后,默认安装到d:\__msys64


2、安装后,到msys2窗口执行,

安装编译程序: pacman -S make gcc diffutils pkg-config

    pacman -S make gcc diffutils pkg-config

    # 可能需要多尝试几次,我安装的时候gcc更新了几次才成功,这个更新过程支持断点续传。

    # 如果不安装pkg-config,运行./configure的时候,会出现如下warning

    # WARNING: pkg-config not found, library detection may fail.

    

3、编辑d:\__msys64\msys2_shell.cmd,将其中的:

                  rem set MSYS2_PATH_TYPE=inherit


                   改为:

                  set MSYS2_PATH_TYPE=inherit


4.、重命名d:\__msys64\usr\bin\link.exe 为C: \msys64\usr\bin\link.bak, 避免和MSVC 的 link.exe抵触。



2、YASM

    1.、下载地址:http://yasm.tortall.net/Download.html,下载其64位版本Win64 .exe (64 位 Windows 通用)。


          2、下载后,将yasm-1.3.0-win64.exe 改名为yasm.exe,并放置于 d:\__msys64\usr\bin\目录中。



3、ffmpeg源码:

    下载ffmpeg代码,版本:release4.3.1,

http://www.ffmpeg.org/download.html





4、更新msys64,并改用国内镜像

# 更新mingw-w64-x86_64-toolchain工具链

    pacman -S mingw-w64-x86_64-toolchain

注意:速度慢的堪比蜗牛。

[D:\__msys64\etc\pacman.d]

办法:改用国内的镜像。

mirrorlist.mingw32

##

## 32-bit Mingw-w64 repository mirrorlist

##

 

## Primary

## msys2.org 

Server = http://mirrors.ustc.edu.cn/msys2/mingw/i686/

Server = http://repo.msys2.org/mingw/i686

Server = http://downloads.sourceforge.net/project/msys2/REPOS/MINGW/i686

Server = http://www2.futureware.at/~nickoe/msys2-mirror/i686/



mirrorlist.mingw64

##

## 64-bit Mingw-w64 repository mirrorlist

## 

## Primary

## msys2.org

 

Server = http://mirrors.ustc.edu.cn/msys2/mingw/x86_64/

Server = http://repo.msys2.org/mingw/x86_64

Server = http://downloads.sourceforge.net/project/msys2/REPOS/MINGW/x86_64

Server = http://www2.futureware.at/~nickoe/msys2-mirror/x86_64/



mirrorlist.msys

##

## MSYS2 repository mirrorlist

## 

## Primary

## msys2.org 

Server = http://mirrors.ustc.edu.cn/msys2/msys/$arch/

Server = http://repo.msys2.org/msys/$arch

Server = http://downloads.sourceforge.net/project/msys2/REPOS/MSYS2/$arch

Server =http://www2.futureware.at/~nickoe/msys2-mirror/msys/$arch/





5、下载x264,并编译

请下载这个版本:x264-snapshot-20170208-2245-stable.tar.bz2

http://download.videolan.org/pub/videolan/x264/snapshots/

./configure --prefix=/usr/local/x264  --enable-shared --disable-thread --disable-avs

make

make install


Windows msys2编译ffmpeg找不到库路径问题之解决方法

FFMpeg支持MinGW以及visual studio编译,两者的configure选项在指定链接库的路径时有差异:

msvc:

--extra-ldflags=-LIBPATH:../builds/lib


mingw:

--extra-ldflags=-L../builds/lib




6、编译ffmpeg

开始菜单--->VS 2015--->vs2015 x86/x64本地命令行工具

image.png

#进入下载ffmpeg目录中,

比如:cd  /e/work/ffmpeg/ffmpeg4.3.1

./configure --toolchain=msvc --enable-yasm --enable-asm --enable-shared --disable-static --prefix=/usr/local/ffmpeg431

【注意:由于编码问题,请不要直接复制这个命令行,而是自己手工写】

make 

make install


./configure --toolchain=msvc --enable-yasm --enable-asm --enable-shared --disable-static --enable-libx264 --extra-cflags="-I/usr/local/x264/include" --extra-ldflags=-LIBPATH:c:/x264/lib




坑:


--extra-cflags="-I/usr/local/x264/include"

--extra-ldflags="-L/usr/local/x264/lib"

--extra-ldflags=-LIBPATH:c:/x264/lib







使用VS2015编译并调试FFmpeg4.3


准备工具:vs2015,git

下载源码:https://github.com/ShiftMediaProject/FFmpeg

image.png

git clone https://github.com/ShiftMediaProject/FFmpeg.git


相关依赖:

依赖的项目包括:


bzlib    iconv    zlib    lzma    libxml2    sdl2    libmp3lame    libvorbis    libspeex    libopus    libilbc    libtheora    libx264    libx265    libxvid    libvpx    libgme    libmodplug    libsoxr    libfreetype     fontconfig    libfribidi    libass    gnutls    libgcrypt    libssh    libcdio    libcdio_paranoia     libbluray    opengl    ffnvcodec    libmfx

建议还是使用 FFmpeg\SMP\project_get_dependencies.bat 批处理自动clone下载,这个脚本不仅仅可在第一次用于clone项目(及其本身依赖的其他git项目),还可以在后面任何时候执行,用来自动更新各自最新的版本


所以,双击执行 “project_get_dependencies.bat” 批处理,等待一段 较长的时间 的下载,即可完成大部分依赖库的下载


其它依赖:

https://files.cnblogs.com/files/BensonLaur/msvc.zip

为 VS添加自定构建项 NASM

为 VS添加自定构建项 YASM



参考网页:https://www.cnblogs.com/BensonLaur/p/10989115.html





使用FFmpeg4.3.1的SDK官方开发包编译ffmpeg.c

ffmpeg-4.3.1-win32-dev

include:头文件

Lib:库文件


ffmpeg-4.3.1-win32-shared

Bin:动态库dll


ffmpeg.c的源文件

ffmpeg.c


image.png



使用Qt亲手编译ffmpeg.c源码


原材料:

FFmpeg4.3.1的SDK开发包

FFmpeg.c, cmdutil.c等源文件

Ffmpeg4.3.1的源码:https://github.com/ShiftMediaProject/FFmpeg



编译环境:

IDE:Qt5.9.8

编译器:VC2015

image.png


















好文章,来自【福优学苑@音视频+流媒体】
***【在线视频教程】***