Shivam
Shivam

Reputation: 144

Error writing video in Emgu Cv

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.

Upvotes: 3

Views: 5070

Answers (1)

Sebastian Schmitz
Sebastian Schmitz

Reputation: 1894

Cite from Comment:

The issue was with the selecting the proper codec to record. I changed part of line 3 below:

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

This provided me with a dialog box with the list of codec available on my machine. I selected "Uncompressed" codec and the video was properly generated.

Upvotes: 1

Related Questions