【问题标题】:Need help correcting Access Violation with FFmpeg DLL需要帮助纠正 FFmpeg DLL 的访问冲突
【发布时间】:2012-09-25 02:17:53
【问题描述】:

我正在尝试通过 Visual Studio 2012 使用 FFmpeg dll,当我调用 avcodec_find_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

我猜返回 codec 指针有问题,但我是 C++ 新手,不知道如何纠正它。我尝试了 cdecl、stdcall 和 fastcall 调用约定——没有一个能纠正这个问题。我正在使用来自 Zeranoe 的最新 32 位 DLL。有什么建议吗?

编辑: 我在 DLL 中调用了其他函数并且它们可以工作。例如,avformat_open_input 可以正常工作。我可以传递参数并且函数返回一个成功的返回值 (0) 并填充格式上下文结构。 av_find_stream_info 也可以。我仍然不明白为什么avcodec_find_decoder 会造成访问冲突。

【问题讨论】:

  • 有趣的是,当我切换到 avcodec_find_encoder_by_name 时,我不得不切换到一个字符串。新代码运行时没有错误,但即使我将有效的编解码器名称作为字符串传递,也总是返回 NULL(失败)。不过建议很好。
  • 纯粹出于好奇:如果您将无效指针传递给avcodec_find_encoder_by_name(例如(char *)0x49),回溯会是什么样子?它会在同一个avcodec 位置崩溃吗?
  • `avcodec_find_encoder_by_name((char *)0x49)` 运行没有错误,并且正确地返回一个空指针。
  • 天哪……这不是一个好兆头。我认为 DLL 和您的编译器一定存在分歧。如果您需要的话,我实际上建议从源代码构建libav;这并不是所有那么困难,如果您使用相同的编译器,它应该可以解决您的问题。
  • 我是否可以使用 Microsoft Visual Studio 2012 构建 DLL,即使它不符合 C99?

标签: c++ dll ffmpeg visual-studio-2012


【解决方案1】:

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

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

现在看来一切正常。

【讨论】:

  • 这并没有详细说明修复的真正原因,似乎 MSVC 本身有一个错误,这似乎在 2012 年及更高版本中修复。更多信息:ffmpeg.org/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-27
  • 2016-02-13
  • 2015-10-30
相关资源
最近更新 更多