avifilelib.rle module

Decoders for Microsoft RLE formats.

This package provides decoders capable of decoding frames encoded using the Microsoft RLE4 and RLE8 formats.

class avifilelib.rle.RLE4Decoder(width, height, colors)

Bases: avifilelib.rle.RLEDecoderBase

Decoder for RLE4 compression.

This class implements a decoder for the RLE4 compression algorithm.

Parameters:
  • width (int) – Width of the image to be decoded.
  • height (int) – Height of the image to be decoded.
  • colors (numpy.ndarray, dtype=uint8) – 16 x 3 of red, green, and blue values.
COMPRESSION = 2
decode_frame_buffer(buffer, size, keyframe=True)

Decode a frame from a bytes object.

Decodes a single frame from the data contained in buffer.

Parameters:
  • buffer (bytes) – A bytes object containing the frame data.
  • size (int) – Size of the data in the 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

class avifilelib.rle.RLE8Decoder(width, height, colors)

Bases: avifilelib.rle.RLEDecoderBase

Decoder for RLE8 compression.

This class implements a decoder for the RLE8 compression algorithm.

Parameters:
  • width (int) – Width of the image to be decoded.
  • height (int) – Height of the image to be decoded.
  • colors (numpy.ndarray, dtype=uint8) – 256 x 3 of red, green, and blue values.
COMPRESSION = 1
decode_frame_buffer(buffer, size, keyframe=True)

Decode a frame from a bytes object.

Decodes a single frame from the data contained in buffer.

Parameters:
  • buffer (bytes) – A bytes object containing the frame data.
  • size (int) – Size of the data in the 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

class avifilelib.rle.RLEDecoderBase(width, height, colors)

Bases: avifilelib.decoder.DecoderBase

Base class for RLE formats.

This class provides the foundation for run-length encoding decoders. Both the RLE4 and RLE8 formats require color paletes, and therefore this class accepts a color palate/table as an argument.

Parameters:
  • width (int) – Width of the image to be decoded.
  • height (int) – Height of the image to be decoded.
  • colors (numpy.ndarray, dtype=uint8) – N x 3 of red, green, and blue values, where N is 2^4 or 2^8 depending on the type of RLE compression.
COMPRESSION = (<BI_COMPRESSION.BI_RLE4: 2>, <BI_COMPRESSION.BI_RLE8: 1>)
colors

Get the color table.

classmethod for_avi_stream(stream_definition)

Attempts to find a decoder implementation for a stream.

Subclasses of RLEDecoderBase are selected by matching the value of COMPRESSION.

Returns:A subclass of RLEDecoderBase.
Return type:object