Skip to content

Commit 1a8b3f8

Browse files
committed
fixes to pass metadata tests
1 parent df6072d commit 1a8b3f8

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

output.mp3

Whitespace-only changes.

src/torchcodec/_core/custom_ops.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,10 @@ std::string get_json_metadata(at::Tensor& decoder) {
479479
auto streamMetadata =
480480
videoMetadata.allStreamMetadata[*maybeBestVideoStreamIndex];
481481
if (streamMetadata.numFramesFromScan.has_value()) {
482-
metadataMap["numFrames"] =
482+
metadataMap["numFramesFromHeader"] =
483483
std::to_string(*streamMetadata.numFramesFromScan);
484484
} else if (streamMetadata.numFramesFromHeader.has_value()) {
485-
metadataMap["numFrames"] =
485+
metadataMap["numFramesFromHeader"] =
486486
std::to_string(*streamMetadata.numFramesFromHeader);
487487
}
488488
if (streamMetadata.minPtsSecondsFromScan.has_value()) {

src/torchcodec/_samplers/video_clip_sampler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def _get_clips_for_index_based_sampling(
213213
sample_end_index = (
214214
min(
215215
index_based_sampler_args.sample_end_index + 1,
216-
metadata_json["numFrames"],
216+
metadata_json["numFramesFromHeader"],
217217
)
218218
- index_based_sampler_args.video_frame_dilation
219219
* index_based_sampler_args.frames_per_clip
@@ -263,13 +263,13 @@ def _get_start_seconds(
263263
Returns:
264264
(`List[float]`): List of the sampled clip start position in seconds
265265
"""
266-
video_duration_in_seconds = metadata_json["durationSeconds"]
266+
video_duration_in_seconds = metadata_json["durationSecondsFromHeader"]
267267

268268
clip_duration_in_seconds = (
269269
time_based_sampler_args.frames_per_clip
270270
* time_based_sampler_args.video_frame_dilation
271271
+ 1
272-
) / metadata_json["averageFps"]
272+
) / metadata_json["averageFpsFromHeader"]
273273

274274
minPtsSecondsFromScan = (
275275
metadata_json["minPtsSecondsFromScan"]

test/test_ops.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def test_pts_apis_against_index_ref(self, device):
215215

216216
metadata = get_json_metadata(decoder)
217217
metadata_dict = json.loads(metadata)
218-
num_frames = metadata_dict["numFrames"]
218+
num_frames = metadata_dict["numFramesFromHeader"]
219219
assert num_frames == 390
220220

221221
_, all_pts_seconds_ref, _ = zip(
@@ -395,9 +395,11 @@ def test_video_get_json_metadata(self):
395395
metadata_dict = json.loads(metadata)
396396

397397
# We should be able to see all of this metadata without adding a video stream
398-
assert metadata_dict["durationSeconds"] == pytest.approx(13.013, abs=0.001)
399-
assert metadata_dict["numFrames"] == 390
400-
assert metadata_dict["averageFps"] == pytest.approx(29.97, abs=0.001)
398+
assert metadata_dict["durationSecondsFromHeader"] == pytest.approx(
399+
13.013, abs=0.001
400+
)
401+
assert metadata_dict["numFramesFromHeader"] == 390
402+
assert metadata_dict["averageFpsFromHeader"] == pytest.approx(29.97, abs=0.001)
401403
assert metadata_dict["codec"] == "h264"
402404
ffmpeg_dict = get_ffmpeg_library_versions()
403405
if ffmpeg_dict["libavformat"][0] >= 60:

0 commit comments

Comments
 (0)