我需要根据一系列图像编写视频。我正在使用这段代码:
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;
}
与 Windows 7 中的视频相比,我得到一个非常暗的视频。我认为这是编解码器的问题。适用于 mac os x 的最佳编解码器是什么。谢谢
最佳答案
如您所说,如果您将其与Windows进行比较,则可能是编解码器问题。没有最好的编解码器;一些编解码器在特定情况下更好,而在其他情况下更差。常用的编解码器可能是使用 CV_FOURCC('X', 'V', 'I', 'D')
的 XVID,但不能保证您拥有它。
一个好的做法是在第一次运行时在 cv::VideoWriter
构造函数中传递 -1
而不是 CV_FOURCC()
宏。将弹出一个窗口,您可以看到可以使用的编解码器类型。当您对其中之一感到满意时,找到该代码的 4CC 代码并将其硬编码到您的程序中。
您也可以尝试 Perian在 Mac OS 中访问更多编解码器。
关于c++ - Fourcc 与 mac os X,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23281179/