Ask Your Question

ianwalters16's profile - activity

2020-03-23 20:35:27 -0600 received badge  Taxonomist
2014-09-04 14:57:57 -0600 received badge  Student (source)
2012-08-29 05:48:06 -0600 asked a question H264 reads but won't write

I'm having some trouble using H264 video with openCV... I'm using the following code to open an avi file, convert to H264 and save a copy....

CvCapture*  capture;    
IplImage*   bgr_frame;    
CvVideoWriter*  writer;    
capture = cvCreateFileCapture("movies//test.avi");    
bgr_frame = cvQueryFrame(capture);

double fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);    
CvSize size = cvSize((int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH),
          (int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT));

writer = cvCreateVideoWriter("movies//Output.avi", 
                CV_FOURCC('H', '2', '6', '4'),
                fps, size);

while( (bgr_frame=cvQueryFrame(capture)) != NULL ) 
{
    cvWriteFrame( writer, bgr_frame );
}

cvReleaseVideoWriter(&writer);

The problem is with cvCreateVideoWriter(). If I use other codecs such as DIVX or XVID it returns a pointer, but not with H264...(returns 0x00000000) This would suggest I don't have H264 installed, right? However, I have created a video with Blender using H264 and checked it with GSpot, which tells me H264 is installed. In fact, the "test.avi" I'm opening with cvCreateFileCapture("movies//test.avi") uses H264... and this call returns a pointer quite happily.

So, the question is... If OpenCV can read an H264 video with cvCreateFileCapture(), surely I should be able to write one with cvCreateVideoWriter()?

I'm using OpenCV 2.3.1 pre-built libraries with VC++10

If anyone has had similar problems I would be extremely grateful for any help!