Skip to content

Commit 22bcf4d

Browse files
authored
Ensure SingleStreamDecoder is robust against numFrames = 0
Differential Revision: D87109526 Pull Request resolved: #1059
1 parent 17164fd commit 22bcf4d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/torchcodec/_core/SingleStreamDecoder.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,14 @@ void SingleStreamDecoder::scanFileAndUpdateMetadataAndIndex() {
288288
streamMetadata.numFramesFromContent =
289289
streamInfos_[streamIndex].allFrames.size();
290290

291+
// This ensures that we are robust in handling cases where
292+
// we are decoding in exact mode and numFrames is 0. The current metadata
293+
// validation logic assumes that these values should not be None
294+
if (streamMetadata.numFramesFromContent.value() == 0) {
295+
streamMetadata.beginStreamPtsFromContent = 0;
296+
streamMetadata.endStreamPtsFromContent = 0;
297+
}
298+
291299
if (streamMetadata.beginStreamPtsFromContent.has_value()) {
292300
streamMetadata.beginStreamPtsSecondsFromContent = ptsToSeconds(
293301
*streamMetadata.beginStreamPtsFromContent, avStream->time_base);

0 commit comments

Comments
 (0)