Skip to content

Commit a60968c

Browse files
danielflores3Dan-Flores
authored andcommitted
Update C++ metadata names to match python
1 parent 3056f40 commit a60968c

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

src/torchcodec/_core/Metadata.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ struct StreamMetadata {
2525
AVMediaType mediaType;
2626
std::optional<AVCodecID> codecId;
2727
std::optional<std::string> codecName;
28-
std::optional<double> durationSeconds;
28+
std::optional<double> durationSecondsFromHeader;
2929
std::optional<double> beginStreamFromHeader;
30-
std::optional<int64_t> numFrames;
30+
std::optional<int64_t> numFramesFromHeader;
3131
std::optional<int64_t> numKeyFrames;
3232
std::optional<double> averageFps;
3333
std::optional<double> bitRate;
@@ -58,7 +58,7 @@ struct ContainerMetadata {
5858
int numVideoStreams = 0;
5959
// Note that this is the container-level duration, which is usually the max
6060
// of all stream durations available in the container.
61-
std::optional<double> durationSeconds;
61+
std::optional<double> durationSecondsFromHeader;
6262
// Total BitRate level information at the container level in bit/s
6363
std::optional<double> bitRate;
6464
// If set, this is the index to the default audio stream.

src/torchcodec/_core/SingleStreamDecoder.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ void SingleStreamDecoder::initializeDecoder() {
125125

126126
int64_t frameCount = avStream->nb_frames;
127127
if (frameCount > 0) {
128-
streamMetadata.numFrames = frameCount;
128+
streamMetadata.numFramesFromHeader = frameCount;
129129
}
130130

131131
if (avStream->duration > 0 && avStream->time_base.den > 0) {
132-
streamMetadata.durationSeconds =
132+
streamMetadata.durationSecondsFromHeader =
133133
av_q2d(avStream->time_base) * avStream->duration;
134134
}
135135
if (avStream->start_time != AV_NOPTS_VALUE) {
@@ -163,7 +163,7 @@ void SingleStreamDecoder::initializeDecoder() {
163163

164164
if (formatContext_->duration > 0) {
165165
AVRational defaultTimeBase{1, AV_TIME_BASE};
166-
containerMetadata_.durationSeconds =
166+
containerMetadata_.durationSecondsFromHeader =
167167
ptsToSeconds(formatContext_->duration, defaultTimeBase);
168168
}
169169

@@ -1463,9 +1463,9 @@ int64_t SingleStreamDecoder::getNumFrames(
14631463
return streamMetadata.numFramesFromScan.value();
14641464
case SeekMode::approximate: {
14651465
TORCH_CHECK(
1466-
streamMetadata.numFrames.has_value(),
1466+
streamMetadata.numFramesFromHeader.has_value(),
14671467
"Cannot use approximate mode since we couldn't find the number of frames from the metadata.");
1468-
return streamMetadata.numFrames.value();
1468+
return streamMetadata.numFramesFromHeader.value();
14691469
}
14701470
default:
14711471
throw std::runtime_error("Unknown SeekMode");
@@ -1491,9 +1491,9 @@ double SingleStreamDecoder::getMaxSeconds(
14911491
return streamMetadata.maxPtsSecondsFromScan.value();
14921492
case SeekMode::approximate: {
14931493
TORCH_CHECK(
1494-
streamMetadata.durationSeconds.has_value(),
1494+
streamMetadata.durationSecondsFromHeader.has_value(),
14951495
"Cannot use approximate mode since we couldn't find the duration from the metadata.");
1496-
return streamMetadata.durationSeconds.value();
1496+
return streamMetadata.durationSecondsFromHeader.value();
14971497
}
14981498
default:
14991499
throw std::runtime_error("Unknown SeekMode");

src/torchcodec/_core/_metadata.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ def get_container_metadata(decoder: torch.Tensor) -> ContainerMetadata:
225225
for stream_index in range(container_dict["numStreams"]):
226226
stream_dict = json.loads(_get_stream_json_metadata(decoder, stream_index))
227227
common_meta = dict(
228-
duration_seconds_from_header=stream_dict.get("durationSeconds"),
228+
duration_seconds_from_header=stream_dict.get("durationSecondsFromHeader"),
229229
bit_rate=stream_dict.get("bitRate"),
230-
begin_stream_seconds_from_header=stream_dict.get("beginStreamFromHeader"),
230+
begin_stream_seconds_from_header=stream_dict.get("beginStreamSecondsFromHeader"),
231231
codec=stream_dict.get("codec"),
232232
stream_index=stream_index,
233233
)
@@ -242,9 +242,9 @@ def get_container_metadata(decoder: torch.Tensor) -> ContainerMetadata:
242242
),
243243
width=stream_dict.get("width"),
244244
height=stream_dict.get("height"),
245-
num_frames_from_header=stream_dict.get("numFrames"),
245+
num_frames_from_header=stream_dict.get("numFramesFromHeader"),
246246
num_frames_from_content=stream_dict.get("numFramesFromScan"),
247-
average_fps_from_header=stream_dict.get("averageFps"),
247+
average_fps_from_header=stream_dict.get("averageFpsFromHeader"),
248248
**common_meta,
249249
)
250250
)
@@ -264,7 +264,7 @@ def get_container_metadata(decoder: torch.Tensor) -> ContainerMetadata:
264264
streams_metadata.append(StreamMetadata(**common_meta))
265265

266266
return ContainerMetadata(
267-
duration_seconds_from_header=container_dict.get("durationSeconds"),
267+
duration_seconds_from_header=container_dict.get("durationSecondsFromHeader"),
268268
bit_rate_from_header=container_dict.get("bitRate"),
269269
best_video_stream_index=container_dict.get("bestVideoStreamIndex"),
270270
best_audio_stream_index=container_dict.get("bestAudioStreamIndex"),

src/torchcodec/_core/custom_ops.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -456,18 +456,18 @@ std::string get_json_metadata(at::Tensor& decoder) {
456456

457457
std::map<std::string, std::string> metadataMap;
458458
// serialize the metadata into a string std::stringstream ss;
459-
double durationSeconds = 0;
459+
double durationSecondsFromHeader = 0;
460460
if (maybeBestVideoStreamIndex.has_value() &&
461461
videoMetadata.allStreamMetadata[*maybeBestVideoStreamIndex]
462-
.durationSeconds.has_value()) {
463-
durationSeconds =
462+
.durationSecondsFromHeader.has_value()) {
463+
durationSecondsFromHeader =
464464
videoMetadata.allStreamMetadata[*maybeBestVideoStreamIndex]
465-
.durationSeconds.value_or(0);
465+
.durationSecondsFromHeader.value_or(0);
466466
} else {
467467
// Fallback to container-level duration if stream duration is not found.
468-
durationSeconds = videoMetadata.durationSeconds.value_or(0);
468+
durationSecondsFromHeader = videoMetadata.durationSecondsFromHeader.value_or(0);
469469
}
470-
metadataMap["durationSeconds"] = std::to_string(durationSeconds);
470+
metadataMap["durationSecondsFromHeader"] = std::to_string(durationSecondsFromHeader);
471471

472472
if (videoMetadata.bitRate.has_value()) {
473473
metadataMap["bitRate"] = std::to_string(videoMetadata.bitRate.value());
@@ -523,8 +523,8 @@ std::string get_container_json_metadata(at::Tensor& decoder) {
523523

524524
std::map<std::string, std::string> map;
525525

526-
if (containerMetadata.durationSeconds.has_value()) {
527-
map["durationSeconds"] = std::to_string(*containerMetadata.durationSeconds);
526+
if (containerMetadata.durationSecondsFromHeader.has_value()) {
527+
map["durationSecondsFromHeader"] = std::to_string(*containerMetadata.durationSecondsFromHeader);
528528
}
529529

530530
if (containerMetadata.bitRate.has_value()) {
@@ -562,8 +562,8 @@ std::string get_stream_json_metadata(
562562

563563
std::map<std::string, std::string> map;
564564

565-
if (streamMetadata.durationSeconds.has_value()) {
566-
map["durationSeconds"] = std::to_string(*streamMetadata.durationSeconds);
565+
if (streamMetadata.durationSecondsFromHeader.has_value()) {
566+
map["durationSecondsFromHeader"] = std::to_string(*streamMetadata.durationSecondsFromHeader);
567567
}
568568
if (streamMetadata.bitRate.has_value()) {
569569
map["bitRate"] = std::to_string(*streamMetadata.bitRate);
@@ -572,11 +572,11 @@ std::string get_stream_json_metadata(
572572
map["numFramesFromScan"] =
573573
std::to_string(*streamMetadata.numFramesFromScan);
574574
}
575-
if (streamMetadata.numFrames.has_value()) {
576-
map["numFrames"] = std::to_string(*streamMetadata.numFrames);
575+
if (streamMetadata.numFramesFromHeader.has_value()) {
576+
map["numFramesFromHeader"] = std::to_string(*streamMetadata.numFramesFromHeader);
577577
}
578578
if (streamMetadata.beginStreamFromHeader.has_value()) {
579-
map["beginStreamFromHeader"] =
579+
map["beginStreamSecondsFromHeader"] =
580580
std::to_string(*streamMetadata.beginStreamFromHeader);
581581
}
582582
if (streamMetadata.minPtsSecondsFromScan.has_value()) {
@@ -597,7 +597,7 @@ std::string get_stream_json_metadata(
597597
map["height"] = std::to_string(*streamMetadata.height);
598598
}
599599
if (streamMetadata.averageFps.has_value()) {
600-
map["averageFps"] = std::to_string(*streamMetadata.averageFps);
600+
map["averageFpsFromHeader"] = std::to_string(*streamMetadata.averageFps);
601601
}
602602
if (streamMetadata.sampleRate.has_value()) {
603603
map["sampleRate"] = std::to_string(*streamMetadata.sampleRate);

0 commit comments

Comments
 (0)