SuRGeoNix / Flyleaf

Media Player .NET Library for WinUI 3/ WPF/WinForms (based on FFmpeg/DirectX)
GNU Lesser General Public License v3.0
687 stars 92 forks source link

Open stream at current position #451

Closed spektor56 closed 3 months ago

spektor56 commented 3 months ago

Is there any way to open a stream at a predetermined position? Whenever I call Player.OpenAsync(stream) it resets the current position of the stream to the beginning. If i set the position of the stream and flush after i get the first half second of the beginning of the stream first.

SuRGeoNix commented 3 months ago

1) Set Config.Player.AutoPlay = false 2) You should either reset Config.Player.AutoPlay (on OpenCompleted) to true or Listen to Player.SeekCompleted and manually call Player.Play 3) Listen to Player.OpenCompleted event and perform a Player.Seek

spektor56 commented 3 months ago

unfortunately it still plays the first part of the stream even with "Config.Player.AutoPlay = false"

SuRGeoNix commented 3 months ago

I just retested to ensure AutoPlay=false works. Can you provide a log file?

spektor56 commented 3 months ago

Autoplay=false works, but when I set the position of the steam and then call play, the first half second of the beginning of the stream plays before it skips to the current stream position. I'm setting the position on the stream itself since it's a combination of raw hevc streams via ssh, so all I know is the length of the stream in bytes, not how long it is etc. Even with autoplay=false I'm assuming it's still buffering the data to play

SuRGeoNix commented 3 months ago

I'm not sure yet how you use it, but the proper way and build-in way to seek will flush the packet queue after the seek has been completed and it will decode until the first video frame to present it. Did you check the (trace) logs? Does the demuxer brings old packets after seek?

spektor56 commented 3 months ago

rewind

This is an example of what is happening, I added some log output you can see. I can't use the player seek because i dont know the time in ms that i need to jump to, I only know the percentage. Its a raw HEVC stream over SSH so there is no information about current position / length in ms

[16:46:54 DBG] Opening New Stream [16:46:54 DBG] Seeking to: 0% [16:46:54 DBG] Stream Opened [16:46:54 DBG] Seeking to: 63% [16:46:54 DBG] Position Set to: 63% [16:46:54 DBG] Calling Play [16:46:54 DBG] Buffering Started - Current Stream Position:63% [16:46:54 DBG] Buffering Complete - Current Stream Position:63% [16:46:55 DBG] Buffering Started - Current Stream Position:63% [16:46:55 DBG] Buffering Complete - Current Stream Position:63%

I am calling flush before i call play:

flyleafHost1.Player.Flush(); Serilog.Log.Debug("Calling Play"); flyleafHost1.Player.Play();