bilibili / flv.js

HTML5 FLV Player
Apache License 2.0
22.9k stars 3.39k forks source link

A/V sync problem in unstable live streams #194

Open boczeratul opened 7 years ago

boczeratul commented 7 years ago

I've noticed serious A/V sync problem on unstable live streams 2017-08-17 11 27 20 silent frames are added to the samples with long duration but not removed from those with short duration. as a result, A/V gets out of sync very quickly is it possible to refactor the silent frame logic so it's added when there's accumulated timestamp difference? instead of comparing single sample?

FYI stash buffer is turned on no error is reported in chrome://media-internals

thanks in advance.

boczeratul commented 7 years ago

something like this https://github.com/Bilibili/flv.js/compare/master...boczeratul:av-sync

but the change breaks the video. there's probably something I'm missing and creates some inconsistency on time stamps. It's just to demonstrate the idea.

does it make sense? would like to hear your opinion on this 😄 thanks!

xqq commented 7 years ago

Audio frame sample duration should always be consistently equals to an value which is related to sampling rate.

refSampleDuration = 1024 / meta.audioSampleRate * meta.timescale;

If not, the browser will force adjust the presentation timestamp to make audio playback seamlessly, which may cause A/V unsync.

That is to say, the stream publisher should always follow the rule. The player can only do very little and limited workarounds with malformed streams.