0
votes

I am using a webcam to show live stream, capture images, record video etc using AForge library.

Each time I get a new frame, I assign it to a picture Box to show the live stream and i have added a tool strip for recording video when it is checked. so i did it in the same following method.

private void video_NewFrame( object sender, NewFrameEventArgs eventArgs)
{
   // Assigning new frame to a picturebox
   pictureBox1.Image = newFrame;

    if(recordVideo.Checked)
    {
       writer.AddFrame(newFrame);
    }
}

when the record Video tool strip is checked. I open the avi file.

writer.Open("test.avi", pictureBox1.Width, pictureBox1.Height);

and when it is unchecked i close the file.

writer.Close();

but when i start recording the video i get the following error:

Invalid Operation Exception - object is currently in use elsewhere.

1
Have you close the writer after you opening it? - redIntent
which call exactly (which line in source code) throws the exception? - DrKoch
Yes. I close the file when i uncheck the start recording toolstrip. - RizwanHaider
@DrKoch when it comes to write a Frame (Add frame) it throws this error. - RizwanHaider

1 Answers

0
votes

Just use it like this

pictureBox1.Image = newFrame.Clone() as Bitmap;