Ask Your Question

Revision history [back]

reading uncompressed video error

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();

}

click to hide/show revision 2
No.2 Revision

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

berak gravatar image

reading uncompressed video error

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>

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

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



using namespace std;
using namespace cv;

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

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>

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

using namespace std;
using namespace cv;

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

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));
capture.retrieve(frame));
 }
  imshow("video", frame);
 int c = waitKey(33);
  if(c ==27) break;
frame_number++;
 frame_number++;
}
  capture.release();
}

}