avifilelib.definition module

Classes related to stream definitions.

This module contains classes related to stream defintions and headers.

class avifilelib.definition.AviJunkChunk

Bases: object

Consumes a Junk chunk.

classmethod load(file_like)

Consumes a junk chunk.

Parameters:file_like (file-like) – A file-like object containing a ‘JUNK’ chunk.
class avifilelib.definition.AviStreamData(raw_bytes)

Bases: object

Data about a stream.

A stream defintion may contain additional data about a stream within a ‘strd’ chunk. No format is specified for the data. The data is stored in the raw_bytes member of the instance.

Parameters:raw_bytes (bytes) – The data associated with the stream data chunk.
classmethod load(file_like)

Create a new AviStreamData instance.

Creates a new instance from a file-like object positioned at the start of a ‘strd’ chunk.

Parameters:file_like (file-like) – A file-like object containing a ‘strd’ chunk.
Returns:Stream data instance for this stream.
Return type:AviStreamData
class avifilelib.definition.AviStreamDefinition(stream_id, stream_header, stream_format, stream_data=None, stream_name=None)

Bases: object

A container for the data related to stream definitions.

This class contains the information of the ‘strl’ list in an AVI file.

Parameters:
  • stream_id (int) – The id number of the stream.
  • stream_header (AviStreamHeader) – Stream header data for this stream definition.
  • stream_format (AviStreamFormat) – An AviStreamFormat (or subclass thereof) defining the format for the stream.
  • stream_data (AviStreamData) – Optionally, an instance of AviStreamData (or subclass thereof).
  • stream_name (AviStreamName) – Optionally, an instance of AviStreamName (or subclass thereof).
classmethod load(stream_id, file_like)

Create an AviStreamDefinition

This method creates a new AviStreamDefinition from the contents of an AVI ‘strl’ list.

Parameters:
  • stream_id (int) – The id number of the stream.
  • file_like (file-like) – A file-like object positioned at the start of a ‘strl’ list.
Returns:

Return type:

AviStreamDefinition

strd

Get the stream data chunk.

strf

Get the stream format.

strh

Get the stream_header.

strn

Get the stream name.

class avifilelib.definition.AviStreamFormat

Bases: object

Base class for stream format classes.

This class provides the base for concrete implementations of stream format classes.

classmethod load(stream_header, file_like)

Create an AviStreamFormat subclass

This method creates a new instance of a AviStreamFormat from the contents of an AVI ‘strf’ list. Subclasses are selected by matching the FCC_TYPE member of the class to the fcc_type member of the stream_header.

Parameters:
  • stream_header (AviStreamHeader) – Header associated with the stream.
  • file_like (file-like) – A file-like object positioned at the start of a ‘strh’ list.
Returns:

Instance of a AviStreamFormat subclass.

Return type:

object

class avifilelib.definition.AviStreamHeader(fcc_type, fcc_handler, flags, priority, language, initial_frames, scale, rate, start, length, suggested_buffer_size, quality, sample_size, frame)

Bases: object

An AVI Stream Header.

This class represents the AVISTREAMHEADER structure.

classmethod load(file_like)

Create an AviStreamHeader

This method creates a new AviStreamHeader from the contents of an AVI ‘strh’ list.

Parameters:file_like (file-like) – A file-like object positioned at the start of a ‘strh’ list.
Returns:
Return type:AviStreamHeader
class avifilelib.definition.AviStreamName(name)

Bases: object

Name of the stream.

Parameters:name (str) – Stream name
classmethod load(file_like)

Create a new AviStreamName instance.

Creates a new instance from a file-like object positioned at the start of a ‘strn’ chunk.

Parameters:file_like (file-like) – A file-like object containing a ‘strn’ chunk.
Returns:Stream data instance for this stream.
Return type:AviStreamName
class avifilelib.definition.BitmapInfoHeaders(size, width, height, planes, bit_count, compression, size_image, x_pels_per_meter, y_pels_per_meter, clr_used, clr_important)

Bases: avifilelib.definition.AviStreamFormat

Stream format structure for video streams.

For video streams the stream format is a BITMAPINFO structure.

FCC_TYPE = 'vids'
UNPACK_FORMAT = '<I2i2H2I2i2I'
classmethod load(stream_header, file_like, force_color_table=False)

Create a new BitmapInfoHeaders instance from a RIFF file.

Parameters:
  • stream_header (AviStreamHeader) – Stream header structure for the stream
  • file_like (file-like) – A file-like object positioned at the start of ‘strf’ chunk.
  • force_color_table (bool) – Force an attempt to load a color table.
Returns:

The stream format instance for this stream.

Return type:

BitmapInfoHeaders

classmethod load_from_file(file_like, force_color_table=False)

Create a new BitmapInfoHeaders instance from a file.

Parameters:
  • file_like (file-like) – A file-like object positioned at the start of ‘strf’ chunk.
  • force_color_table (bool) – Force an attempt to load a color table.
Returns:

The stream format instance for this stream.

Return type:

BitmapInfoHeaders

read_colortable(file_like, force=False)

Read and store a color table.

Parameters:
  • chunk (file-like) – The file-like object from which the color table should be read.
  • force (bool) – Try and read a color table even if the stream format indicates that there were zero colors used.
class avifilelib.definition.UnparsedStreamFormat(raw_bytes)

Bases: avifilelib.definition.AviStreamFormat

An holder for a raw stream format structure.

This implementation does not parse the stream format.

Parameters:raw_bytes (bytes) – A byte array with the stream format data.
classmethod load(stream_header, file_like)

Create an UnparsedStreamFormat instance

This method creates a new instance of UnparsedStreamFormat from the contents of an AVI ‘strf’ list.

Parameters:
  • stream_header (AviStreamHeader) – Header associated with the stream.
  • file_like (file-like) – A file-like object positioned at the start of a ‘strh’ list.
Returns:

Instance of UnparsedStreamFormat.

Return type:

object