Home > Forum > MediaPlayer Capture Video frame

MediaPlayer Capture Video frame

Feb 27, 2018
Athisarn wrote
Dear Staff:

I tried to capture videoframe with .Frame_GetCurrent and shows it on PictureBox. It works just fine.
However, when I change the VDO position with .Position_Set_Time(New Time)
and capture the frame. It doesn't show the new frame, instead, it shows the previous frame.

Note: My intention is the make three PictureBox shows
Video frame (time - 500ms), Video frame (Current time), Video frame (time + 500ms).
The result is all three PictureBoxs show the same frame.

Reply
8 Answers
Feb 28, 2018
Roman Minyaylov agent wrote
Hi

You should copy frame before assign to PictureBox.
Feb 28, 2018
Athisarn wrote
Dear Roman:

I'm quite new. Please bear with me. How can I copy frame.
Do you mean, I copy the frame by using mediaPlayer1.Frame_CopyToClipboard();
and then, assign the image from the Clipboard to PictureBox?



Feb 28, 2018
Roman Minyaylov agent wrote
Frame_GetCurrent returns Bitmap, you can create Bitmap like usual in WinForms.

For example using constructor:

Bitmap A = mediaPlayer1.Frame_GetCurrent();
Bitmap B = new Bitmap(A);
Feb 28, 2018
Athisarn wrote
I still get the same result on both pictureBox1 & 2. However, if I delay 80ms. using timer, the result should be fine. However, it causing a delay in mediaPlayer1

Bitmap A = mediaPlayer1.Frame_GetCurrent();
Bitmap tmpA = new Bitmap(A);
pictureBox1.Image = tmpA;

mediaPlayer1.Position_Set_Time(mediaPlayer1.Position_Get_Time() + 350);
A = mediaPlayer1.Frame_GetCurrent();
Bitmap tmpB = new Bitmap(A);
pictureBox2.Image = tmpB;

Is there more things, I should do.
Feb 28, 2018
Athisarn wrote
Also, in the help ".Frame_GetCurrent()"
Under Remark: "Call Dispose for returned frame in your code." What do you mean by that?
Feb 28, 2018
Roman Minyaylov agent wrote
OK. Let me made small sample code for you.
Feb 28, 2018
Athisarn wrote
Thank you very much
Feb 28, 2018
Roman Minyaylov agent wrote
Ok. I've added 3 picture boxes on WinForms app (Main Demo used).

// flag to capture frame
private bool saveImageToPictureBox = false;

// button to move forward for 3 seconds and set capture frame flag
private void button1_Click(object sender, EventArgs e)
{
MediaPlayer1.Position_Set_Time(MediaPlayer1.Position_Get_Time() + 3000);
Thread.Sleep(250);

saveImageToPictureBox = true;
}

// added OnVideoFrameBitmap event implementation instead Frame_GetCurrent to capture new frame after seeking and assign it to empty PictureBox
private void MediaPlayer1_OnVideoFrameBitmap(object sender, VideoFrameBitmapEventArgs e)
{
if (saveImageToPictureBox)
{
saveImageToPictureBox = false;

if (pictureBox1.Image == null)
{
pictureBox1.Image = new Bitmap(e.Frame);
return;
}

if (pictureBox2.Image == null)
{
pictureBox2.Image = new Bitmap(e.Frame);
return;
}

if (pictureBox3.Image == null)
{
pictureBox3.Image = new Bitmap(e.Frame);
return;
}
}
}