From 4cc2e69d8e80561c3164032e106b8ea2beac1b75 Mon Sep 17 00:00:00 2001 From: Cheng Guo Date: Sat, 21 Jun 2025 09:02:34 +0200 Subject: [PATCH] Only enforce the check for video and audio streams --- src/torchcodec/_core/SingleStreamDecoder.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/torchcodec/_core/SingleStreamDecoder.cpp b/src/torchcodec/_core/SingleStreamDecoder.cpp index 02a2d44c..d4f6bfcb 100644 --- a/src/torchcodec/_core/SingleStreamDecoder.cpp +++ b/src/torchcodec/_core/SingleStreamDecoder.cpp @@ -203,11 +203,16 @@ void SingleStreamDecoder::scanFileAndUpdateMetadataAndIndex() { return; } + // Instead of iterating over all streams unconditionally: for (unsigned int i = 0; i < formatContext_->nb_streams; ++i) { - // We want to scan and update the metadata of all streams. - TORCH_CHECK( - formatContext_->streams[i]->discard != AVDISCARD_ALL, - "Did you add a stream before you called for a scan?"); + AVStream* stream = formatContext_->streams[i]; + auto codecType = stream->codecpar->codec_type; + // Only enforce the check for video and audio streams. + if (codecType == AVMEDIA_TYPE_VIDEO || codecType == AVMEDIA_TYPE_AUDIO) { + TORCH_CHECK( + stream->discard != AVDISCARD_ALL, + "Did you add a stream before you called for a scan?"); + } } AutoAVPacket autoAVPacket;