From 4503a8da2098ccbbcc367ce2e80693f506de33d2 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Thu, 14 Oct 2021 19:54:08 -0700 Subject: [PATCH] rebroadcast: audio transcode fix --- plugins/prebuffer-mixin/package-lock.json | 4 +-- plugins/prebuffer-mixin/package.json | 2 +- plugins/prebuffer-mixin/src/main.ts | 36 +++++++++++++++-------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/plugins/prebuffer-mixin/package-lock.json b/plugins/prebuffer-mixin/package-lock.json index 194d9af73..fb9b12f17 100644 --- a/plugins/prebuffer-mixin/package-lock.json +++ b/plugins/prebuffer-mixin/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/prebuffer-mixin", - "version": "0.1.63", + "version": "0.1.68", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/prebuffer-mixin", - "version": "0.1.63", + "version": "0.1.68", "license": "Apache-2.0", "dependencies": { "@scrypted/common": "file:../../common", diff --git a/plugins/prebuffer-mixin/package.json b/plugins/prebuffer-mixin/package.json index 1ec4660c2..b4e9c6afa 100644 --- a/plugins/prebuffer-mixin/package.json +++ b/plugins/prebuffer-mixin/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/prebuffer-mixin", - "version": "0.1.63", + "version": "0.1.68", "description": "Rebroadcast and Prebuffer for VideoCameras.", "author": "Scrypted", "license": "Apache-2.0", diff --git a/plugins/prebuffer-mixin/src/main.ts b/plugins/prebuffer-mixin/src/main.ts index 0b50a868c..52b7cff7a 100644 --- a/plugins/prebuffer-mixin/src/main.ts +++ b/plugins/prebuffer-mixin/src/main.ts @@ -118,6 +118,7 @@ class PrebufferSession { ], }, { + key: 'detectedResolution', group, title: 'Detected Resolution and Bitrate', readonly: true, @@ -125,6 +126,7 @@ class PrebufferSession { description: 'Configuring your camera to 1920x1080 is recommended.', }, { + key: 'detectedCodec', group, title: 'Detected Video/Audio Codecs', readonly: true, @@ -132,6 +134,7 @@ class PrebufferSession { description: 'Configuring your camera to H264 video (2000Kb/s) and AAC/MP3/MP2 audio is recommended.' }, { + key: 'detectedKeyframe', group, title: 'Detected Keyframe Interval', description: "Configuring your camera to 4 seconds is recommended (IDR = FPS * 4 seconds).", @@ -169,7 +172,11 @@ class PrebufferSession { } else if (reencodeAudio) { // setting no audio codec will allow ffmpeg to do an implicit conversion. - acodec = []; + acodec = [ + '-bsf:a', 'aac_adtstoasc', + '-acodec', 'libfdk_aac', + '-profile:a', 'aac_low' + ]; } else { // NOTE: if there is no audio track, this will still work fine. @@ -349,8 +356,13 @@ class PrebufferSession { const { audioConfig, pcmAudio, reencodeAudio } = this.getAudioConfig(); if (reencodeAudio) { - // could be anything... as we let the defaults decide. fix this to hardcode aac maybe. mediaStreamOptions.audio = { + codec: 'aac', + } + } + else { + mediaStreamOptions.audio = { + codec: session?.inputAudioCodec, } } @@ -376,7 +388,7 @@ class PrebufferSession { ) } - this.console.log('prebuffer ffmpeg input', ffmpegInput.inputArguments); + this.console.log('prebuffer ffmpeg input', ffmpegInput); const mo = mediaManager.createFFmpegMediaObject(ffmpegInput); return mo; } @@ -445,27 +457,19 @@ class PrebufferMixin extends SettingsMixinDeviceBase implements Vid const msos = await this.mixinDevice.getVideoStreamOptions(); const enabledStreams = this.getEnabledMediaStreamOptions(msos); - if (enabledStreams) { + if (enabledStreams && msos?.length > 1) { settings.push( { title: 'Prebuffered Streams', description: 'The streams to prebuffer. Enable only as necessary to reduce traffic.', key: 'enabledStreams', - value: enabledStreams.map(mso => mso.name), + value: enabledStreams.map(mso => mso.name || ''), choices: msos.map(mso => mso.name), multiple: true, }, ) } - for (const id of this.sessions.keys()) { - // ignore the default key entry, which will resolve to something else. - if (id == null) - continue; - const session = this.sessions.get(id); - settings.push(...await session.getMixinSettings()); - } - settings.push( { title: 'Prebuffer Duration', @@ -482,6 +486,12 @@ class PrebufferMixin extends SettingsMixinDeviceBase implements Vid value: (this.storage.getItem(SEND_KEYFRAME) !== 'false').toString(), }, ); + + + for (const session of new Set([...this.sessions.values()])) { + settings.push(...await session.getMixinSettings()); + } + return settings; }