简体   繁体   English

Fourcc与mac os X.

[英]Fourcc with mac os X

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. 与Windows 7相比,我的视频非常暗。我认为这是编解码器的问题。 What is the best codec that works on mac os x. 什么是适用于mac os x的最佳编解码器。 thanks 谢谢

As you said if you compared it to Windows, it's probably the codec problem. 如你所说,如果你将它与Windows进行比较,那可能就是编解码器问题。 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. 要使用的常见编解码器可能是使用CV_FOURCC('X', 'V', 'I', 'D') XVID CV_FOURCC('X', 'V', 'I', 'D')但不能保证你拥有它。

A good practice is to pass -1 instead of CV_FOURCC() macro in the cv::VideoWriter constructor for your first run. 一个好的做法是在第一次运行时在cv::VideoWriter构造函数中传递-1而不是CV_FOURCC()宏。 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. 如果您对其中一个感到满意,请找到该代码的4CC代码并在程序中对其进行硬编码。

Also you may want to try Perian to have access to more codecs in Mac OS. 您也可以尝试使用Perian访问Mac OS中的更多编解码器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM