【问题标题】:FFMPEG exception in debug mode only仅调试模式下的 FFMPEG 异常
【发布时间】:2015-09-28 09:20:38
【问题描述】:

所以我尝试在 c++ 中使用 ffmpeg。我的代码是这样的:

#include <iostream>

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

}

using namespace std;
#pragma comment(lib, "dev/lib/avcodec.lib")
#pragma comment(lib, "dev/lib/avformat.lib")
#pragma comment(lib, "dev/lib/swscale.lib")

int main()
{
    avcodec_register_all();
    av_register_all();
    char inputFile[] = "video.mp4";
    AVFormatContext *pFormatCtx;

    if (avformat_open_input(&pFormatCtx, inputFile, NULL, 0) != 0) // exception occurs here
    {
        cout << "could not open file"; 
        return -1;
    }

}

此代码在发布模式下运行,但在调试模式下我在avformat_open_input 得到异常:

在 0x0000000074BC3C35 (avformat-55.dll) 中未处理的异常 ingrain.exe: 0xC0000005: 访问冲突读取位置 0xFFFFFFFFFFFFFFFF.

我直接从 ffmpeg 的网站下载了 dll 和 lib,并将它们包含在我的 Visual Studio 2012 项目中。

提前致谢。

【问题讨论】:

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


    【解决方案1】:

    阅读documentation

    int avformat_open_input ( AVFormatContext ** ps,
                              const char * filename,
                              AVInputFormat * fmt,
                              AVDictionary ** options 
                            )   
    

    参数

    ps:指向用户提供的 AVFormatContext 的指针(由 avformat_alloc_context)。可能是指向NULL 的指针,在这种情况下 AVFormatContext 由该函数分配并写入ps。 请注意,用户提供的AVFormatContext 将在失败时被释放。

    你还没有初始化pFormatCtx,要么用avformat_alloc_context分配它,要么把它设置为nullptr,让它由avformat_open_input自动分配。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-11
      • 1970-01-01
      • 2012-04-28
      • 1970-01-01
      • 2013-03-23
      相关资源
      最近更新 更多