Ask Your Question
0

reading uncompressed video error

asked 2013-10-09 07:05:50 -0500

ege gravatar image

updated 2013-10-09 07:57:07 -0500

berak gravatar image

Hi everyone, is there anyone who can manage read uncompressed video file by using opencv videocapture class? I wrote a video with fourcc= I420 and with container .avi by using videowriter class. I can watch it by using gom player but I can't play it by using opencv code. I need to mention that I can play any other compressed avi files by using this code I wrote. Is there a bug in Opencv for reading uncompressed video files? The code I wrote for converting compressed video to uncompressed video.

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include <opencv2/highgui/highgui.hpp>
#include <iostream>



using namespace std;
using namespace cv;


int main( int argc, char *argv[] )
{
    VideoCapture capture(argv[1]);

    Mat frame;

    cout << "# of frame:" << capture.get(CV_CAP_PROP_FRAME_COUNT) << endl;

    int frame_number = 1;
    if(!capture.isOpened())
    {   
        return 1;
    }   
    double rate = capture.get(CV_CAP_PROP_FPS);
    int width = capture.get(CV_CAP_PROP_FRAME_WIDTH);
    int height = capture.get(CV_CAP_PROP_FRAME_HEIGHT);
    //int fourcc = capture.get(CV_CAP_PROP_FOURCC);
    //int fourcc = CV_FOURCC('I','Y','U','V');
    int fourcc = CV_FOURCC('I','4','2','0');
    //int fourcc = -1;

    Size size(width, height);
    VideoWriter my_video("E:\\video_conversion.avi", fourcc, rate, size);

    while(true)
    {
        if(frame_number > 150)
            break;
        cout << frame_number<<endl; 
        if(capture.grab())
        {
        if( capture.retrieve(frame));
        }
    my_video.write(frame);
        frame_number++;
    }
    capture.release();
}

The code I try to read uncompressed video

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main( int argc, char *argv[] )
{
    VideoCapture capture(argv[1]);
    Mat frame;

    cout << "# of frame:" << capture.get(CV_CAP_PROP_FRAME_COUNT) << endl;

    int frame_number = 1;
    if(!capture.isOpened())
    {
        return 1;
    }

    while(true)
    {
        if(frame_number > 150)
            break;
        cout << frame_number<<endl; 
        if(capture.grab())
        {   
            if( capture.retrieve(frame));   
        }

        imshow("video", frame);
        int c = waitKey(33);
        if(c ==27) break;

        frame_number++; 
    }
    capture.release();
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-10-09 07:14:56 -0500

jorge7 gravatar image

Seems like they are work in on it: http://code.opencv.org/issues/2281

In my case I am using Emgu and I get a similar error but only when I try to play two videos at the same time. One works just fine.

edit flag offensive delete link more

Comments

Hi I looked at the issues page on opencv's website (http://code.opencv.org/issues/2281), and the commit on GitHub (https://github.com/Itseez/opencv/pull/1516/commits)

But I am not sure how I should use these files to fix the uncompressed video problem. Do I just download all the files and replace my existing files in opencv? I am using OpenCV 2.4.3. Do you know if this bug has been fixed in later versions of OpenCV and if it would help if I just updated my version?

Thanks.

harshi gravatar imageharshi ( 2013-12-18 23:39:04 -0500 )edit

The bug must be fixed on OpenCV 2.4.7. It is source and binary compatible with 2.4.3, so you can update OpenCV without compilation issues.

Alexander Smorkalov gravatar imageAlexander Smorkalov ( 2013-12-19 02:44:27 -0500 )edit

Question Tools

Stats

Asked: 2013-10-09 07:05:50 -0500

Seen: 941 times

Last updated: Dec 18 '13