Question

I can only save 1 frame of a video with my current code. but I need to save the video for a longer period of time. Can some one help me with this?

 public void ProcessFrame(object sender, EventArgs e)
    {
           frame = _capture.QueryFrame();
           imageBox1.Image = frame;
           VideoW = new VideoWriter(@"temp.avi", 
                                   CvInvoke.CV_FOURCC('M', 'P', '4', '2'), 
                                   (Convert.ToInt32(upDownFPS.Value)), 
                                   frame.Width, 
                                   frame.Height, 
                                   true);
           VideoW.WriteFrame(frame);
    }
Was it helpful?

Solution

There is a problem with your code as far as I can see, that is process frame is attached to the application.idle event.

So when ever the application is idle this function is called and a frame is grabbed from the video source.

Now if we consider your ProcessFrame Function ,it just reinitializes the VideoWriter and writes a frame(current frame) in the video and that is why you only get a single frame in the output video.

So ideally your ProcessFrame should look something like this

public void ProcessFrame(object sender, EventArgs e)
    {
           frame = _capture.QueryFrame();
           imageBox1.Image = frame;

           VideoW.WriteFrame(frame);
    }

and the initialization of the VideoW variable ie, this underlying code.

VideoW = new VideoWriter(@"temp.avi", 
                                   CvInvoke.CV_FOURCC('M', 'P', '4', '2'), 
                                   (Convert.ToInt32(upDownFPS.Value)), 
                                   frame.Width, 
                                   frame.Height, 
                                   true); 

It should be placed outside ideally in the constructor or where you have initilized other variables(_capture variables etc.)

check this tutorial for more about reading and writing video files in Emgucv.

Hoping this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top