【问题标题】:Trying to write a video file using OpenCV尝试使用 OpenCV 编写视频文件
【发布时间】:2010-02-18 22:08:12
【问题描述】:

我正在尝试使用 OpenCV 编写视频文件。我有一个简单的程序,可以从视频文件中加载帧,然后接受保存

起初 cvCreateVideoWrite 总是返回 NULL。我从您的小组得到了答复,说它返回单独的图像并尝试将文件名更改为 test0001.png,这很有效。

但是现在cvWriteFrame函数总是失败,代码是

 CString path;
 path="d:\\mice\\Test_Day26_2.avi";

   CvCapture* capture = cvCaptureFromAVI(path);
   IplImage* img = 0;

 CvVideoWriter *writer = 0;
 int isColor = 1;
 int fps     = 25;  // or 30
 int frameW  = 640; // 744 for firewire cameras
 int frameH  = 480; // 480 for firewire cameras
 writer=cvCreateVideoWriter("d:\\mice\\test0001.png",CV_FOURCC('P','I','M','1'),
                           fps,cvSize(frameW,frameH),isColor);
 if (writer==0)
  MessageBox("could not open writter");

int nFrames = 50;
for(int i=0;i<nFrames;i++){
  if (!cvGrabFrame(capture))
   MessageBox("could not grab frame");
  img=cvRetrieveFrame(capture);  // retrieve the captured frame
  if (img==0)
   MessageBox("could not retrive data");
  if (!cvWriteFrame(writer,img) )
   MessageBox("could not write frame");
}
cvReleaseVideoWriter(&writer);

【问题讨论】:

  • 您得到什么异常或错误代码?你调试过img和writer的值了吗?他们是对的吗?
  • 我在 SOF 上有一个类似的问题here。响应和 cmets 可能会对您有所帮助。

标签: file opencv video file-io


【解决方案1】:

尝试CV_FOURCC('D', 'I', 'V', 'X')CV_FOURCC('f', 'f', 'd', 's')(带有*.avi 文件名)或CV_FOURCC_DEFAULT(带有*.mpg)。在opencv中写视频还是比较乱的>_>

【讨论】:

    【解决方案2】:

    我在 OpenCV 中也看到了很多关于编写视频的问题。我发现英特尔 iYUV 格式可以很好地满足我的需求。

    【讨论】:

      【解决方案3】:

      你的库是用HAVE_FFMPEG 定义的吗? 如果不是,您可能需要使用该选项重新编译 opencv。您应该在配置步骤中看到类似这样的内容:

      ...
      Video I/O--------------
      Use QuickTime      no
      Use xine           no
      Use ffmpeg:        yes
      Use v4l            yes
      ...
      

      如果你没有ffmpeg,你可以从here获取。

      【讨论】:

        猜你喜欢
        • 2011-06-19
        • 2015-03-10
        • 2015-08-11
        • 2011-07-22
        • 2023-04-09
        • 1970-01-01
        • 1970-01-01
        • 2016-11-18
        • 1970-01-01
        相关资源
        最近更新 更多