ffmpeginteropx / FFmpegInteropX

FFmpeg decoding library for Windows 10 UWP and WinUI 3 Apps
Apache License 2.0
212 stars 53 forks source link

Auto extend media duration if stream contains additional data #319

Closed lukasf closed 2 years ago

lukasf commented 2 years ago

Sometimes there are files where the duration is not detected correctly, or metadata contains wrong duration tag. Or a filter extends the duration of the file. If the MediaStreamSource delivers more samples than expected by MediaPlayer, then the MediaPlayer will fast forward through all samples until reaching EOF. This is a bit weird and usually not what you want.

This PR detects if a sample has a higher timestamp than expected, and extends the duration of the MediaStreamSource. Behavior seems fine from MediaPlayer, you see the progress bad change and playback continues without any noticeable gaps.

Current behavior is to first extend by 1 second, then by 2 (this time 0.5 seconds before reaching end), then, 3, 4, 5 and then always by 5. Not sure if this makes so much sense. Maybe we should just extend by 1 second all the time.

This is easy to test by reducing mediaDuration by factor 10 in InitFFmpegContext and then seek to near the end of the progress bar.

I have made this configurable, but enabed by default, because this is most probably what people expect. If the file is longer than expected, just continue playing.