Rate this Page
★ ★ ★ ★ ★

VideoStream#

class torchcodec.decoders.VideoStream(demuxer: Demuxer, index: int)[source]#

A video stream followed by a Demuxer.

You should not build one yourself: a Demuxer creates one for you.

Variables:

index (int) – The stream’s index within the container, absolute across all media types. This is what a Packet’s stream_index can be compared against.

Examples using VideoStream:

Build your own decoding pipeline

Build your own decoding pipeline
property codec_parameters: VideoCodecParameters#

What a decoder needs to know to decode this stream’s packets.

Pass them to a VideoPacketDecoder, or pickle them to build the decoder in another process. To read the stream’s properties, use metadata instead. See VideoCodecParameters.

make_decoder(device: str | device | None = None, *, num_ffmpeg_threads: int = 1) → VideoPacketDecoder[source]#

[DISCOURAGED]

Still available so that existing code keeps working. The recommended way to build a VideoPacketDecoder is to instantiate it directly, from the stream’s codec parameters: VideoPacketDecoder(stream.codec_parameters, ...).

property metadata: VideoStreamHeaderMetadata#

What the container header says about this video stream.

From the header only. This stream’s exact frame count, timestamps and keyframe positions aren’t in there - those come from scan(), and that is the distinction the _from_header and _from_content suffixes mark.

scan() → FrameIndex[source]#

Demux this stream from end to end, without decoding it (a scan), and return its FrameIndex.

This is the only way to know a stream’s exact frame count, timestamps and keyframe positions: the container header can be wrong about all three.

You can call this on multiple video streams from the same demuxer. The first call scans the entire video once, and subsequent calls on other streams are free.

Important

If called, then this must be called before any packets are read from the demuxer.

Returns:

the frame index for this stream, describing its keyframes and frame positions.

Return type:

FrameIndex