Containers¶
Generic¶
- class av.container.Container¶
Bases:
object- options¶
- container_options¶
- stream_options¶
- metadata_encoding¶
- metadata_errors¶
- open_timeout¶
- read_timeout¶
Flags¶
- av.container.Container.flags¶
- class av.container.Flags¶
Wraps AVFormatContext.flags.
Container Attribute
Flags Name
Flag Value
Meaning in FFmpeg
Input Containers¶
- class av.container.InputContainer¶
Bases:
Container- bit_rate¶
- close()¶
- decode(streams=None, video=None, audio=None, subtitles=None, data=None)¶
Yields a series of
Framefrom 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
Packetfrom the given set ofStream: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, *, backward=True, any_frame=False, stream=None)¶
Seek to a (key)frame nearest to the given timestamp.
- Parameters:
offset (int) – Time to seek to, expressed in``stream.time_base`` if
streamis given, otherwise inav.time_base.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_basetheoffsetis in.unsupported_frame_offset (bool) –
offsetis a frame index instead of a time; not supported by any known format.unsupported_byte_offset (bool) –
offsetis a byte location in the file; not supported by any known format.
After seeking, packets that you demux should correspond (roughly) to the position you requested.
In most cases, the defaults of
backwards = Trueandany_frame = Falseare the best course of action, followed by you demuxing/decoding to the position that you want. This is because to properly decode video frames you need to start from the previous keyframe.See also
avformat_seek_file for discussion of the flags.
- size¶
- start_time¶
- start_time_realtime¶
Start time of the stream in real world time, in microseconds since the Unix epoch, or
Noneif unknown.Only a few demuxers know this; RTSP computes it from RTCP sender reports, which is what makes it useful for aligning analytics with a camera’s clock.
Output Containers¶
- class av.container.OutputContainer¶
Bases:
Container- add_attachment(str name: str, str mimetype: str, bytes data: bytes)¶
Create an attachment stream and embed its payload into the container header.
Only supported by formats that support attachments (e.g. Matroska).
No per-packet muxing is required; attachments are written at header time.
- add_data_stream(codec_name=None)¶
Creates a new data stream and returns it.
- add_mux_stream(codec_name, rate=None)¶
Creates a new stream for muxing pre-encoded data without creating a
CodecContext. Use this when you want to mux packets that were already encoded externally and no encoding/decoding is needed.
- add_stream(codec_name, rate=None, *, hwaccel=None)¶
Creates a new stream from a codec name and returns it. Supports video, audio, and subtitle streams.
- Parameters:
codec_name (str) – The name of a codec.
options (dict) – Stream options.
hwaccel (HWAccel) – Optional settings for hardware-accelerated encoding. Only applies to video streams (e.g.
h264_vaapi); software frames passed toencode()are uploaded to the device automatically.**kwargs – Set attributes for the stream.
- Return type:
The new
Stream.
Warning
Configure every output stream before muxing the first packet. Writing the file header opens all stream codec contexts, after which structural properties such as format, dimensions, layout, and rate cannot change.
- add_stream_from_template(Stream template: Stream, bool opaque: bool | None = None, **kwargs)¶
Creates a new stream from a template. Supports video, audio, subtitle, data and attachment streams.
- close()¶
- default_audio_codec¶
Returns the default audio codec this container recommends.
- default_subtitle_codec¶
Returns the default subtitle codec this container recommends.
- default_video_codec¶
Returns the default video codec this container recommends.
- mux(packets)¶
- start_encoding()¶
Write the file header! Called automatically.
- supported_codecs¶
Returns a set of all codecs this format supports.
Formats¶
- ContainerFormat.name¶
- ContainerFormat.long_name¶
- ContainerFormat.input¶
An input-only view of this format.
- ContainerFormat.output¶
An output-only view of this format.
- ContainerFormat.is_input¶
- ContainerFormat.is_output¶
- ContainerFormat.extensions¶