Skip to content

Commit

Permalink
fix: last GOP dont have audio track (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyuhen authored Apr 1, 2019
1 parent ac64d8a commit 67d37bb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
6 changes: 6 additions & 0 deletions example/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ module.exports = env => {
changeOrigin: true,
secure: false,
},
'/vzuu': {
target: 'https://vdn1.vzuu.com/',
pathRewrite: {'^/vzuu': ''},
changeOrigin: true,
secure: false,
},
},
},

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
],
"scripts": {
"format": "prettier \"packages/**/*.{js,json,md}\" \"*.{js,json,md}\"",
"format:fix": "prettier --write \"packages/**/*.{js,json,md}\" \"*.{js,json,md}\"",
"lint": "eslint 'packages/*/src/**/*.js' '*.js'",
"test": "jest",
"test:coverage": "jest --coverage",
Expand Down
6 changes: 6 additions & 0 deletions packages/griffith-mp4/src/mp4/utils/getBufferStart.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,11 @@ function getChunkSize(mp4BoxTree, offsetStart, type) {
type === 'video' ? 'videoStco' : 'audioStco'
)

// 如果最后一个 GOP 没有音频轨,BufferStart 需要按照视频轨来计算。
// If the last GOP dont have audio track, we should ignore the audio chunk size.
if (chunkIndex >= stcoBox.samples.length) {
return Number.MAX_SAFE_INTEGER
}

return stcoBox.samples[chunkIndex].chunkOffset + sampleSize
}
11 changes: 9 additions & 2 deletions packages/griffith-mp4/src/mp4/utils/getFragmentPosition.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ export default function getFragmentPosition(
) {
const videoSamplesEnd = videoSamples[videoSamples.length - 1].end
const videoSamplesStart = videoSamples[0].start
const audioSamplesEnd = audioSamples[audioSamples.length - 1].end
const audioSamplesStart = audioSamples[0].start

// maybe the last GOP dont have audio track
// 最后一个 GOP 序列可能没有音频轨
let audioSamplesEnd = 0
let audioSamplesStart = Number.MAX_SAFE_INTEGER
if (audioSamples.length !== 0) {
audioSamplesEnd = audioSamples[audioSamples.length - 1].end
audioSamplesStart = audioSamples[0].start
}

const fragmentEndPosition = isLastFragmentPosition
? ''
Expand Down
15 changes: 10 additions & 5 deletions packages/griffith-mp4/src/mse/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,18 @@ export default class MSE {
FMP4.mdat(videoTrackInfo)
)

const audioRawData = concatTypedArray(
FMP4.moof(audioTrackInfo, audioBaseMediaDecodeTime),
FMP4.mdat(audioTrackInfo)
)
// maybe the last GOP dont have audio track
// 最后一个 GOP 序列可能没有音频轨
if (audioTrackInfo.samples.length !== 0) {
const audioRawData = concatTypedArray(
FMP4.moof(audioTrackInfo, audioBaseMediaDecodeTime),
FMP4.mdat(audioTrackInfo)
)
this.sourceBuffers.audio.appendBuffer(audioRawData)
}

this.sourceBuffers.video.appendBuffer(videoRawData)
this.sourceBuffers.audio.appendBuffer(audioRawData)

if (time) {
this.needUpdateTime = true
}
Expand Down

0 comments on commit 67d37bb

Please sign in to comment.