From c30a35a493a2c03805bce1bb37e8c015027387c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Thu, 18 Jul 2024 17:23:02 +0200 Subject: [PATCH] Fix assertion when rendering demo with updated ffmpeg library The `in_channel_count` and `out_channel_count` properties of the `SwrContext` were already deprecated and have been removed in the most recent ffmpeg library version, hence rendering demos was causing an assertion error when these properties were set. For newer ffmpeg versions, we now set the channel layout with the `in_chlayout` and `out_chlayout` properties instead of setting the number of channels. --- src/engine/client/video.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/engine/client/video.cpp b/src/engine/client/video.cpp index 5ec31936e..85d7cc9ee 100644 --- a/src/engine/client/video.cpp +++ b/src/engine/client/video.cpp @@ -826,7 +826,11 @@ bool CVideo::OpenAudio() } /* set options */ - dbg_assert(av_opt_set_int(m_AudioStream.m_vpSwrContexts[i], "in_channel_count", 2, 0) == 0, "invalid option"); +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 24, 100) + dbg_assert(av_opt_set_chlayout(m_AudioStream.m_vpSwrContexts[i], "in_chlayout", &pContext->ch_layout, 0) == 0, "invalid option"); +#else + dbg_assert(av_opt_set_int(m_AudioStream.m_vpSwrContexts[i], "in_channel_count", pContext->channels, 0) == 0, "invalid option"); +#endif if(av_opt_set_int(m_AudioStream.m_vpSwrContexts[i], "in_sample_rate", m_pSound->MixingRate(), 0) != 0) { log_error("videorecorder", "Could not set audio sample rate to %d", m_pSound->MixingRate()); @@ -834,7 +838,7 @@ bool CVideo::OpenAudio() } dbg_assert(av_opt_set_sample_fmt(m_AudioStream.m_vpSwrContexts[i], "in_sample_fmt", AV_SAMPLE_FMT_S16, 0) == 0, "invalid option"); #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 24, 100) - dbg_assert(av_opt_set_int(m_AudioStream.m_vpSwrContexts[i], "out_channel_count", pContext->ch_layout.nb_channels, 0) == 0, "invalid option"); + dbg_assert(av_opt_set_chlayout(m_AudioStream.m_vpSwrContexts[i], "out_chlayout", &pContext->ch_layout, 0) == 0, "invalid option"); #else dbg_assert(av_opt_set_int(m_AudioStream.m_vpSwrContexts[i], "out_channel_count", pContext->channels, 0) == 0, "invalid option"); #endif