Reputation: 1778
I need to write a video from a sequence of images. I am using this code:
int main()
{
//Read sequence of images
Size frameSize(1360,1024);
//cout<<path<<endl;
VideoCapture sequence("path/fr%1d.jpg");
if (!sequence.isOpened())
{
cerr << "Failed to open Image Sequence!\n" << endl;
return -1;
}
//Write video
VideoWriter oVideoWriter ("path/MyVideo.avi",CV_FOURCC('8','B','P','S'), 15
, frameSize);
Mat imageGrey;
if(!oVideoWriter.isOpened())
{
cout<<"ERROR: Failed to write the video"<<endl;
return -1;
}
Mat Image;
int i=0;
while(true)
{
sequence>>Image;
if(Image.empty())
break;
cout<<i<<endl;
Mat imageArr[] = {Image, Image, Image};
merge(imageArr, 3, imageGrey);
//cvtColor(Image,imageGrey,CV_GRAY2BGR);
oVideoWriter.write(imageGrey);
i++;
}
cout<<"video written!"<<endl;
return 1;
}
I get a very dark video compared with one in Windows 7. I think it a problem of codec. What is the best codec that works on mac os x. thanks
Upvotes: 0
Views: 1472
Reputation: 2512
As you said if you compared it to Windows, it's probably the codec problem. There is no best codec; some codecs are better for specific situations while worse for other cases. A common codec to use may be XVID using CV_FOURCC('X', 'V', 'I', 'D')
but there is no guarantee that you have it.
A good practice is to pass -1
instead of CV_FOURCC()
macro in the cv::VideoWriter
constructor for your first run. A window will pop up and you can see what types of codecs you have available to use. When you are happy with one of them, find the 4CC code of that code and hardcode it in your program.
Also you may want to try Perian to have access to more codecs in Mac OS.
Upvotes: 2