Rate this Page
★ ★ ★ ★ ★

VideoStreamHeaderMetadata#

class torchcodec.decoders.VideoStreamHeaderMetadata(duration_seconds_from_header: float | None, begin_stream_seconds_from_header: float | None, bit_rate: float | None, codec: str | None, stream_index: int, media_type: str, width: int | None, height: int | None, num_frames_from_header: int | None, average_fps_from_header: float | None, pixel_aspect_ratio: Fraction | None, rotation: float | None, color_primaries: str | None, color_space: str | None, color_transfer_characteristic: str | None, pixel_format: str | None)[source]#

Metadata of a single video stream, as reported by the container header.

Examples using VideoStreamHeaderMetadata:

Build your own decoding pipeline

Build your own decoding pipeline
average_fps_from_header: float | None#

Averate fps of the stream, obtained from the header (float or None). We recommend using the average_fps attribute instead.

begin_stream_seconds_from_header: float | None#

Beginning of the stream, in seconds, obtained from the header (float or None). Usually, this is equal to 0.

bit_rate: float | None#

Bit rate of the stream, in seconds (float or None).

codec: str | None#

Codec (str or None).

color_primaries: str | None#

Color primaries as reported by FFmpeg. E.g. "bt709", "bt2020".

color_space: str | None#

Color space as reported by FFmpeg. E.g. "bt709", "bt2020nc".

color_transfer_characteristic: str | None#

Color transfer characteristic as reported by FFmpeg E.g. "bt709", "smpte2084" (PQ), "arib-std-b67" (HLG).

duration_seconds_from_header: float | None#

Duration of the stream, in seconds, obtained from the header (float or None). This could be inaccurate.

height: int | None#

Height of the frames (int or None).

media_type: str#

Type of media the stream carries (str). One of "video", "audio", "subtitle", "data", "attachment" or "unknown".

num_frames_from_header: int | None#

Number of frames, from the stream’s metadata. This is potentially inaccurate. (int or None).

pixel_aspect_ratio: Fraction | None#

Pixel Aspect Ratio (PAR), also known as Sample Aspect Ratio (SAR — not to be confused with Storage Aspect Ratio, also SAR), is the ratio between the width and height of each pixel (fractions.Fraction or None).

pixel_format: str | None#

The source pixel format of the video as reported by FFmpeg. E.g. 'yuv420p', 'yuv444p', etc.

rotation: float | None#

Rotation angle in degrees (counter-clockwise rounded to the nearest multiple of 90 degrees) from the display matrix metadata. This indicates how the video should be rotated for correct display. TorchCodec automatically applies this rotation during decoding, so the returned frames are in the correct orientation (float or None).

Note

The width and height attributes report the post-rotation dimensions, i.e., the dimensions of frames as they will be returned by TorchCodec’s decoding methods. For videos with 90 or -90 degree rotation, this means width and height are swapped compared to the raw encoded dimensions in the container.

stream_index: int#

Index of the stream that this metadata refers to (int).

width: int | None#

Width of the frames (int or None).