2012-10-28 66 views
1

我知道已經有一堆類似的問題,但不幸的是他們都沒有幫助。所以,這就是問題所在(我對OpenCV相當陌生)。OpenCV無法讀取AVI文件

試圖簡單地打開並顯示一個AVI文件。該文件存在,其路徑正確。

int main(int argc, char** argv) 
{ 
    VideoCapture cap; 

    if(!cap.open(argv[1])) 
    { 
     printf("Failed to open %s\n", argv[1]); 
     return -1; 
    } 

    namedWindow("Video output", 1); 

    for(;;) 
    { 
     Mat curFrame; 

     cap >> curFrame; 

     imshow("Video output\n", curFrame); 

     if(waitKey(30) >= 0) 
      break; 
    } 

    return 0; 
} 

沒有錯誤出現,open()返回false。

我以前用mencode轉換過這個文件。下面是有關該文件的信息:

[email protected]:~$ ffmpeg -i out.avi 
ffmpeg version 0.8.3-4:0.8.3-0ubuntu0.12.04.1, Copyright (c) 2000-2012 the Libav developers 
    built on Jun 12 2012 16:37:58 with gcc 4.6.3 
*** THIS PROGRAM IS DEPRECATED *** 
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead. 
Input #0, avi, from 'out.avi': 
    Metadata: 
    encoder   : MEncoder svn r34540 (Ubuntu), built with gcc-4.6 
    Duration: 00:00:01.00, start: 0.000000, bitrate: 265458 kb/s 
    Stream #0.0: Video: rawvideo, yuv420p, 1280x720, PAR 1:1 DAR 16:9, 24 tbr, 24 tbn, 24 tbc 
At least one output file must be specified 

至於我能理解,視頻格式YUV420P,這是由OpenCV的支持。

有什麼建議嗎?

謝謝!

+0

您是否嘗試過打開其他視頻? – ArtemStorozhuk

+0

是的,但沒有效果。也許我缺少一些打開AVI所需的庫? –

+0

你的程序的第一個參數是什麼,視頻文件位於何處?這似乎是錯誤的輸入文件的位置。 – ArtemStorozhuk

回答

1

嗯,問題在於OpenCV編譯時沒有使用ffmpeg(或任何其他視頻庫)支持。

感謝this great post,我成功安裝了ffmpeg並重新編譯了OpenCV,然後一切都很好。