Skip to content

Commit 0ad86a4

Browse files
author
Daniel Flores
committed
link tutorial, simplify tensor creation
1 parent 3c2cb09 commit 0ad86a4

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/torchcodec/decoders/_video_decoder.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ class VideoDecoder:
8282
}
8383
8484
Alternative field names "pkt_pts" and "pkt_duration" are also supported.
85+
Read more about this parameter in:
86+
:ref:`sphx_glr_generated_examples_decoding_custom_frame_mappings.py`
8587
8688
Attributes:
8789
metadata (VideoStreamMetadata): Metadata of the video stream.
@@ -475,13 +477,15 @@ def _read_custom_frame_mappings(
475477
"Invalid custom frame mappings. The 'pts'/'pkt_pts', 'duration'/'pkt_duration', and 'key_frame' keys are required in the frame metadata."
476478
)
477479

478-
frame_data = [
479-
(int(frame[pts_key]), frame["key_frame"], int(frame[duration_key]))
480-
for frame in input_data["frames"]
481-
]
482-
all_frames = torch.tensor([x[0] for x in frame_data], dtype=torch.int64)
483-
is_key_frame = torch.tensor([x[1] for x in frame_data], dtype=torch.bool)
484-
duration = torch.tensor([x[2] for x in frame_data], dtype=torch.int64)
480+
all_frames = torch.tensor(
481+
[int(frame[pts_key]) for frame in input_data["frames"]], dtype=torch.int64
482+
)
483+
is_key_frame = torch.tensor(
484+
[int(frame["key_frame"]) for frame in input_data["frames"]], dtype=torch.bool
485+
)
486+
duration = torch.tensor(
487+
[int(frame[duration_key]) for frame in input_data["frames"]], dtype=torch.int64
488+
)
485489
if not (len(all_frames) == len(is_key_frame) == len(duration)):
486490
raise ValueError("Mismatched lengths in frame index data")
487491
return all_frames, is_key_frame, duration

0 commit comments

Comments
 (0)