Skip to content

Commit

Permalink
feat(avplayer): 支持处理 mp4 的旋转元数据
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaohappy committed Nov 19, 2024
1 parent bf11b51 commit 267b019
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/avplayer/AVPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1695,9 +1695,11 @@ export default class AVPlayer extends Emitter implements ControllerObserver {
)
? this.canvas.transferControlToOffscreen()
: this.canvas
const stream = this.formatContext.streams.find((stream) => {
return stream.codecpar.codecType === AVMediaType.AVMEDIA_TYPE_VIDEO
})

// 处理旋转
if (videoStream.metadata['matrix']) {
this.renderRotate = -(Math.atan2(videoStream.metadata['matrix'][3], videoStream.metadata['matrix'][0]) * (180 / Math.PI))
}

// 注册一个视频渲染任务
await this.VideoRenderThread.registerTask
Expand All @@ -1716,15 +1718,15 @@ export default class AVPlayer extends Emitter implements ControllerObserver {
flipHorizontal: this.flipHorizontal,
flipVertical: this.flipVertical,
timeBase: {
num: stream.timeBase.num,
den: stream.timeBase.den,
num: videoStream.timeBase.num,
den: videoStream.timeBase.den,
},
viewportWidth: this.options.container.offsetWidth,
viewportHeight: this.options.container.offsetHeight,
devicePixelRatio: devicePixelRatio,
stats: addressof(this.GlobalData.stats),
enableWebGPU: this.options.enableWebGPU,
startPTS: stream.startTime,
startPTS: videoStream.startTime,
avframeList: addressof(this.GlobalData.avframeList),
avframeListMutex: addressof(this.GlobalData.avframeListMutex),
enableJitterBuffer: !!this.jitterBufferController && !this.audioDecoder2AudioRenderChannel
Expand All @@ -1735,13 +1737,9 @@ export default class AVPlayer extends Emitter implements ControllerObserver {
}
if (this.audioDecoder2AudioRenderChannel) {

const stream = this.formatContext.streams.find((stream) => {
return stream.codecpar.codecType === AVMediaType.AVMEDIA_TYPE_AUDIO
})

this.audioRender2AudioWorkletChannel = new MessageChannel()

this.playChannels = Math.max(stream.codecpar.chLayout.nbChannels, Math.min(AVPlayer.audioContext.destination.channelCount, 2))
this.playChannels = Math.max(audioStream.codecpar.chLayout.nbChannels, Math.min(AVPlayer.audioContext.destination.channelCount, 2))

let resamplerResource = await this.getResource('resampler')
let stretchpitcherResource = await this.getResource('stretchpitcher')
Expand Down Expand Up @@ -1772,10 +1770,10 @@ export default class AVPlayer extends Emitter implements ControllerObserver {
stretchpitcherResource,
stats: addressof(this.GlobalData.stats),
timeBase: {
num: stream.timeBase.num,
den: stream.timeBase.den,
num: audioStream.timeBase.num,
den: audioStream.timeBase.den,
},
startPTS: stream.startTime,
startPTS: audioStream.startTime,
avframeList: addressof(this.GlobalData.avframeList),
avframeListMutex: addressof(this.GlobalData.avframeListMutex),
enableJitterBuffer: !!this.jitterBufferController
Expand Down

0 comments on commit 267b019

Please sign in to comment.