Opencv视频编写器只写128byte文件(os x el capitan)

时间:2016-03-30 20:46:09

标签: c++ macos opencv

所以我现在尝试了几段代码,或多或少相似,它们都只生成一个128字节的文件。我想将网络摄像头流记录到文件中。

我不相信这是一个编解码器问题,我尝试了所有这些,我仍然只得到128个字节。谁知道这里的问题是什么?到目前为止,我只在MacOS X上试过它。

例如下面的代码:

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

int main( int argc, char** argv ) {
CvCapture* capture;

capture = cvCreateCameraCapture(0);

assert( capture != NULL );

IplImage* bgr_frame = cvQueryFrame( capture );

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

cvNamedWindow( "Webcam", CV_WINDOW_AUTOSIZE );

CvVideoWriter *writer = cvCreateVideoWriter(    "vidtry.AVI",
                                            CV_FOURCC('A','V','C','1'),
                                            30,
                                        size
                                            );

while( (bgr_frame = cvQueryFrame( capture )) != NULL ) 
{
     cvWriteFrame(writer, bgr_frame );
     cvShowImage( "Webcam", bgr_frame );
     char c = cvWaitKey( 33 );
     if( c == 27 ) break;
}
cvReleaseVideoWriter( &writer );
cvReleaseCapture( &capture );
cvDestroyWindow( "Webcam" );
return( 0 );
}

0 个答案:

没有答案