Ahmed-Anas
Ahmed-Anas

Reputation: 5619

FFMPEG exception in debug mode only

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

Answers (1)

user657267
user657267

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 by avformat_alloc_context). May be a pointer to NULL, in which case an AVFormatContext is allocated by this function and written into ps. Note that a user-supplied AVFormatContext 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

Related Questions