2016-12-04 48 views
0

在嘗試讀取opencv中的.yuv視頻文件時遇到特定問題。我的代碼如下:在opencv中讀取YUV文件

#include <opencv2/core/core.hpp> 
#include <opencv2/highgui/highgui.hpp> 
#include <opencv2/opencv.hpp> 

using namespace cv; 
using namespace std; 

int main(void) 
{ 

    VideoCapture cap("video/balloons1.yuv"); // open the video file for reading 

    if (!cap.isOpened()) // if not success, exit program 
    { 
     cout << "Cannot open the video file" << endl; 
     return -1; 
    } 

return 0; 
} 

不過,我不斷遇到以下錯誤: enter image description here

我已經安裝了FFmpeg的下面從這個網站上的說明:http://www.wikihow.com/Install-FFmpeg-on-Windows,安裝似乎是正確的。有沒有人有任何想法可能是什麼問題?

回答

1

原始YUV視頻文件不包含任何元數據,如圖片尺寸,時間,使用的像素格式,甚至任何標記以將文件標識爲視頻文件。沒有額外的幫助,沒有玩家可以打開這個文件,OpenCV和ffmpeg也不能。您需要以某種方式告訴OpenCV文件的參數(不確定這甚至可能與OpenCV api)或將文件轉換爲其他格式。

我建議做後者。可能最簡單的方法是在Using FFMPEG to losslessly convert YUV to another format for editing in Adobe Premier(這將無損壓縮視頻文件)中描述,或者您可以嘗試使用能夠存儲原始視頻的某種格式 - IIRC mxf可以。

只要確保爲您的特定文件提供正確的細節 - 正確的尺寸和像素格式至關重要。

+0

感謝您清理這個!我會盡量找到解決辦法 – user1816546