2015-09-28 29 views
1

所以我試圖在C++中使用ffmpeg。我的代碼是這樣的:僅在調試模式下的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)

未處理異常 阿利

.exe:0xC0000005:訪問衝突讀取位置 0xFFFFFFFFFFFFFFFF。

我從ffmpeg的網站上直接下載了dll和lib,並將它們包含在我的visual studio 2012的項目中。

提前致謝。

回答

4

閱讀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自動分配。

相關問題