From 267b0197b2b89ecd20fc7ce24ce7173ac2e98a01 Mon Sep 17 00:00:00 2001 From: zhaohappy <2281756061@qq.com> Date: Tue, 19 Nov 2024 21:47:55 +0800 Subject: [PATCH] =?UTF-8?q?feat(avplayer):=20=E6=94=AF=E6=8C=81=E5=A4=84?= =?UTF-8?q?=E7=90=86=20mp4=20=E7=9A=84=E6=97=8B=E8=BD=AC=E5=85=83=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/avplayer/AVPlayer.ts | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/avplayer/AVPlayer.ts b/src/avplayer/AVPlayer.ts index ef06a63..6af95f0 100644 --- a/src/avplayer/AVPlayer.ts +++ b/src/avplayer/AVPlayer.ts @@ -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 @@ -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 @@ -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') @@ -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