Skip to content

Commit

Permalink
fix: hls播放mp2音画不同步
Browse files Browse the repository at this point in the history
  • Loading branch information
wudechang authored and gemxx committed Dec 18, 2024
1 parent 0655c9d commit afd1991
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/xgplayer-transmuxer/src/mpeg-ts/fixer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AudioSample, WarningType } from '../model'
import { AAC } from '../codec'
import { isSafari } from '../utils'
import { AudioCodecType } from '../model/types'

const LARGE_AV_FIRST_FRAME_GAP = 90000 / 2 // 500ms
const AUDIO_GAP_OVERLAP_THRESHOLD_COUNT = 3
Expand Down Expand Up @@ -230,6 +231,23 @@ export class TsFixer {
const samples = audioTrack.samples

if (!samples.length) return
if (audioTrack.codecType === AudioCodecType.MP3) {
if (this.lastAudioSample) {
samples.unshift(this.lastAudioSample)
}
for (let index = 0; index < samples.length; index++) {
const x = samples[index]
if (samples[index + 1]) {
x.duration = samples[index + 1].pts - x.pts
} else {
break
}
x.pts -= this._baseDts
x.dts = x.pts
}
this.lastAudioSample = samples.pop()
return
}
samples.forEach(x => {
x.pts -= this._needForceFixLargeGap ? this._baseAudioDts : this._baseDts
x.dts = x.pts
Expand Down

0 comments on commit afd1991

Please sign in to comment.