windows 在 Visual Studio 中使用 FFmpeg
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11701635/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use FFmpeg in Visual Studio
提问by box
I'm trying to use FFmpeg in a C++ project in Visual Studio 2010. I want to include the libraries as statically linked files. Simple programs like libavcodec/api-example.ccompile without error and no linker error appears in the error view when starting them. However, a message box shows up after starting the application, saying that avutil-51.dll is missing. Do you have any hints on how to fix that?
我正在尝试在 Visual Studio 2010 的 C++ 项目中使用 FFmpeg。我想将这些库包含为静态链接文件。像libavcodec/api-example.c这样的简单程序编译时不会出错,并且在启动它们时错误视图中不会出现链接器错误。但是,启动应用程序后会出现一个消息框,说缺少 avutil-51.dll。你有什么关于如何解决这个问题的提示吗?
I used the latest dev build from http://ffmpeg.zeranoe.com/builds/. Then I specified include as additional include directory, avcodec.lib;avfilter.lib;avformat.lib;avutil.lib as additional dependencies and lib as additional library directory.
我使用了来自http://ffmpeg.zeranoe.com/builds/的最新开发版本。然后我指定 include 作为附加包含目录,avcodec.lib;avfilter.lib;avformat.lib;avutil.lib 作为附加依赖项,lib 作为附加库目录。
回答by Roman R.
With FFmpeg you can either:
使用 FFmpeg,您可以:
- use pre-built .lib/.dll files and your binary produced with Visual Studio will be dependent on av*.dll files
- compile FFmpeg from source code into static libraries using non-Microsoft compiler, and then link to your Visual Studio project (mind the LGPL/GPL license in this case)
- 使用预先构建的 .lib/.dll 文件,您使用 Visual Studio 生成的二进制文件将依赖于 av*.dll 文件
- 使用非 Microsoft 编译器将 FFmpeg 从源代码编译为静态库,然后链接到您的 Visual Studio 项目(在这种情况下请注意 LGPL/GPL 许可)
You built your project as per item 1 above. You have to use and redistribute the av*.dll dependent files with your binary to have it working.
您按照上面的第 1 项构建了您的项目。您必须使用二进制文件并重新分发 av*.dll 相关文件才能使其正常工作。
"Static" on Zeranoemeans that libraries are statically linked into binaries like ffmpeg.exe
. Do not confuse this with static .lib
libraries that link into your binary. Zeranoe does not provide such.
Zeranoe上的“静态”意味着库被静态链接到二进制文件中,例如ffmpeg.exe
. 不要将此与.lib
链接到二进制文件的静态库混淆。泽拉诺不提供这样的。
On Zeranoeyou will find archives like this:
在Zeranoe 上,您会找到这样的档案:
- "Shared" ffmpeg-20120726-git-236ecc3-win32-shared.7z:
bin/avcodec-54.dll
bin/avutil-51.dll
- etc
- "Dev" ffmpeg-20120726-git-236ecc3-win32-dev.7z:
lib/avcodec.lib
lib/avutil.lib
- “共享” ffmpeg-20120726-git-236ecc3-win32-shared.7z:
bin/avcodec-54.dll
bin/avutil-51.dll
- 等等
- “开发”ffmpeg-20120726-git-236ecc3-win32-dev.7z:
lib/avcodec.lib
lib/avutil.lib
"Shared" archive has FFmpeg built with dynamic link to DLL libraries. "Dev" archive has lib files which you can use in your project to link to them as well in a way that ffmpeg.exe does in shared archive.
“共享”存档具有 FFmpeg,内置 DLL 库的动态链接。“Dev”存档具有 lib 文件,您可以在项目中使用它们以 ffmpeg.exe 在共享存档中所做的方式链接到它们。
So, your Visual Studio project can be as simple as this (browse full source here):
因此,您的 Visual Studio 项目可以像这样简单(在此处浏览完整源代码):
extern "C"
{
// NOTE: Additional directory ..\zeranoe.com\dev\include gets to the files
#include "libavcodec\avcodec.h"
}
// NOTE: Additional directory ..\zeranoe.com\dev\lib gets to the files
#pragma comment(lib, "avcodec.lib")
// NOTE: Be sure to copy DLL files from ..\zeranoe.com\shared\bin to the directory of
// the FFmpegApp.exe binary
int _tmain(int argc, _TCHAR* argv[])
{
_tprintf(_T("Trying avcodec_register_all... "));
avcodec_register_all();
_tprintf(_T("Done.\n"));
return 0;
}
You will extract "Dev" archive into dev
subdirectory of Visual Studio project and you will add dev\include
on the additional include path. This will be sufficient to build the binary, and it will be dependent on av*.dll
:
您将“Dev”存档解压缩到dev
Visual Studio 项目的子目录中,并添加dev\include
额外的包含路径。这足以构建二进制文件,它将依赖于av*.dll
:
This is when you extract the "Shared" archive, and copy DLLs from its bin
to the directory of your binary. And your app will work from there:
这是当您提取“共享”存档并将 DLL 从其复制bin
到二进制文件的目录时。您的应用程序将从那里开始工作:
C:\FFmpegApp\Release>FFmpegApp.exe
Trying avcodec_register_all... Done.
20 Jan 2016 UPDATE: The project in repository is upgraded to Visual Studio 2013 (older VS 2010 code) and checked against current Zeranoe builds. The sample and instructions remain in good standing.
2016 年 1 月 20 日更新:存储库中的项目升级到 Visual Studio 2013(较旧的 VS 2010 代码)并根据当前的 Zeranoe 版本进行检查。样品和说明保持良好状态。
Note that Win32
builds in Visual Studio assume that you use 32-bit files from Zeranoe. To build 64-bit version, download respective files and set up Visual C++ project respectively, to build x64
(or, the best, download both, set up both configurations and configure include/lib paths respectively). Failure to match bitness would result in error, mentioned in the comments below.
请注意,Win32
Visual Studio中的构建假定您使用来自 Zeranoe 的 32 位文件。要构建 64 位版本,请下载相应的文件并分别设置 Visual C++ 项目,以进行构建x64
(或者,最好同时下载,分别设置两个配置并配置 include/lib 路径)。不匹配位将导致错误,在下面的评论中提到。