Page 1 of 1

Displaying the frame at a given time

Posted: 07 Oct 2020 07:26
by Nico6687
Hello,

I'm using libLVCSharp.WinForms and trying to display the frame corresponding to a time in the video.
Basically, if I have a time in ms, how do I display the corresponding frame in my VideoView control?

From what I understand, the video must be playing or paused, so I'm doing the following:

mediaPlayer.Play();
[Edit] <- I realized that at this point I basically need to wait until the video is actually playing

mediaPlayer.SetPause(true);
mediaPlayer.Time = 500;

Sometimes it works, sometimes it does not, and I have the feeling that I'm missing a step or precondition?

[Edit] I still have a couple of issues:
1) if I do the above, I can see the beginning of the video for a fraction of second in the VideoView control before it switches to the right frame. How can I avoid this?
2) if I pass the media.Duration for the time in order to display the last frame, it will not work (same thing if I set mediaPlayer.Position to 1.0f instead)
I assume that it is because it is actually after the time at which the last frame is starting to be displayed? How do I get that time? Will calculating that time from the duration and the fps rate be accurate enough?


Any help/ pointers would be greatly appreciated.

Re: Displaying the frame at a given time

Posted: 07 Oct 2020 17:39
by Rémi Denis-Courmont
First, not all formats and files support accurate seeking.

And even then, VLC normally starts to render only from a keyframe.

Re: Displaying the frame at a given time

Posted: 09 Oct 2020 15:17
by Nico6687
Hi Rémi, thank you for the reply.

My code indeed ensures that the video is seekable by first checking mediaPlayer.IsSeekable.

Can you give me a bit more details about what you mean by "starts render only from a keyframe"? What function should I call to jump to specific keyframe? I tried to set both the Time and Position properties without success. For example if I set mediaPlayer.Time to media.Duration (or mediaPlayer.Position to 1.0) to jump to / display the last frame, it does not work. Smaller values will work but not reach the end of the video.

Thank you.