C++ 需要帮助纠正FFmpeg DLL的访问冲突吗

C++ 需要帮助纠正FFmpeg DLL的访问冲突吗,c++,dll,ffmpeg,visual-studio-2012,C++,Dll,Ffmpeg,Visual Studio 2012,我试图使用Visual Studio 2012使用FFmpeg dll,当我调用avcodec\u find\u encoder时,我遇到了运行时访问冲突。代码如下: // TestFFmpeg.cpp : Defines the entry point for the console application. // #include "stdafx.h" extern "C" { #include "libavcodec\avcodec.h" #include "libavformat\a

我试图使用Visual Studio 2012使用FFmpeg dll,当我调用
avcodec\u find\u encoder
时,我遇到了运行时访问冲突。代码如下:

// TestFFmpeg.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

extern "C" {
#include "libavcodec\avcodec.h"
#include "libavformat\avformat.h"
}

#define INBUF_SIZE 4096

int _tmain(int argc, _TCHAR* argv[])
{
    AVCodec *codec;

    const char *videoFilename = "C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.wmv";

    av_register_all(); // This works; however, no parameters or return values.

    codec = avcodec_find_encoder(CODEC_ID_WMV3);  // Run time Access Violation HERE
    if (!codec) {
    fprintf(stderr, "Codec not found\n");
        exit(1);
    }

    return 0;
}
以下是错误消息:

TestFFmpeg.exe中0x75C18B60(msvcrt.dll)处未处理的异常:0xC0000005:访问冲突读取位置0x00000049

堆栈跟踪是:

    msvcrt.dll!_strcmp()    Unknown
    avcodec-54.dll!6a56caac()   Unknown
    [Frames below may be incorrect and/or missing, no symbols loaded for avcodec-54.dll]    
>   TestFFmpeg.exe!wmain(int argc, wchar_t * * argv) Line 23    C++
    TestFFmpeg.exe!__tmainCRTStartup() Line 533 C
    TestFFmpeg.exe!wmainCRTStartup() Line 377   C
    kernel32.dll!@BaseThreadInitThunk@12()  Unknown
    ntdll.dll!___RtlUserThreadStart@8() Unknown
    ntdll.dll!__RtlUserThreadStart@8()  Unknown
<>我猜返回<代码>编解码器指针有问题,但是我对C++是新的,不知道如何改正它。我尝试了cdecl、stdcall和fastcall调用约定,但都没有解决这个问题。我正在使用来自Zeranoe的最新32位DLL。有什么建议吗

编辑:
我调用了DLL中的其他函数,它们可以工作。例如,
avformat\u open\u input
工作正常。我可以传递参数,函数返回一个成功的返回值(0)并填充格式上下文结构<代码>自动查找流信息也可以使用。我仍然不明白为什么
avcodec\u find\u decoder
会创建访问冲突。

最后,修复了它。我做了两个步骤,但我不确定哪一个有效(呵呵):

  • 添加了“.lib”文件作为链接器输入依赖项
  • 我选择了9月7日的构建,并确保dll、库和包含文件的构建日期都相同

  • 现在一切似乎都很好。

    有趣的是,当我切换到avcodec\u find\u encoder\u by\u name时,我不得不切换到字符串。新代码运行时没有错误,但始终返回NULL(失败),即使我将有效的编解码器名称作为字符串传递。不过,这是一个很好的建议。纯粹出于好奇:如果您通过名称(例如
    (char*)0x49
    )传递一个指向
    avcodec\u find\u encoder\u的无效指针,那么回溯是什么样子的?它是否在相同的
    avcodec
    位置崩溃?`avcodec\u find\u encoder\u by_name((char*)0x49)`运行时没有错误,并且正确地返回空指针。哦,天哪……这不是一个好迹象。我认为DLL和你的编译器一定有分歧。如果您需要的话,我建议您从源代码构建
    libav
    ;这并不是那么困难,如果使用相同的编译器,应该可以解决您的问题。我可以使用Microsoft Visual Studio 2012构建DLL吗,即使它不符合C99?这并没有详细说明修复的真正原因,似乎MSVC本身就有一个bug这似乎在2012年及更高版本中得到修复。更多信息: