Reputation: 5619
So I'm trying to use ffmpeg in c++. My code is like this:
#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;
}
}
This code runs in release mode but in debug mode I get the exception at avformat_open_input
:
Unhandled exception at 0x0000000074BC3C35 (avformat-55.dll) in ingrain.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
I downloaded the dll's and lib's directely from ffmpeg's site and included them in my visual studio 2012's project.
Thank's in advance.
Upvotes: 1
Views: 1256
Reputation: 21000
Read the documentation.
int avformat_open_input ( AVFormatContext ** ps,
const char * filename,
AVInputFormat * fmt,
AVDictionary ** options
)
Parameters
ps
: Pointer to user-supplied AVFormatContext (allocated byavformat_alloc_context
). May be a pointer toNULL
, in which case anAVFormatContext
is allocated by this function and written intops
. Note that a user-suppliedAVFormatContext
will be freed on failure.
You haven't initialized pFormatCtx
, either allocate it with avformat_alloc_context
, or set it to nullptr
to have it automatically allocated by avformat_open_input
.
Upvotes: 4