使用 VS2015 编译并调试 ffmpeg
导读 |
ffmpeg 是音频处理方面非常强大非常有名的开源项目了,然而如 雷神 所说,“FFMPEG 难度比较大,却没有一个循序渐进,由简单到复杂的教程。现在网上的有关FFMPEG的教程多半难度比较大,不太适合刚接触 FFMPEG 的人学习;而且很多的例子程序编译通不过,极大地打消了学习的积极性”,对于平时只习惯在 Windows 下开发的初学者来说,从零开始了解相关依赖,搭建起项目并调试 ffmpeg 并不是件容易的事,好在另一个非官方的 开源项目,提供了一整套 Windows 下,用 VS 来调试 ffmpeg 的解决方案——Shift Media Project。 本文使用最新版本的 ShiftMediaProject 的代码(20191015),展示在Windows10 下使用 VS2015 下载代码并成功编译的过程。在另一篇本文参考的 博文 中亦介绍了整个过程,不过由于是 20180307 写的,有些新的内容没有覆盖到,这里可当做是对其进行补充和拓展。同时也作为个人笔记分享出来,希望能帮助到更多刚好有需求的人。 |
目录 |
本文测试使用环境:
操作系统:Windows 10
编译使用开发环境:Visual Studio 2015
下载源代码工具:git 客户端
(ffmpeg 的编译要求编译器对 C99 标准的支持。VS 中默认只有 VS2013 以及更新的版本对 C99 标准提供了支持,所以只能使用 VS2013 之后的版本,如果要使用更前版本,那么就得自己在 VS 先添加 C99 标准的支持)
项目地址:https://github.com/ShiftMediaProject/FFmpeg
需要注意的是,克隆到本地的目标项目目录 至少需要有2层,因为期望的项目的结构是这样子的:
- msvc (OutputDir) (该项目默认的 VS 编译输出的目录)
- source (这个是需要的上一级目录,待会下载的依赖项目有很多,十几二十来个依赖项目都会下载到这里)
- FFmpeg (这个是 clone 到本地的项目目录)
- ..Any other libraries source code.. (其他的十几二十个依赖的项目)
准备好文件夹后,比如这里上面的 "source" 文件夹,在这个文件夹下,克隆代码下来
git clone https://github.com/ShiftMediaProject/FFmpeg.git
所有的 VS 项目相关的文件,都在 SMP 文件夹下,仔细查看该目录下的 readme 文件内容,按里面的说明进行。
This is a small list of steps in order to build FFmpeg into a msvc DLL and lib file. The projects contain Release and Debug builds for static lib files (Debug/Release)
as well as dynamic shared dll files (DebugDLL/ReleaseDLL).
Choose whichever project configuration meets your requirements. Note: FFmpeg requires C99 support in order to compile. Only Visual Studio 2013 or newer supports required C99 functionality and so any
older version is not supported. Visual Studio 2013 or newer is required. If using an older unsupported version of Visual Studio the
Intel compiler can be used to add in the required C99 capability. *** Using the Default Supplied Projects *** The supplied project files are created using default configuration options as used by the ShiftMediaProject.
These projects use Visual Studio 2013/2015 and require certain additional dependencies to be built and available at compile time.
Required project dependencies include:
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 Most of the above dependencies are supplied as part of the ShiftMediaProject repositories.
These repositories can be manually downloaded or automatically cloned using the supplied
project_get_dependencies.bat file. This file can also be used to check for and download
any dependency updates at any point after the first clone of the library. Some of these dependency projects have additional requirements to those listed here. See the corresponding readme for each of the projects for further details. Many of the possible FFmpeg dependencies (and there dependencies) are available in the ShiftMediaProject repositories.
However the following is a list of extra dependency options that require external downloads:
1) opengl (requires glext)
a) Download glext.h and wglext.h from opengl.org.
b) Save the header files into "OutputDir/include/gl/*".
c) Download khrplatform.h from khronos.org
d) Save the header file into "OutputDir/include/KHR/*".
2) ffnvcodec (requires nv-codec-headers)
a) Download the nv-codec-headers repository from https://github.com/FFmpeg/nv-codec-headers
b) Save the contents of the nv-codec-headers repositories "include" folder into "OutputDir/include/*".
3) AMF (requires Advanced Media Framework (AMF) SDK headers)
a) Download the AMF repository from https://github.com/GPUOpen-LibrariesAndSDKs/AMF
b) Save the contents of the AMF repositories "amf/public/include" into "OutputDir/include/AMF/*". *OutputDir is the "Output Directory" specified in the project properties.
The default value of OutputDir is "..\..\msvc" relative to the FFmpeg source directory. An example of the expected
directory structure is:
- msvc (OutputDir)
-> source
- FFmpeg
- ..Any other libraries source code.. Any dependencies supplied by ShiftMediaProject should be downloaded next to the FFmpeg folder as they will use the same OutputDir
location. Projects to build each dependency can be found in the respective repository ./SMP directories or all together using
the all inclusive ffmpeg_deps.sln. Only dependencies built from supplied ShiftMediaProject repositories are tested and supported. Using compiled dependencies from
other sources may result in version mismatch or other issues. Although these external sources generally work fine any problems associated
with them are not covered by ShiftMediaProject and so they should be used with discretion. *** Building with ASM *** In order to build FFmpeg using msvc you must first download and install NASM.
NASM is required to compile all assembly files. 1) Visual Studio NASM integration can be downloaded from https://github.com/ShiftMediaProject/VSNASM/releases/latest 2) Once downloaded simply follow the install instructions included in the download.
readme
按照 readme 说明,接下来:
ShiftMediaProject 使用默认的配置生成了一些项目文件,这些文件可以使用 VS 打开,同时需要依赖特定的额外的项目,才能进一步编译。
依赖的项目包括:
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
上面大部分的依赖项目都被放在了 ShiftMediaProject 用户的 git 仓库 了,这些都可以手动下载,当然强烈建议还是使用 FFmpeg\SMP\project_get_dependencies.bat 批处理自动clone下载,这个脚本不仅仅可在第一次用于clone项目(及其本身依赖的其他git项目),还可以在后面任何时候执行,用来自动更新各自最新的版本
所以,双击执行 “project_get_dependencies.bat” 批处理,等待一段 较长的时间 的下载,即可完成大部分依赖库的下载
大部分需要的依赖(及其自身的依赖)都可以在 ShiftMediaProject 下的仓库找到,不过编译还需要下载其他外部文件。
下面列出了需要额外下载的文件,以及对应需要下载到的目标目录
1) opengl (requires glext)
a) Download glext.h and wglext.h from opengl.org.
b) Save the header files into "OutputDir/include/gl/*".
c) Download khrplatform.h from khronos.org
d) Save the header file into "OutputDir/include/KHR/*".
2) ffnvcodec (requires nv-codec-headers)
a) Download the nv-codec-headers repository from https://github.com/FFmpeg/nv-codec-headers
b) Save the contents of the nv-codec-headers repositories "include" folder into "OutputDir/include/*".
3) AMF (requires Advanced Media Framework (AMF) SDK headers)
a) Download the AMF repository from https://github.com/GPUOpen-LibrariesAndSDKs/AMF
b) Save the contents of the AMF repositories "amf/public/include" into "OutputDir/include/AMF/*".
1、下载 opengl 的 glext.h 和 wglext.h 到 " OutputDir/include/gl/* " (下载点 这里)
2、下载 opengl 的 khrplatform.h 到 " OutputDir/include/KHR/* " (下载点 这里)
3、下载 nv-codec-headers 项目的 "include" 文件夹下的内容到 " OutputDir/include/* " (git 项目点 这里)
4、下载 AMF 项目的 "amf/public/include" 文件夹下的内容到 " OutputDir/include/AMF/* " (git 项目点 这里)
OutputDir 是在项目属性里指定了的 “输出目录 ”
默认的项目输出目录是相对于 FFmpeg 源代码目录的 “..\..\msvc”
一个预期的目录结构如下,(这个也是前面 2、下载源代码 步骤中提到的文件结构)
- msvc (OutputDir) (该项目默认的 VS 编译输出的目录)
- source (这个是需要的上一级目录,待会下载的依赖项目有很多,十几二十来个依赖项目都会下载到这里)
- FFmpeg (这个是 clone 到本地的项目目录)
- ..Any other libraries source code.. (其他的十几二十个依赖的项目)
所以,如上创建 msvc 目录,按步骤创建文件夹并下载对应文件(想偷懒的可以直接点击我下载后打包的 msvc.zip )
下载完了项目依赖的其他 git 项目 和 头文件之后,就可以使用 VS 打开 FFmpeg\SMP\ffmpeg_deps.sln 项目文件了
初次打开项目,如果缺少 Win10 SDK 相关组件,会有类似下图提示
点击 “安装” ,关闭VS后,等待其安装完毕。
实际上,如上 “安装的缺少的功能” 后,重新用 VS 打开项目,还是会提示一些项目 (不可用) 或 (加载失败),还是无法 “重新加载项目”
因为使用 msvc 来编译 ffmpeg 还需要 安装 NASM 才能编译所有的汇编文件。ShiftMediaProject 为编译 ffmpeg 提供的自定义构建项【nasm / yasm】默认 VS是没有支持的,所以最后一步就是为 VS 添加自定构建项
ShiftMediaProject 提供了自动下载和安装 NASM 的安装脚本,下载地址为: https://github.com/ShiftMediaProject/VSNASM/releases/latest
下载完后,以 “管理员身份运行” install_script.bat 即可
若执行成功,没有任何失败提示,便算是安装完成了
不过在我这边的运行环境时出现了2个的错误。
这一步出现的2个错误是:
(1)无法下载 vswhere.exe 到当前目录
(2) 在构建 .......\\VC\bin\amd64\vcvars64.bat 文件的路径时, 构建出一个不存在的路径,导致脚本尝试执行 vcvars64.bat 时出错
第一个错误还好解决,直接手动复制链接到浏览器下载 https://github.com/Microsoft/vswhere/releases/download/2.5.9/vswhere.exe ,然后放在 install_script.bat 同一目录即可
第二个错误就需要手动改 install_script.bat 文件了
经过调试发现,在如下 批处理中:
REM Call the required vcvars file in order to setup up build locations
if "%MSVC_VER%"=="" (
set VCVARS=%VSINSTANCEDIR%\VC\Auxiliary\Build\vcvars%SYSARCH%.bat
) else if "%MSVC_VER%"=="" (
set VCVARS=%VSINSTANCEDIR%\VC\Auxiliary\Build\vcvars%SYSARCH%.bat
) else if "%MSVC_VER%"=="" (
set VCVARS=%VSINSTANCEDIR%\VC\bin%MSVCVARSDIR%\vcvars%SYSARCH%.bat
) else if "%MSVC_VER%"=="" (
set VCVARS=%VSINSTANCEDIR%\VC\bin%MSVCVARSDIR%\vcvars%SYSARCH%.bat
) else (
echo Error: Invalid MSVC version!
goto Terminate
)
构建的变量 %VCVARS% 没有达到预期值,通过打印相关变量(使用 echo 指令),打印出该变量的结果是:
而经过查找,我VS环境中的 vcvars64.bat 实际路径为: "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat", 可能是之前安装VS没有按默认路径安装导致(?)
于是针对我个人的环境情况,根据自己的 vcvars64.bat 脚本的位置,根据我只需要成功为 VS2015 安装这个自定义构建项的需要,我做了如下修改:
//由于VS2015会经过 "%MSVC_VER%"=="14" 的分支,所以我将原先构建的逻辑注释掉(使用 REM),然后直接指定我VS2015 对应的 vcvars64.bat 文件的路径
REM Call the required vcvars file in order to setup up build locations
if "%MSVC_VER%"=="16" (
set VCVARS=%VSINSTANCEDIR%\VC\Auxiliary\Build\vcvars%SYSARCH%.bat
) else if "%MSVC_VER%"=="15" (
set VCVARS=%VSINSTANCEDIR%\VC\Auxiliary\Build\vcvars%SYSARCH%.bat
) else if "%MSVC_VER%"=="14" (
echo [%VSINSTANCEDIR%\VC\bin%MSVCVARSDIR%\vcvars%SYSARCH%.bat]
REM set VCVARS=%VSINSTANCEDIR%\VC\bin%MSVCVARSDIR%\vcvars%SYSARCH%.bat
set VCVARS="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat"
) else if "%MSVC_VER%"=="12" (
set VCVARS=%VSINSTANCEDIR%\VC\bin%MSVCVARSDIR%\vcvars%SYSARCH%.bat
) else (
echo Error: Invalid MSVC version!
goto Terminate
)
重新执行,脚本的执行便没有其他错误了。
重新使用 VS 打开 ffmpeg_deps.sln ,还是提示报错(部分项目未能正确加载),还是没能 “ 重新加载项目 ”
经过一番探索,发现还需要 再安装 另一个 自定义构建项 YASM,这一点是在 ShiftMediaProject 下其他 ffmpeg 的某些依赖项目下说明的,如 https://github.com/ShiftMediaProject/libvpx/tree/master/SMP 项目下的 readme 中:
*** Building with YASM *** In order to build libvpx using msvc you must first download and install YASM.
YASM is required to compile all assembly files. ) Visual Studio YASM integration can be downloaded from https://github.com/ShiftMediaProject/VSYASM/releases/latest ) Once downloaded simply follow the install instructions included in the download.
关于为什么不将 自定义构建项 YASM 的下载说明放到 FFmpeg/SMP/readme.txt 下,项目维护者表示 ffmpeg 本身编译直接依赖的项目只需要 NASM, 只是某些依赖本身编译需要 YASM,想分开来在各自的依赖项目中说明
项目作者具体回复可查看:https://github.com/ShiftMediaProject/FFmpeg/pull/51
ShiftMediaProject 提供了自动下载和安装 yasm 的安装脚本,下载地址为: https://github.com/ShiftMediaProject/VSYASM/releases
安装方法 以及 可能遇到的问题 同上一节 为 VS添加自定构建项 NASM 完全一致
这种情况为依赖项目的子项目没有自动下载导致,这里截图对应的项目为 gnutls 的 git子模块 gnulib 没有自动下载导致。
解决方案:手动下载 gnulib 到 gnutls/gnulib 文件夹下,这里可以使用 git submodule 指令同步下载如下,
如图,如果没有成功下载,可以尝试手动下载,下载地址为 :
https://gitlab.com/libidn/gnulib-mirror.git
或者
git://git.sv.gnu.org/gnulib.git
可使用 git clone 下载代码,然后放置到 gnutls/gnulib 文件夹下即可
可能原因:
解决方案下不同项目设置不一样 (该问题由评论区网友 天空自由 遇到,其使用的的 VS 版本为 VS2019)
参考解决方案:
项目属性 -> 配置属性 -> C/C++ -> 代码生成 -> 运行库
都设置一样就行了: 多线程调试(/MTd)
到此,编译需要的所有事都完成了,重新打开VS,显示(不可用)的项目是还没重新加载, “ 重新加载项目 ”项目即可
接下来,指定一个启动程序来调试,这里设置 ffmpeg.exe 为启动项,“设为启动项目” 后,开始构建编译“生成”
编译过程中,若提示如下,是正常的(可能是因为静态编译模式下 [使用的 lib文件] 在编译生成lib文件后,VS没有及时引用到临时导致的?)
错误 LNK1181 无法打开输入文件“libgmpd.lib” libnettle E:\openSourceGit\ffmpeg-vs\nettle\SMP\LINK 1
错误 LNK1181 无法打开输入文件“libnettled.lib” libhogweed E:\openSourceGit\ffmpeg-vs\nettle\SMP\LINK 1
静静等待其编译结束后,再点构建 “生成” 或是 “运行” 就没报编译上的错误了。
最后的最后,编译完运行 “本地 Windows 调试器”,大概会弹出错误如下:
这是因为“调试”->“命令”使用的文件路径,和 实际在“链接器”->“常规”中设置的“输出文件”路径不一致导致,将前者设置和后者一致即可。
好了,你可以用 vs 调试 ffmpeg 了 !
使用 VS2015 编译并调试 ffmpeg的更多相关文章
- 在CentOS下利用Eclipse调试FFmpeg
所需软件 64位软件打包下载链接:http://pan.baidu.com/s/1i3B08Up 密码:o50u https://yunpan.cn/cBKDSbrGDgBvz 访问密码 1f55 ...
- VS2015编译FFMPEG,修改FFmpeg缓冲区大小解决实时流解码丢包问题,FFmpeg错误rtsp流地址卡死的问题,设置超时
之前尝试过很多网上利用Windows编译FFmpeg的文章,都没有办法编译X64位的FFmpeg,有些教程中有专门提到编译64位的FFmpeg需要下载mingw-w64-install,但是编译的过程 ...
- vs2015编译ffmpeg 出现错误rtmp.lib(rtmp.obj) : error LNK2001: 无法解析的外部符号 ___iob_func
vs2015编译ffmpeg(版本3.0.2)引用外部库文件librtmp出现以下错误: rtmp.lib(rtmp.obj) : error LNK2001: 无法解析的外部符号 __imp__st ...
- VS2015编译ffmpeg的问题解决
刚装了vs2015,打开一些ffmpeg项目,发现不能编译通过,包括stdio.h都无法找到,可能是vs2015的bug吧. 现在记录一下解决方法: 我的目录是这样定义的: C:\Program Fi ...
- vs2015编译OBS-Studio21.1.12
原文地址:http://www.freesion.com/article/37445100/ 参考:https://blog.csdn.net/su_vast/article/details/7498 ...
- 在Windows下利用Eclipse调试FFmpeg
目录 [隐藏] 1 环境与软件 2 第一步:安装MinGW 3 第二步:配置编译环境 4 第三步:配置SDL 5 第四步:编译 5.1 编译faac 5.2 编译fdk-aac 5.3 编译x264 ...
- 用VS2015编译pjsip的工程pjproject-vs14
先去官网下载最新的源码包,我用的版本是2.7.1 . 将源代码解压后,在路径:pjproject-3.7.1\pjlib\include\pj 中创建新文件config_site.h,内容如下: #i ...
- 多媒体开发(8):调试FFmpeg
编译FFmpeg得到二进制文件,之后就是对二进制库的调用,这时FFmpeg就像一个黑盒子.作为程序员,难道不想研究一下FFmpeg的具体实现?比如是怎么拿到歌曲信息的.怎么解码的.怎么推流的,等等. ...
- [转][JSBSim]使用VS2015编译JSBSim
转自csdn原文:https://blog.csdn.net/yu_lei_/article/details/81463187 请大家去看原文,原文有图片和资源,本文仅供本人参考 权威参考:http: ...
随机推荐
- 创建LEANGOO项目
转自:https://www.leangoo.com/leangoo_guide/leangoo_guide_create_project.html#toggle-id-3 一个项目包括多个看板和多名 ...
- 最新Cocoapods 安装及使用
1.移除现有Ruby默认源 gem sources --remove https://rubygems.org/ 2.使用新的源 gem sources -a https://ruby.taobao. ...
- How to: Compile Linux kernel 2.6
Compiling custom kernel has its own advantages and disadvantages. However, new Linux user / admin ...
- 完全平方数 HYSBZ - 2440 (莫比乌斯函数容斥)
完全平方数 HYSBZ - 2440 小 X 自幼就很喜欢数.但奇怪的是,他十分讨厌完全平方数.他觉得这些 数看起来很令人难受.由此,他也讨厌所有是完全平方数的正整数倍的数.然而 这丝毫不影响他对其他 ...
- zencart用sql将某个产品属性值设为只读和默认
zencart用sql将某个产品属性值设为只读和默认 UPDATE `products_attributes` SET `attributes_display_only` = '1', `attrib ...
- flutter 记录正则匹配
手机号正则匹配: // 正则匹配 static bool isChinaPhoneLegal(String str) { return new RegExp('^((13[0-9])|(15[^4]) ...
- loj2425 「NOIP2015」运输计划[二分答案+树上差分]
看到题意最小化最长路径,显然二分答案,枚举链长度不超过$\text{mid}$,然后尝试检验.````` 检验是否存在这样一个边置为0后,全部链长$\le\text{mid}$,其最终目标就是.要让所 ...
- docker run always
https://www.cnblogs.com/kaishirenshi/p/10396446.html
- 一篇文章让您了解MQTT
转载:https://www.jianshu.com/p/de88edf8e023 什么是MQTT MQTT是基于二进制消息的发布/订阅编程模式的消息协议,最早由IBM提出的,如今已经成为OASI ...
- __slots__节约空间
1.为什么要使用__slots__ Python 使用 dicts(hash table)缓存大量的静态资源(属性). 我们最近在Image类中,用仅仅一行__slots__代码,改变成使用tuple ...