使用openCV在MAC上读取/写入avi视频 [英] read/write avi video on MAC using openCV
问题描述
我正在尝试在 MAC 10.6.8 上使用 openCV 2.4.0 读取 avi 视频并再次写入它,因为它没有任何更改
I am trying to read avi video and write it again as it is without any change using openCV 2.4.0 on MAC 10.6.8
我的视频是灰度的,frame_rate = 25,编解码器= 827737670,即FFV1(我想)
My videos is grayscale with frame_rate = 25 and Codec = 827737670 which is FFV1 (I guess)
问题是....当我按原样读写视频时....我看到尺寸和颜色发生了许多变化...经过3到4次写作,我可以看到视频开始变成(粉红色)彩色!!!
The problem is .... when I read and write the video as it is .... I see many changes in size and in color ... After 3 or 4 times of writing I can see the video start to be (Pink) color !!!
我不确定是什么问题!!!
I am not sure what is the problem !!!
这是我对感兴趣的人的代码
this is my code for the people who interest
提前感谢您的帮助:D
Appreciate your help in advance :D
Seereen
注意:我的计算机上装有FFMPEG V 0.11(我不知道这是否重要)
Note : I have on my computer FFMPEG V 0.11 (I do not know if this important)
{
int main (int argc, char * const argv[]) {
char name[50];
if (argc==1)
{
printf("\nEnter the name of the video:");
scanf("%s",name);
} else if (argc == 2)
strcpy(name, argv[1]);
else
{
printf("To run this program you should enter the name of the program at least, or you can enter the name of the program then the file name");
return 0;
}
cvNamedWindow( "Read the video", CV_WINDOW_AUTOSIZE );
// GET video
CvCapture* capture = cvCreateFileCapture( name );
if (!capture )
{
printf( "Unable to read input video." );
return 0;
}
double fps = cvGetCaptureProperty( capture,CV_CAP_PROP_FPS);
printf( "fps %f ",fps );
int codec = cvGetCaptureProperty( capture,CV_CAP_PROP_FOURCC);
printf( "codec %d ",codec );
// Read frame
IplImage* frame = cvQueryFrame( capture );
// INIT the video writer
CvVideoWriter *writer = cvCreateVideoWriter( "x7.avi", codec, fps, cvGetSize(frame),1);
while(1)
{
cvWriteFrame( writer, frame );
cvShowImage( "Read the video", frame );
// READ next frame
frame = cvQueryFrame( capture );
if( !frame )
break;
char c = cvWaitKey(33);
if( c == 27 )
break;
}
// CLEAN everything
cvReleaseImage( &frame );
cvReleaseCapture( &capture );
cvReleaseVideoWriter( &writer );
cvDestroyWindow( "Read the video" );
return 0;}
}
推荐答案
我找出了问题、、、、、以YUV240像素格式(为灰色)编写的原始视频
I figure out the problem ,,,,, The original videos written in YUV240 pixel format (and it is gray)
默认情况下,openCV在BGR上读取视频,因此每次我读取openCV时,openCV都会将像素值转换为BGR
the openCV read the video on BGR by default , so each time when I read it the openCV convert the pixel values to BGR
经过几次读写后,错误开始更大(因为转换操作)那为什么像素值会改变.....我看到视频是粉红色的!
after few time of reading and writing , the error start to be bigger (because the conversion operation) that why the pixels values change .....and I see the video pink !
解决方案是通过FFMPEG项目读取和编写此类视频,并提供YUV240和许多其他格式FFMPEG教程中有代码可以执行此操作
The Solution is , read and write this kind of videos by FFMPEG project which provide YUV240 and many other format there is a code can do this operation in the tutorial of FFMPEG
我希望这可以帮助遇到类似问题的其他人
I hope this can help the others who face similar problem
这篇关于使用openCV在MAC上读取/写入avi视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!