From 92caea08afbdccaa1242fcf1931ec5afad266259 Mon Sep 17 00:00:00 2001 From: gnattu Date: Wed, 11 Dec 2024 14:50:57 +0800 Subject: [PATCH 1/2] Prevent opus more than 2 channels being remux on Safari Safari only supports stereo Opus, which requires a similar workaround as we are applying on WebOS for FLAC. --- src/scripts/browserDeviceProfile.js | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/scripts/browserDeviceProfile.js b/src/scripts/browserDeviceProfile.js index 755e6e70e75..e92cec7b813 100644 --- a/src/scripts/browserDeviceProfile.js +++ b/src/scripts/browserDeviceProfile.js @@ -1028,6 +1028,49 @@ export default function (options) { profile.TranscodingProfiles.push(...flacTranscodingProfiles); } + if (safariSupportsOpus) { + const opusConditions = [ + // Safari doesn't support opus with more than 2 channels + { + Condition: 'LessThanEqual', + Property: 'AudioChannels', + Value: '2', + IsRequired: false + } + ]; + + profile.CodecProfiles.push({ + Type: 'VideoAudio', + Codec: 'opus', + Conditions: opusConditions + }); + + const opusTranscodingProfiles = []; + + // Split each video transcoding profile with opus so that the containing opus is only applied to 2 channels audio + profile.TranscodingProfiles.forEach(transcodingProfile => { + if (transcodingProfile.Type !== 'Video') return; + + const audioCodecs = transcodingProfile.AudioCodec.split(','); + + if (!audioCodecs.includes('opus')) return; + + const opusTranscodingProfile = { ...transcodingProfile }; + opusTranscodingProfile.AudioCodec = 'opus'; + opusTranscodingProfile.MaxAudioChannels = '2'; + opusTranscodingProfile.ApplyConditions = [ + ...opusTranscodingProfile.ApplyConditions || [], + ...opusConditions + ]; + + opusTranscodingProfiles.push(opusTranscodingProfile); + + transcodingProfile.AudioCodec = audioCodecs.filter(codec => codec != 'opus').join(','); + }); + + profile.TranscodingProfiles.push(...opusTranscodingProfiles); + } + let maxH264Level = 42; let h264Profiles = 'high|main|baseline|constrained baseline'; From 8f7974d5c6d71b36c293332b44a6b5dd1ac5e0b6 Mon Sep 17 00:00:00 2001 From: gnattu Date: Sun, 22 Dec 2024 01:58:56 +0800 Subject: [PATCH 2/2] Remove redundant channel limit --- src/scripts/browserDeviceProfile.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/scripts/browserDeviceProfile.js b/src/scripts/browserDeviceProfile.js index e92cec7b813..8c6cd686d3f 100644 --- a/src/scripts/browserDeviceProfile.js +++ b/src/scripts/browserDeviceProfile.js @@ -1057,7 +1057,6 @@ export default function (options) { const opusTranscodingProfile = { ...transcodingProfile }; opusTranscodingProfile.AudioCodec = 'opus'; - opusTranscodingProfile.MaxAudioChannels = '2'; opusTranscodingProfile.ApplyConditions = [ ...opusTranscodingProfile.ApplyConditions || [], ...opusConditions