Displaying the frame at a given time

This forum is about all development around libVLC.
Nico6687
New Cone
New Cone
Posts: 5
Joined: 19 Sep 2020 08:25

Displaying the frame at a given time

Postby Nico6687 » 07 Oct 2020 07:26

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.

Rémi Denis-Courmont
Developer
Developer
Posts: 15266
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: Displaying the frame at a given time

Postby Rémi Denis-Courmont » 07 Oct 2020 17:39

First, not all formats and files support accurate seeking.

And even then, VLC normally starts to render only from a keyframe.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

Nico6687
New Cone
New Cone
Posts: 5
Joined: 19 Sep 2020 08:25

Re: Displaying the frame at a given time

Postby Nico6687 » 09 Oct 2020 15:17

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.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 14 guests