From 824350b6e66ce7ef8a5449b60ce1abb2e4f462a5 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 21 Apr 2026 22:26:25 +0200 Subject: Fix bug causing mangled audio analyses in some cases (#3155). The duplicate ID detection was broken due to using the video stream index rather than its ID for checks. --- run/tests | 2 +- src/lib/ffmpeg_examiner.cc | 2 +- test/audio_analysis_test.cc | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/run/tests b/run/tests index 40bbdcdf0..839dc8dd4 100755 --- a/run/tests +++ b/run/tests @@ -3,7 +3,7 @@ # e.g. --run_tests=foo set -e -PRIVATE_GIT="d64f166137a3f2ee5c950f112e48e52fd982f781" +PRIVATE_GIT="7cbcb10afc73ab559ae9b907881881892aa6d57f" DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" source $DIR/environment diff --git a/src/lib/ffmpeg_examiner.cc b/src/lib/ffmpeg_examiner.cc index 6b60f6de3..48b354394 100644 --- a/src/lib/ffmpeg_examiner.cc +++ b/src/lib/ffmpeg_examiner.cc @@ -221,7 +221,7 @@ FFmpegExaminer::check_for_duplicate_ids() std::set stream_ids; if (_video_stream) { - stream_ids.insert(*_video_stream); + stream_ids.insert(_format_context->streams[*_video_stream]->id); } for (auto stream: _audio_streams) { diff --git a/test/audio_analysis_test.cc b/test/audio_analysis_test.cc index 8e04945ac..578250b2c 100644 --- a/test/audio_analysis_test.cc +++ b/test/audio_analysis_test.cc @@ -40,6 +40,7 @@ #include "lib/playlist.h" #include "lib/ratio.h" #include "test.h" +#include #include #include @@ -315,3 +316,38 @@ BOOST_AUTO_TEST_CASE(ebur128_test) } #endif + +static bool saw_ffmpeg_error = false; + +static +void +test_log_callback(void*, int level, const char*, va_list) +{ + if (level <= AV_LOG_WARNING) { + saw_ffmpeg_error = true; + } +} + + +/* The file in this test has the audio stream as index 0, video as 1, + * with both streams having the same ID. This triggered a bug where + * on analysis (with video disabled) the video packets would be fed + * to the audio decoder, causing chaos manifesting as many audio decoder + * errors. + */ +BOOST_AUTO_TEST_CASE(analysis_stream_confusion_test) +{ + auto sound = content_factory(TestPaths::private_data() / "ge.mkv")[0]; + auto film = new_test_film("analysis_stream_confusion_test", { sound }); + + av_log_set_callback(test_log_callback); + dcp::ScopeGuard sg = []() { + capture_ffmpeg_logs(); + }; + + auto job = make_shared(film, film->playlist(), true); + JobManager::instance()->add(job); + BOOST_REQUIRE(!wait_for_jobs()); + + BOOST_CHECK(!saw_ffmpeg_error); +} -- cgit v1.2.3