VideoStreamMetadata¶
- class torchcodec.decoders.VideoStreamMetadata(duration_seconds_from_header: Optional[float], bit_rate: Optional[float], num_frames_from_header: Optional[int], num_frames_from_content: Optional[int], begin_stream_seconds: Optional[float], end_stream_seconds: Optional[float], codec: Optional[str], width: Optional[int], height: Optional[int], average_fps_from_header: Optional[float], stream_index: int)[source]¶
Metadata of a single video stream.
Examples using
VideoStreamMetadata
:Decoding a video with VideoDecoder
Decoding a video with VideoDecoder- property average_fps: Optional[float]¶
Average fps of the stream. If a scan was perfomed, this is computed from the number of frames and the duration of the stream. Otherwise we fall back to
average_fps_from_header
.
- average_fps_from_header: Optional[float]¶
Averate fps of the stream, obtained from the header (float or None). We recommend using the
average_fps
attribute instead.
- begin_stream_seconds: Optional[float]¶
Beginning of the stream, in seconds (float or None). Conceptually, this corresponds to the first frame’s pts. It is computed as min(frame.pts) across all frames in the stream. Usually, this is equal to 0.
- property duration_seconds: Optional[float]¶
Duration of the stream in seconds. We try to calculate the duration from the actual frames if a scan was performed. Otherwise we fall back to
duration_seconds_from_header
.
- duration_seconds_from_header: Optional[float]¶
Duration of the stream, in seconds, obtained from the header (float or None). This could be inaccurate.
- end_stream_seconds: Optional[float]¶
End of the stream, in seconds (float or None). Conceptually, this corresponds to last_frame.pts + last_frame.duration. It is computed as max(frame.pts + frame.duration) across all frames in the stream. Note that no frame is played at this time value, so calling
get_frame_played_at()
with this value would result in an error. Retrieving the last frame is best done by simply indexing theVideoDecoder
object with[-1]
.
- property num_frames: Optional[int]¶
Number of frames in the stream. This corresponds to
num_frames_from_content
if a scan was made, otherwise it corresponds tonum_frames_from_header
.
- num_frames_from_content: Optional[int]¶
Number of frames computed by TorchCodec by scanning the stream’s content (the scan doesn’t involve decoding). This is more accurate than
num_frames_from_header
. We recommend using thenum_frames
attribute instead. (int or None).