user1816546
user1816546

Reputation: 313

Reading YUV file in opencv

I am encountering a particular problem while attempting to read a .yuv video file in opencv. My code is as follows:

#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;
}

However, I keep encountering the following error: enter image description here

I have installed FFMPEG following the instructions from this website: http://www.wikihow.com/Install-FFmpeg-on-Windows and the installation seems to be correct. Does anyone have any ideas of what the problem might be?

Upvotes: 0

Views: 1327

Answers (1)

Andrey Turkin
Andrey Turkin

Reputation: 2509

Raw YUV video file doesn't contain any metadata such like picture dimensions, timing, used pixel format or even any markers to identify the file as video file. No player can open this file without extra help, and neither can OpenCV nor ffmpeg. You need either to somehow tell OpenCV parameters of the file (not sure this even possible with OpenCV api) or convert the file into some other format.

I suggest doing latter. Probably easiest way do that is described in Using FFMPEG to losslessly convert YUV to another format for editing in Adobe Premier (this will losslessly compress video file), or you can try using some format capable of storing raw video - IIRC mxf is capable.

Just be sure to provide correct details for your particular file - correct dimensions and pixel format are crucial.

Upvotes: 1

Related Questions