Containers

class av.container.Container

Bases: object

container_options
dumps_format()
file
format
metadata
metadata_encoding
metadata_errors
name
options
stream_options
streams
writeable

Input Containers

class av.container.InputContainer

Bases: av.container.core.Container

bit_rate
decode(streams=None, video=None, audio=None, subtitles=None, data=None)

Yields a series of Frame from the given set of streams:

for frame in container.decode():
    # Do something with `frame`.

See also

StreamContainer.get() for the interpretation of the arguments.

demux(streams=None, video=None, audio=None, subtitles=None, data=None)

Yields a series of Packet from the given set of Stream:

for packet in container.demux():
    # Do something with `packet`, often:
    for frame in packet.decode():
        # Do something with `frame`.

See also

StreamContainer.get() for the interpretation of the arguments.

Note

The last packets are dummy packets that when decoded will flush the buffers.

duration
seek(offset, whence='time', backward=True, any_frame=False, stream=None)

Seek to a (key)frame nearsest to the given timestamp.

Parameters:
  • offset (int) – Location to seek to. Interpretation depends on whence.
  • whence (str) – One of 'time', 'frame', or 'byte'
  • backward (bool) – If there is not a (key)frame at the given offset, look backwards for it.
  • any_frame (bool) – Seek to any frame, not just a keyframe.
  • stream (Stream) – The stream who’s time_base the offset is in.

whence has the following meanings:

  • 'time': offset is in stream.time_base if stream else av.time_base.
  • 'frame': offset is a frame index
  • 'byte': offset is the byte location in the file to seek to.

Warning

Not all formats support all options, and may fail silently.

size
start_time

Output Containers

class av.container.OutputContainer

Bases: av.container.core.Container

add_stream(codec_name, rate=None)

Create a new stream, and return it.

Parameters:
  • codec_name (str) – The name of a codec.
  • rate – The frame rate for video, and sample rate for audio. Examples for video include 24, 23.976, and Fraction(30000,1001). Examples for audio include 48000 and 44100.
Returns:

The new Stream.

close(strict=False)
mux(packets)
mux_one(Packet packet)
start_encoding()

Write the file header! Called automatically.

Formats

class av.format.ContainerFormat

Bases: object

Descriptor of a container format.

Parameters:
  • name (str) – The name of the format.
  • mode (str) – 'r' or 'w' for input and output formats; defaults to None which will grab either.
descriptor
extensions
input

An input-only view of this format.

is_input
is_output
long_name
name
options
output

An output-only view of this format.