From 54fe46815728f73bbbd064d7076de1d9347827e3 Mon Sep 17 00:00:00 2001 From: Ahmad Sharif Date: Mon, 8 Jul 2024 06:23:54 -0700 Subject: [PATCH] [torchcodec] Fix bug where we were not finding the best audio stream (#64) Summary: Pull Request resolved: https://github.com/pytorch-labs/torchcodec/pull/64 Previous we were using the best video stream for the best audio stream. This diff fixes that and updates the tests. Reviewed By: NicolasHug Differential Revision: D59460206 --- src/torchcodec/decoders/_core/VideoDecoder.cpp | 2 +- test/decoders/test_metadata.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/torchcodec/decoders/_core/VideoDecoder.cpp b/src/torchcodec/decoders/_core/VideoDecoder.cpp index 7c3d3b88..a5f7561f 100644 --- a/src/torchcodec/decoders/_core/VideoDecoder.cpp +++ b/src/torchcodec/decoders/_core/VideoDecoder.cpp @@ -176,7 +176,7 @@ void VideoDecoder::initializeDecoder() { if (bestVideoStream >= 0) { containerMetadata_.bestVideoStreamIndex = bestVideoStream; } - int bestAudioStream = getBestStreamIndex(AVMEDIA_TYPE_VIDEO); + int bestAudioStream = getBestStreamIndex(AVMEDIA_TYPE_AUDIO); if (bestAudioStream >= 0) { containerMetadata_.bestAudioStreamIndex = bestAudioStream; } diff --git a/test/decoders/test_metadata.py b/test/decoders/test_metadata.py index 6b3921a9..6253683d 100644 --- a/test/decoders/test_metadata.py +++ b/test/decoders/test_metadata.py @@ -16,7 +16,7 @@ def test_get_video_metadata(): metadata = get_video_metadata(decoder) assert len(metadata.streams) == 6 assert metadata.best_video_stream_index == 3 - assert metadata.best_audio_stream_index == 3 + assert metadata.best_audio_stream_index == 4 with pytest.raises(NotImplementedError, match="TODO: decide on logic"): metadata.duration_seconds