Browse Source

obs-ffmpeg: Fix encoding of 2.1 with FFmpeg aac encoder

The aac spec has a list of default channel layouts that are implemented
by all aac encoders / decoders.
Unfortunately 2.1 is not in that list. When I wrote the surround sound
support into OBS, as a workaround I decided to encode 2.1 as
AV_CH_LAYOUT_SURROUND = FL+FR+FC.
The LFE channel is encoded as a regular audio channel which uses more
bits but this allows compatibility with all aac decoders.
Recently we updated to the new channel layout API of FFmpeg, but the
mapping of 2.1 to AV_CH_LAYOUT_SURROUND was forgotten in the FFmpeg
native aac encoder. This is remedied here.

Signed-off-by: pkv <[email protected]>
pkv 2 years ago
parent
commit
ad3df88fe3
1 changed files with 3 additions and 0 deletions
  1. 3 0
      plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c

+ 3 - 0
plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c

@@ -235,6 +235,9 @@ static void *enc_create(obs_data_t *settings, obs_encoder_t *encoder,
 	if (aoi->speakers == SPEAKERS_4POINT1)
 		enc->context->ch_layout =
 			(AVChannelLayout)AV_CHANNEL_LAYOUT_4POINT1;
+	if (aoi->speakers == SPEAKERS_2POINT1)
+		enc->context->ch_layout =
+			(AVChannelLayout)AV_CHANNEL_LAYOUT_SURROUND;
 #endif
 
 	enc->context->sample_rate = audio_output_get_sample_rate(audio);