From 3478640b4d1186ff7e5379ad03d23b8d75198ab4 Mon Sep 17 00:00:00 2001
From: Taylor Richards <taylor@icculus.org>
Date: Sun, 7 Apr 2024 18:43:15 -0400
Subject: [PATCH] fix deprecated/removed code in cutscene ffmpeg (#6088)

---
 code/cutscene/ffmpeg/AudioDecoder.cpp  | 2 +-
 code/cutscene/ffmpeg/FFMPEGDecoder.cpp | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/code/cutscene/ffmpeg/AudioDecoder.cpp b/code/cutscene/ffmpeg/AudioDecoder.cpp
index 37b67667607..377d3202068 100644
--- a/code/cutscene/ffmpeg/AudioDecoder.cpp
+++ b/code/cutscene/ffmpeg/AudioDecoder.cpp
@@ -6,7 +6,7 @@ namespace {
 const int OUT_CH_LAYOUT = AV_CH_LAYOUT_STEREO;
 const int OUT_SAMPLE_RATE = 48000;
 const AVSampleFormat OUT_SAMPLE_FORMAT = AV_SAMPLE_FMT_S16;
-const int OUT_NUM_CHANNELS = av_get_channel_layout_nb_channels(OUT_CH_LAYOUT);
+const int OUT_NUM_CHANNELS = av_popcount64(OUT_CH_LAYOUT);
 
 const int DEFAULT_SRC_NUM_SAMPLES = 1024;
 
diff --git a/code/cutscene/ffmpeg/FFMPEGDecoder.cpp b/code/cutscene/ffmpeg/FFMPEGDecoder.cpp
index 33664fc7fc8..6c3a2af6309 100644
--- a/code/cutscene/ffmpeg/FFMPEGDecoder.cpp
+++ b/code/cutscene/ffmpeg/FFMPEGDecoder.cpp
@@ -69,7 +69,11 @@ CodecContextParameters getCodecParameters(AVStream* stream) {
 	paras.height       = stream->codecpar->height;
 	paras.pixel_format = (AVPixelFormat)stream->codecpar->format;
 
-	paras.channel_layout = stream->codecpar->channel_layout;
+	#if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(59, 36, 255)
+		paras.channel_layout = stream->codecpar->ch_layout.u.mask;
+	#else
+		paras.channel_layout = stream->codecpar->channel_layout;
+	#endif
 	paras.sample_rate    = stream->codecpar->sample_rate;
 	paras.audio_format   = (AVSampleFormat)stream->codecpar->format;
 

