Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/remux/mp4-remuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class MP4Remuxer {
this._mp3UseMpegAudio = !Browser.firefox;

this._fillAudioTimestampGap = this._config.fixAudioTimestampGap;

this._deltaAudioTimestapGap = 0;
}

destroy() {
Expand Down Expand Up @@ -371,13 +373,15 @@ class MP4Remuxer {
let needFillSilentFrames = false;
let silentFrames = null;

this._deltaAudioTimestapGap += sampleDuration - refSampleDuration;
// Silent frame generation, if large timestamp gap detected && config.fixAudioTimestampGap
if (sampleDuration > refSampleDuration * 1.5 && this._audioMeta.codec !== 'mp3' && this._fillAudioTimestampGap && !Browser.safari) {
if (this._deltaAudioTimestapGap > refSampleDuration && this._audioMeta.codec !== 'mp3' && this._fillAudioTimestampGap && !Browser.safari) {
// We need to insert silent frames to fill timestamp gap
needFillSilentFrames = true;
let delta = Math.abs(sampleDuration - refSampleDuration);
let frameCount = Math.ceil(delta / refSampleDuration);
let frameCount = Math.floor(delta / refSampleDuration);
let currentDts = dts + refSampleDuration; // Notice: in float
this._deltaAudioTimestapGap = this._deltaAudioTimestapGap % refSampleDuration;

Log.w(this.TAG, 'Large audio timestamp gap detected, may cause AV sync to drift. ' +
'Silent frames will be generated to avoid unsync.\n' +
Expand Down Expand Up @@ -740,4 +744,4 @@ class MP4Remuxer {

}

export default MP4Remuxer;
export default MP4Remuxer;