From 06e2b31001f488e633defea0b293e83655ab230a Mon Sep 17 00:00:00 2001 From: pkv Date: Sun, 5 May 2024 19:09:33 +0200 Subject: [PATCH] obs-ffmpeg: Fix 7.1 ALAC encoding Commit [1] added ALAC & PCM support. But 7.1 ALAC encoding fails. This fixes the issue by assigning the correct 7.1 layout supported by FFmpeg ALAC encoder (7.1(wide)). [1] https://github.com/obsproject/obs-studio/commit/3ae98511d09f1ebaf5c9cc005a285efd1a26aeff Signed-off-by: pkv --- plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c b/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c index d65be4073..49ee82dae 100644 --- a/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c +++ b/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c @@ -271,12 +271,21 @@ static void *enc_create(obs_data_t *settings, obs_encoder_t *encoder, #else av_channel_layout_default(&enc->context->ch_layout, (int)audio_output_get_channels(audio)); + /* The avutil default channel layout for 5 channels is 5.0, which OBS + * does not support. Manually set 5 channels to 4.1. */ if (aoi->speakers == SPEAKERS_4POINT1) enc->context->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_4POINT1; + /* AAC, ALAC, & FLAC default to 3.0 for 3 channels instead of 2.1. + * Tell the encoder to deal with 2.1 as if it were 3.0. */ if (aoi->speakers == SPEAKERS_2POINT1) enc->context->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_SURROUND; + // ALAC supports 7.1 wide instead of regular 7.1. + if (aoi->speakers == SPEAKERS_7POINT1 && + astrcmpi(enc->type, "alac") == 0) + enc->context->ch_layout = + (AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK; #endif enc->context->sample_rate = audio_output_get_sample_rate(audio);