在 Visual Studio 中使用 FFmpeg [英] Use FFmpeg in Visual Studio

查看:63
本文介绍了在 Visual Studio 中使用 FFmpeg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Visual Studio 2010 的 C++ 项目中使用 FFmpeg.我想将这些库包含为静态链接文件.像 libavcodec/api-example.c 编译没有错误并且启动它们时错误视图中没有出现链接器错误.但是,启动应用程序后会出现一个消息框,说缺少 avutil-51.dll.你有什么关于如何解决这个问题的提示吗?

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.c compile 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?

我使用了来自 http://ffmpeg.zeranoe.com/builds/ 的最新开发版本.然后我指定 include 作为附加包含目录,avcodec.lib;avfilter.lib;avformat.lib;avutil.lib 作为附加依赖项,lib 作为附加库目录.

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.

推荐答案

使用 FFmpeg,您可以:

With FFmpeg you can either:

  1. 使用预先构建的 .lib/.dll 文件,您使用 Visual Studio 生成的二进制文件将依赖于 av*.dll 文件
  2. 使用非 Microsoft 编译器将 FFmpeg 从源代码编译为静态库,然后链接到您的 Visual Studio 项目(在这种情况下请注意 LGPL/GPL 许可)

您按照上面的第 1 项构建了您的项目.您必须使用二进制文件并重新分发 av*.dll 相关文件才能使其正常工作.

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.

静态"Zeranoe 意味着库被静态链接到二进制文件中,例如 ffmpeg.exe.不要将其与链接到二进制文件的静态 .lib 库混淆.Zeranoe 不提供此类服务.

"Static" on Zeranoe means 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 上,您会找到这样的档案:

On Zeranoe you will find archives like this:

  • 共享"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

共享"存档有 FFmpeg 构建的动态链接到 DLL 库.开发"存档包含 lib 文件,您可以在项目中使用这些文件链接到它们,就像 ffmpeg.exe 在共享存档中所做的那样.

"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.

因此,您的 Visual Studio 项目可以像这样简单(在此处浏览完整源代码):

So, your Visual Studio project can be as simple as this (browse full source here):

extern "C" 
{
        // NOTE: Additional directory ..zeranoe.comdevinclude gets to the files
        #include "libavcodecavcodec.h"
}

// NOTE: Additional directory ..zeranoe.comdevlib gets to the files
#pragma comment(lib, "avcodec.lib")

// NOTE: Be sure to copy DLL files from ..zeranoe.comsharedin 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.
"));
        return 0;
}

您将提取Dev"存档到 Visual Studio 项目的 dev 子目录中,您将在附加包含路径上添加 devinclude.这足以构建二进制文件,它将依赖于 av*.dll:

You will extract "Dev" archive into dev subdirectory of Visual Studio project and you will add devinclude on the additional include path. This will be sufficient to build the binary, and it will be dependent on av*.dll:

这是当您提取共享"文件时存档,并将 DLL 从其 bin 复制到二进制文件的目录中.您的应用将从那里开始运行:

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:

C:FFmpegAppRelease>FFmpegApp.exe
Trying avcodec_register_all... Done.

2016 年 1 月 20 日更新:存储库中的项目已升级到 Visual Studio 2013(较旧的 VS 2010 代码)并根据当前的 Zeranoe 版本进行检查.样品和说明仍然有效.

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.

请注意,Visual Studio 中的 Win32 构建假定您使用来自 Zeranoe 的 32 位文件.要构建 64 位版本,请分别下载相应的文件并设置 Visual C++ 项目,以构建 x64(或者,最好同时下载,分别设置两个配置和配置 include/lib 路径).不匹配位将导致错误,在下面的评论中提到.

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.

2021 年 7 月 20 日更新:(从下面的评论中提取)Zeranoe 版本不再可用.Windows builds by BtbN 是一个很好的官方认可的替代方案.本教程需要一个 (...)-win64-gpl-shared.zip(...)-win64-lgpl-shared.zip 文件.

20 Jul 2021 UPDATE: (pulled from comments below) Zeranoe builds are no longer available. A good and officially endorsed alternative is Windows builds by BtbN. You will need a (...)-win64-gpl-shared.zip or (...)-win64-lgpl-shared.zip file for this tutorial.

这篇关于在 Visual Studio 中使用 FFmpeg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆