avifilelib.decoder module

Base class for video stream decoders.

This module defines the base class for video decoders and provides a utility function that is used by a number of the included decoders.

class avifilelib.decoder.DecoderBase(width, height)

Bases: object

Base class for video Decoder objects.

Parameters:
  • width (int) – Width of the image to be decoded.
  • height (int) – Height of the image to be decoded.
decode_frame_buffer(buffer, size, keyframe=True)

Decode a frame from a bytes object.

This method has no implementation in DecoderBase and raises a NotImplementedError. This method must be implemented by subclasses of DecoderBase.

Parameters:
  • buffer (bytes) – A bytes object containing the frame data.
  • size (int) – Size of the data in the buffer. Some formats write 2-byte aligned chunks, and therefore, the data size need not equal the length of buffer.
  • keyframe (bool) – Indicates to the decoder that this chunk contains a key frame.
Returns:

A two dimensional array of dimensions height by width containing the resulting image.

Return type:

numpy.ndarray

decode_frame_chunk(stream_chunk, keyframe=False)

Decode a frame from a RIFF chunk.

Parameters:
  • stream_chunk (avifilelib.avi.AviStreamChunk) – A data chunk that contains frame data.
  • keyframe (bool) – Indicates to the decoder that this chunk contains a key frame.
Returns:

A two dimensional array of dimensions height by width containing the resulting image.

Return type:

numpy.ndarray

classmethod for_avi_stream(stream_definition)

Attempts to find a decoder implementation for a stream.

This method searches DecoderBase subclasses for a subclass capable of handling the stream format defined in stream_definition. Matches are made by comparing the stream_definition.stream_header.compression field to the COMPRESSION member of a DecoderBase subclass. The COMPRESSION member must be a member of the avifilelib.enums.BI_COMPRESSION enumeration, or a tuple of such values. Thus, if a particular compression method supports multiple subformats, it is recommended that a subclass base for that compression method be written, and the for_avi_stream() method of the subclass be overridden to handle further delegation.

Parameters:stream_definition (avifilelib.avi.AviStreamDefinition) – Stream definition for the stream to be decoded.
Returns:A subclass of DecoderBase capable of decoding a stream compressed according to stream_definition.
Return type:object
height

Gets the height of the image.

image

Gets a copy of the image.

width

Gets the width of the image.

avifilelib.decoder.chunkwise(iterable, count=2, fill_value=None)

Iterate over count-size chunks of an iterable.

Parameters:
  • iterable (iterable) – An object that can be iterated over.
  • count (int) – Size of the chunks to be returned.
  • fill_value (object) – Value to be use as a filler if iterable is not divisible by count.
Returns:

An iterable object which yields count-tuples.

Return type:

zip_longest