Skip to content

Commit e3b91ea

Browse files
author
Molly Xu
committed
address feedback
1 parent 8bf490c commit e3b91ea

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/torchcodec/_core/Metadata.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ std::optional<int64_t> StreamMetadata::getNumFrames(SeekMode seekMode) const {
8080
numFramesFromContent.has_value(), "Missing numFramesFromContent");
8181
return numFramesFromContent.value();
8282
case SeekMode::approximate: {
83-
if (numFramesFromContent.has_value()) {
84-
return numFramesFromContent.value();
85-
}
8683
if (numFramesFromHeader.has_value()) {
8784
return numFramesFromHeader.value();
8885
}

src/torchcodec/_core/custom_ops.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -801,9 +801,17 @@ std::string get_stream_json_metadata(
801801

802802
std::map<std::string, std::string> map;
803803

804-
if ((seekMode == SeekMode::custom_frame_mappings &&
805-
stream_index == activeStreamIndex) ||
806-
(seekMode != SeekMode::custom_frame_mappings)) {
804+
// Check whether content-based metadata is available for this stream.
805+
// In exact mode: content-based metadata exists for all streams.
806+
// In approximate mode: content-based metadata does not exist for any stream.
807+
// In custom_frame_mappings: content-based metadata exists only for the active
808+
// stream.
809+
// Our fallback logic assumes content-based metadata is available.
810+
// It is available for decoding on the active stream, but would break
811+
// when getting metadata from non-active streams.
812+
if ((seekMode != SeekMode::custom_frame_mappings) ||
813+
(seekMode == SeekMode::custom_frame_mappings &&
814+
stream_index == activeStreamIndex)) {
807815
if (streamMetadata.durationSecondsFromHeader.has_value()) {
808816
map["durationSecondsFromHeader"] =
809817
std::to_string(*streamMetadata.durationSecondsFromHeader);

0 commit comments

Comments
 (0)