VideoStream#
- class torchcodec.decoders.VideoStream(demuxer: Demuxer, index: int)[source]#
A video stream followed by a
Demuxer.You should not build one yourself: a
Demuxercreates one for you.- Variables:
index (int) – The stream’s index within the container, absolute across all media types. This is what a
Packet’sstream_indexcan be compared against.
Examples using
VideoStream:- 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, usemetadatainstead. SeeVideoCodecParameters.
- 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
VideoPacketDecoderis 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_headerand_from_contentsuffixes 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: