3

I am trying to record a video captured from a webcam using Emgu CV but I a, getting an exception.

_capture = new Capture(0);
_capture.QueryFrame();
captureOutput = new VideoWriter(@"output.avi",
                                (int)_capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FOURCC),
                                (int)_capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FPS),
                                (int)_capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH),
                                (int)_capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT),
                                true);
Image<Bgr, Byte> frame = _capture.QueryFrame();
captureOutput.WriteFrame(frame);

I am getting an "Attempted to divide by zero." exception when I am executing captureOutput.WriteFrame(frame) line.

4

1 回答 1

1

引用评论:

问题在于选择正确的编解码器进行录制。我更改了下面第 3 行的一部分:

_capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FOURCC)与-1。

这为我提供了一个对话框,其中包含我机器上可用的编解码器列表。我选择了“未压缩”编解码器,视频已正确生成。

于 2014-04-30T16:02:13.310 回答