Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/torchcodec/_core/SingleStreamDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down