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

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

问题描述

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



我使用了最新的dev版本,从 http://ffmpeg.zeranoe.com/builds/ 。然后我指定include作为附加的include目录,avcodec.lib; avfilter.lib; avformat.lib; avutil.lib作为附加依赖项和lib作为附加库目录。

解决方案

使用FFmpeg,您可以:


  1. 使用预构建的.lib / .dll文件和二进制文件使用Visual Studio生成将依赖于av * .dll文件

  2. 将FFmpeg从源代码编译成使用非Microsoft编译器的静态库,然后链接到您的Visual Studio项目(记住LGPL / GPL许可证)

根据上述第1项构建了您的项目。您必须使用并重新分发av * .dll依赖文件与您的二进制文件才能正常工作。



Zeranoe 意味着库被静态链接到二进制文件,如 ffmpeg.exe 。不要将此与与链接到您的二进制文件的静态 .lib 库混淆。泽拉诺没有提供这样的。



Zeranoe 上,你会发现档案如下:




  • 共享ffmpeg-20120726-git-236ecc3-win32-shared.7z:


    • bin / avcodec-54.dll

    • bin / avutil $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $¬$ -20120726-git-236ecc3-win32-dev.7z:


      • lib / avcodec.lib / li>
      • lib / avutil.lib




      • 共享归档文件具有动态链接到DLL库的FFmpeg。 Dev存档有lib文件,您可以在项目中使用它们链接到ffmpeg.exe在共享存档中的方式。



        所以,你的Visual Studio项目可以这样简单(全文浏览源代码):

          externC
        {
        //注意:其他目录..\zeranoe.com\dev\include获取文件
        #includelibavcodec\avcodec.h
        }

        //注意:其他目录..\zeranoe.com\dev\lib获取文件
        #pragma comment(lib,avcodec.lib)

        //注:确保将.. \zeranoe.com\shared\bin中的DLL文件复制到目录
        // FFmpegApp.exe binary
        int _tmain(int argc,_TCHAR * argv [ ])
        {
        _tprintf(_T(Trying avcodec_register_all ...));
        avcodec_register_all();
        _tprintf(_T(Done.\\\
        ));
        return 0;
        }

        您将将Dev归档解压缩到 dev Visual Studio项目的子目录,您将在附加的包含路径上添加 dev \include 。这将足以构建二进制文件,它将依赖于 av * .dll





        这是当你提取共享存档,并将DLL从其 bin 复制到二进制文件的目录。您的应用程序将从那里工作:

          C:\FFmpegApp\Release> FFmpegApp.exe 
        尝试avcodec_register_all ...完成

        2016年1月20日更新:存储库中的项目升级到Visual Studio 2013(旧版VS 2010代码),并检查当前的Zeranoe版本。示例和说明仍然保持良好状态。



        请注意,Visual Studio中的$ code> Win32 假定您使用32-来自Zeranoe的位文件。要构建64位版本,分别下载相应的文件并设置Visual C ++项目,以构建 x64 (或者,最好的,下载两者,设置两个配置和配置包括/ lib路径)。不符合比特率会导致错误,在下面的评论中提到。


        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?

        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.

        解决方案

        With FFmpeg you can either:

        1. use pre-built .lib/.dll files and your binary produced with Visual Studio will be dependent on av*.dll files
        2. 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)

        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.

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

        On Zeranoe you will find archives like this:

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

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

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

        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:

        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:\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.

        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.

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

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