所以我试图在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获得异常。
ingrain.exe: 0xC0000005:访问冲突读取位置0xFFFFFFFFFFFFFFFFFF中0x000000000074BC3C35 (avformat-55.dll)处的未处理异常。
我直接从ffmpeg的网站下载了dll和lib,并将它们包含在我的visual studio 2012项目中。
谢谢已经提前了。
发布于 2015-09-28 09:40:33
读文档。
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分配它,或者将它设置为由avformat_open_input自动分配给nullptr。
https://stackoverflow.com/questions/32819508
复制相似问题