SuRGeoNix/Flyleaf

Player.TogglePlayPause() doesn't restart from the pause point

Closed this issue · 14 comments

PlayPause() is working perfectly for videos, but when playing audio files (at least for .mp3 and .flac), it starts playing after the pause point - by around 1-3 secs.
Should I handle audio files differently? I've checked your sample audio player (Custom Winforms) but it's not clear what might be handled differently.
Thanks,
David

Can't see the issue, I'm afraid you are doing something wrong. Can you provide your code? Maybe you should try use Player.TogglePlayPause() if you use multiple threads)

@davsun55 I cannot see your code (where did you attached it?) Can you clarify that those files are playing properly with the sample/demo app from releases?

FlyleafDemo.zip
Apologies - I replied to the last msg via email rather than in this webpage so ZIP didn't work.
The files all play perfectly in Windows. Most play properly in your FlyleafPlayer (Custom) (Winforms) sample but there's no snapshot being taken there.
AVI still has delayed audio; FLAC still fastforwards the 'CurTime' on startup - although the actual audio playback is perfect; OGG has perfect audio (not delayed as in my demo).
If I add a play/pause button to your sample, same deal with skipping audio on restart in eg FLAC. The button only has flyleaf1.Player.TogglePlayPause();
Thanks

@davsun55 Now I see them, haven't test audio only much to be honest, I need to review this and I will come back soon..

Also i knew there are some weird audio formats such as pcm/flac/ogg that could create some issues

@davsun55 Please re-test when you can with the latest fixes and let me know if you still have issues

Thanks - much better, with these issues remaining:
AVI: Audio starts playing ~1 sec after the video
FLAC: Perfect
MOV: Audio has a very minor delay at the start (snapshot works now)
OGG: Still starts at position where snapshot was attempted (restart is perfect)
WMA: Perfect first time after open; However Pause; Seek(0) or SeekAccurate(0) does not reposition to the very start

BTW TogglePlayPause() works perfectly on all the audio streams

@davsun55 My mistake I thought it was enabled by default, use this:-

flConfig.Audio.FiltersEnabled = true;

This should fix both AVI/MOV

OGG: is not a video, the seek fails so you get e == -1 and it will never seek(0)
WMA: the problem is that it does not have a timestamp, initially it knows that probably is the 0 timestamp but after seek it cannot be sure.

Perfect - thanks.
For any file that doesn't have a timestamp, could 'SeekAccurate(0)' have an override that always sets to the first frame rather than via a timestamp?
BTW when do you think you might do a new release that incorporates these fixes?
Regards

BTW, what does flConfig.Audio.FiltersEnabled = true; do? It fixed my issues!

People, were asking to support mainly Speed for audio that you can actually understand what they say. So, in v3.7.3 I've started to support FFmpeg audio filters but I had my doubts for both performance but mainly for timestamps. More or less the abuffersrc / abuffersink does not work properly with timestamps but with some workarounds now it became stable enough.

If you want to try some filters you can check those https://github.com/SuRGeoNix/Flyleaf/blob/master/Samples/FlyleafPlayer%20(WPF%20Control)%20(WPF)/MainWindow.xaml.cs#L102 for speed it will use atempo behind the scenes. For video, it is not clear from FFmpeg when it will download the frame from GPU to RAM and then re-upload it and I didn't want to lose the performance so I add the required/main filters directly in the renderer (eg. HFlip/VFlip lately).

Generally, you can check my demo with all the settings/configuration and mess around (eg enable/disable audio filters to see the difference eg. for Speed)

And for your issues, FiltersEnabled works because the simple approach with swr_convert does not currenly use min/max samples per frame and the AVI that you provide it was more than 1 second for each frame, which is really bad encoding. That's why the delays. Audio filters will split this single frame to multiple of 20-50ms frames.

I would use Filters for playing normal files / movies / youtube etc. to support also proper audio with speed and I would disable them for Cameras / Live streams as it is more important to focus on accurate AV sync as it can have a lot of gaps. This is probably not true anymore, I have not done much testing. I think audio with filters will work better in most cases and I might need to turn it on by default.

To go in the beginning of the file use Seek(0) which will be handled differently than normal Seek (not need to SeekAccurate) it will Seek at the exact first timestamp of the demuxer, however when no timestamps are provided you cannot guess, it is a bad encoding.

PS: I will do some testing and later today I will have a new release

@davsun55 NuGet is ready, I've fixed also the WMA