Rate this Page
★ ★ ★ ★ ★

get_image_metadata#

torchcodec.decoders.get_image_metadata(source: str | Path | bytes | Tensor) → ImageMetadata[source]#

Get the metadata of an encoded image, without decoding it.

The format is detected from the encoded data, like in decode_image().

See ImageMetadata for the returned attributes, which all describe the output of the decoders.

Example

from torchcodec.decoders import get_image_metadata

metadata = get_image_metadata("image.jpg")
print(metadata.width, metadata.height)
Parameters:

source (str, pathlib.Path, bytes, or torch.Tensor) – The encoded image data: a path (str or pathlib.Path), a bytes object, or a 1-D uint8 torch.Tensor of the raw encoded bytes.

Returns:

The image metadata.

Return type:

ImageMetadata

Examples using get_image_metadata:

Decoding images

Decoding images