avifilelib.data module¶
AVI Stream Data classes.
This module contains classes for handling the stream data within
an AVI file. These classes include AviMoviList which represents
the list structure containing stream data within the AVI file. The ‘movi’
list may optionally contain ‘rec ‘ lists (represented by the AviRecList
class). ‘rec ‘ lists are used to group stream data chunks to indicate that they
should all be read from disk at the same time. This library does not preload data,
and therefore, does not take any special action based on the presence of ‘rec ‘
lists within the ‘movi’ list. Further, upon the location and parsing of a ‘rec ‘
list within an AVI file, avifilelib simply adds the data chunks contained in the
‘rec ‘ list directly into the ‘movi’ list.
Finally, this module provides the AviStreamChunk class to represent a
chunk of stream data within the AVI file. Note that the flags applicable to a
stream chunk are identified in the avifilelib.index.AviV1Index, and
therefore will not normally be available when AviStreamChunks are created.
-
class
avifilelib.data.AviMoviList(absolute_offset=0, data_chunks=None)¶ Bases:
objectUsed to read the ‘movi’ list within an AVI file.
This class is used to facilitate the loading of stream data chunks contained with the ‘movi’ list and to make those chunks acessible for later decoding. Because the AVI index structure identifies chunks by their offset from the start of the ‘movi’ list, the absolute offset of the start of the ‘movi’ list is required in order to compute the relative offsets of the contained data chunks.
Parameters: - absolute_offset (int) – Absolute offset in bytes of the the start of the ‘movi’ list data section from the start of the underlying file.
- data_chunks (list) – A list of
AviStreamChunkobjects.
-
apply_index(index)¶ Apply flags and skipping as defined by an AVI Index.
Parameters: index ( avifilelib.index.AviV1Index) – An index containing AVI indexing information.
-
iter_chunks(stream=None)¶ Return an iterator over the chunks in a stream.
Parameters: stream (int) – Stream identifier of the stream to be iterated over. Returns: A generator that iterates over the chunks in a stream. Return type: generator
-
classmethod
load(file_like)¶ Create an AviMoviList structure.
This method creates an
AviMoviListfrom the contents of an AVI ‘movi’ list. Note that this does not actually load the data associated with the contained stream chunks.Parameters: file_like (file-like) – A file-like object positioned at the start of a ‘movi’ list. Returns: An AviMoviList containing AviStreamChunkobjects.Return type: AviMoviList
-
class
avifilelib.data.AviRecList(data_chunks=None)¶ Bases:
objectUsed to read ‘rec ‘ lists within an AVI file.
Note that this class is used only to facilitate the loading of stream data chunks contained with ‘rec ‘ lists. avifilelib does not maintain the ‘rec ‘ list structure after the stream data chunks have been identified. All stream data chunks contained within ‘rec ‘ lists are reparented to belong to the ‘movi’ (represented by an
AviMoviList) instead.Parameters: data_chunks (list) – A list containing AviStreamChunkobjects.-
classmethod
load(file_like)¶ Create an AviRecList structure.
This method creates an
AviRecListfrom the contents of an AVI ‘rec ‘ list. Note that this does not actually load the data associated with the contained stream chunks.Parameters: file_like (file-like) – A file-like object positioned at the start of a ‘rec ‘ list. Returns: An AviRecList containing AviStreamChunkobjects.Return type: AviRecList
-
classmethod
-
class
avifilelib.data.AviStreamChunk(stream_id, data_type, base_file, absolute_offset, size, flags=0, skip=False)¶ Bases:
objectA block of data representing a portion of an audio or video stream.
For a video stream, a stream chunk would typically represent a single frame. This class does not load the data into memory, but does provide an interface to read the data associated with the chunk from the file system.
Parameters: - stream_id (int) – Identifier of the stream.
- data_type (STREAM_DATA_TYPES) – Identifies the kind of data stored in the chunk.
- base_file (file-like) – File-like object from which the data should be read.
- absolute_offset (int) – Offset from the start of the ‘MOVI’ list.
- size (int) – Size of the chunk.
- flags (AVIIF) – Flags associated with the frame.
- skip (bool) – If True the chunk will be skipped when iterating over the chunks.
-
flags¶ Get the AVIIF flags for the chunks.
-
classmethod
load(file_like)¶ Create an AviStreamChunk structure.
This method creates an
AviStreamChunkfrom the contents of an AVI ‘movi’ or ‘rec ‘ list. Note that this does not actually load the data associated with the stream chunk.Parameters: file_like (file-like) – A file-like object positioned at the start of a stream data chunk. Returns: An AviStreamChunk that may be used to read the data for this chunk. Return type: AviStreamChunk
-
read(size=-1)¶ Read size bytes from the underlying file.
-
seek(pos, whence=0)¶ Change the stream position to the given byte pos. pos is interpreted relative to the position indicated by whence. The default value for whence is SEEK_SET. Values for whence are:
- 0 – start of the chunk (the default); offset should be zero or positive
- 1 – current chunk position; offset may be negative
- 2 – end of the chunk; offset is usually negative
Returns: the new absolute position relative to the start of the stream chunk. Return type: int
-
tell()¶ Return the current position in the chunk.