SimpleVideoDecoder¶
- class torchcodec.decoders.SimpleVideoDecoder(source: Union[str, Path, bytes, Tensor], dimension_order: Literal['NCHW', 'NHWC'] = 'NCHW')[source]¶
A single-stream video decoder.
If the video contains multiple video streams, the best stream is used. This decoder always performs a scan of the video.
- Parameters:
source (str,
Pathlib.path
,torch.Tensor
, or bytes) –The source of the video.
If
str
orPathlib.path
: a path to a local video file.If
bytes
object ortorch.Tensor
: the raw encoded video data.
dimension_order (str, optional) –
The dimension order of the decoded frames. This can be either “NCHW” (default) or “NHWC”, where N is the batch size, C is the number of channels, H is the height, and W is the width of the frames.
Note
Frames are natively decoded in NHWC format by the underlying FFmpeg implementation. Converting those into NCHW format is a cheap no-copy operation that allows these frames to be transformed using the torchvision transforms.
- Variables:
metadata (VideoStreamMetadata) – Metadata of the video stream.
Examples using
SimpleVideoDecoder
:Decoding a video with SimpleVideoDecoder
Decoding a video with SimpleVideoDecoder- __getitem__(key: Union[int, slice]) Tensor [source]¶
Return frame or frames as tensors, at the given index or range.
- get_frame_displayed_at(seconds: float) Frame [source]¶
Return a single frame displayed at the given timestamp in seconds.