Pregunta

I'm trying to develop a simple application where I load a video file, and then to display it on my screen frame by frame.

To load the video file I use this code:

FileVideoSource fileVideo = new FileVideoSource(myVideoSource);
fileVideo.NewFrame += fileVideo_NewFrame;
fileVideo.Start();

And then, at the fileVideo_NewFrame, I capture each frame like this:

 if (SynchronizationContext.Current != uiContext)
 {
        uiContext.Post(delegate { fileVideo_NewFrame(sender, eventArgs);}, null);
        return;
 }

 Bitmap bitmap = eventArgs.Frame;
 PictureBoxvideo.Image = new Bitmap(bitmap);

 bitmap.Dispose();

But I'm receiving System.ArgumentException (so excplicit...). If I stop debugging on the fileVideo I can see this:

enter image description here

The Bitmap seems to not have filled the values.

Any idea on why the video it's not loading fine?

Thanks for help!

¿Fue útil?

Solución

I could solve it with the solution posted here.

FileVideoSource fileVideo = new FileVideoSource(dialog.FileName);
AsyncVideoSource asyncVideoSource = new AsyncVideoSource(fileVideo);
asyncVideoSource.NewFrame += asyncVideoSource_NewFrame;
asyncVideoSource.Start();

private void asyncVideoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
    Image temp = PictureBoxvideo.Image;
    Bitmap bitmap = eventArgs.Frame;
    PictureBoxvideo.Image = new Bitmap(bitmap);
    if (temp!= null) temp.Dispose();
    bitmap.Dispose();
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top