Streams¶
Stream collections¶
- class av.container.streams.StreamContainer¶
Bases:
objectA tuple-like container of
Stream.# There are a few ways to pulling out streams. first = container.streams[0] video = container.streams.video[0] audio = container.streams.get(audio=(0, 1))
Dynamic Slicing¶
- StreamContainer.get(streams=None, video=None, audio=None, subtitles=None, data=None)¶
Get a selection of
Streamas alist.Positional arguments may be
int(which is an index into the streams), orlistortupleof those:# Get the first channel. streams.get(0) # Get the first two audio channels. streams.get(audio=(0, 1))
Keyword arguments (or dicts as positional arguments) as interpreted as
(stream_type, index_value_or_set)pairs:# Get the first video channel. streams.get(video=0) # or streams.get({'video': 0})
Streamobjects are passed through untouched.If nothing is selected, then all streams are returned.
- StreamContainer.best(type: Literal['video', 'audio', 'subtitle', 'attachment', 'data'], /, related: Stream | None)¶
Finds the “best” stream in the file. Wraps av_find_best_stream. Example:
stream = container.streams.best("video")
- Parameters:
type – The type of stream to find
related – A related stream to use as a reference (optional)
- Returns:
The best stream of the specified type
- Return type:
Stream | None
Typed Collections¶
These attributes are preferred for readability if you don’t need the
dynamic capabilities of get():
- StreamContainer.video¶
A tuple of
VideoStream.
- StreamContainer.audio¶
A tuple of
AudioStream.
- StreamContainer.subtitles¶
A tuple of
SubtitleStream.
- StreamContainer.attachments¶
A tuple of
AttachmentStream.
- StreamContainer.data¶
A tuple of
DataStream.
- StreamContainer.other¶
A tuple of
Stream
Streams¶
- class av.stream.Stream¶
Bases:
objectA single stream of audio, video or subtitles within a
Container.>>> fh = av.open(video_path) >>> stream = fh.streams.video[0] >>> stream <av.VideoStream #0 h264, yuv420p 1280x720 at 0x...>
This encapsulates a
CodecContext, located atStream.codec_context. Attribute access is passed through to that context when attributes are missing on the stream itself. E.g.stream.optionswill be the options on the context.
Basics¶
- Stream.type¶
The type of the stream.
- Type:
Literal[“audio”, “video”, “subtitle”, “data”, “attachment”]
- Stream.codec_context¶
Timing¶
See also
Time for a discussion of time in general.
- Stream.time_base¶
The unit of time (in fractional seconds) in which timestamps are expressed.
- Type:
fractions.Fraction | None
Others¶
- Stream.discard¶
Controls which packets of this stream are discarded by the demuxer.
Set this to e.g.
Discard.allon streams you don’t need so thatContainer.demux()andContainer.seek()skip them, avoiding the cost of synchronizing streams you never read.- Type:
Discard