简体   繁体   English

需要帮助纠正使用FFmpeg DLL的访问冲突

[英]Need help correcting Access Violation with FFmpeg DLL

I'm trying to use the FFmpeg dll's using Visual Studio 2012 and I'm getting a run time access violation when I call avcodec_find_encoder . 我正在尝试使用FFmpeg dll使用Visual Studio 2012,当我调用avcodec_find_encoder时,我遇到了运行时访问冲突。 Here is the code: 这是代码:

// 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;
}

Here is the error message: 这是错误消息:

Unhandled exception at 0x75C18B60 (msvcrt.dll) in TestFFmpeg.exe: 0xC0000005: Access violation reading location 0x00000049. TestFFmpeg.exe中0x75C18B60(msvcrt.dll)的未处理异常:0xC0000005:访问冲突读取位置0x00000049。

The stack trace is: 堆栈跟踪是:

    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

I'm guessing there's a problem with returning the codec pointer, but I'm new to C++ and have no idea how to correct it. 我猜测返回codec指针存在问题,但我是C ++的新手并且不知道如何纠正它。 I tried the cdecl, stdcall, and fastcall calling conventions -- none corrected the issue. 我尝试了cdecl,stdcall和fastcall调用约定 - 没有更正问题。 I'm using the latest 32-bit DLL from Zeranoe. 我正在使用Zeranoe的最新32位DLL。 Any suggestions? 有什么建议么?

EDIT: I've called other functions in the DLL and they work. 编辑:我已经调用了DLL中的其他函数,它们工作。 For example, avformat_open_input works properly. 例如, avformat_open_input正常工作。 I can pass parameters and the function returns a successful return value (0) and populates the format context structure. 我可以传递参数,函数返回一个成功的返回值(0)并填充格式上下文结构。 av_find_stream_info works as well. av_find_stream_info也可以。 I still can't figure out why avcodec_find_decoder creates an access violation. 我仍然无法弄清楚为什么avcodec_find_decoder会创建访问冲突。

Finally, fixed it. 最后,修复它。 I did two steps and I'm not sure which one worked (heh): 我做了两个步骤,我不确定哪个工作(呵呵):

  1. Added the '.lib' files as linker input dependencies 添加了“.lib”文件作为链接器输入依赖项
  2. I picked up the Sept 7 build and made sure I have all the same build-date for the dll's, libraries, and include files. 我选择了9月7日版本,并确保我拥有dll,库和包含文件的所有相同构建日期。

Everything appears to work fine now. 现在一切似乎都很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM