Audio¶
Audio Streams¶
- class av.audio.stream.AudioStream¶
Bases:
Stream
- decode(Packet packet=None)¶
Decode a
Packet
and return a list ofAudioFrame
.- Return type:
See also
This is a passthrough to
CodecContext.decode()
.
- encode(AudioFrame frame=None)¶
Encode an
AudioFrame
and return a list ofPacket
.See also
This is mostly a passthrough to
CodecContext.encode()
.
Audio Context¶
- class av.audio.codeccontext.AudioCodecContext¶
Bases:
CodecContext
- format¶
The audio sample format.
- Type:
- layout¶
The audio channel layout.
- Type:
- rate¶
Another name for
sample_rate
.
Audio Formats¶
- class av.audio.format.AudioFormat¶
Bases:
object
Descriptor of audio formats.
- bits¶
Number of bits per sample.
>>> AudioFormat('s16p').bits 16
- bytes¶
Number of bytes per sample.
>>> AudioFormat('s16p').bytes 2
- container_name¶
The name of a
ContainerFormat
which directly accepts this data.- Raises:
ValueError – when planar, since there are no such containers.
- name¶
Canonical name of the sample format.
>>> AudioFormat('s16p').name 's16p'
- packed¶
The packed variant of this format.
Is itself when packed:
>>> fmt = AudioFormat('s16') >>> fmt.packed is fmt True
- planar¶
The planar variant of this format.
Is itself when planar:
>>> fmt = AudioFormat('s16p') >>> fmt.planar is fmt True
Audio Layouts¶
Audio Frames¶
- class av.audio.frame.AudioFrame¶
Bases:
Frame
A frame of audio.
- format¶
The audio sample format.
- Type:
- static from_ndarray(array, format='s16', layout='stereo')¶
Construct a frame from a numpy array.
- layout¶
The audio channel layout.
- Type:
- rate¶
Another name for
sample_rate
.
- to_ndarray()¶
Get a numpy array of this frame.
Note
Numpy must be installed.
Audio FIFOs¶
- class av.audio.fifo.AudioFifo¶
Bases:
object
A simple audio sample FIFO (First In First Out) buffer.
- write(frame)¶
Push a frame of samples into the queue.
- Parameters:
frame (AudioFrame) – The frame of samples to push.
The FIFO will remember the attributes from the first frame, and use those to populate all output frames.
If there is a
pts
andtime_base
andsample_rate
, then the FIFO will assert that the incoming timestamps are continuous.
- read(samples=0, partial=False)¶
Read samples from the queue.
- Parameters:
- Returns:
New
AudioFrame
orNone
(if empty).
If the incoming frames had valid a
time_base
,sample_rate
andpts
, the returned frames will have accurate timing.
- read_many(samples, partial=False)¶
Read as many frames as we can.
- format¶
The
AudioFormat
of this FIFO.
- layout¶
The
AudioLayout
of this FIFO.
- pts_per_sample¶
- sample_rate¶
- samples¶
Number of audio samples (per channel) in the buffer.
- samples_read¶
- samples_written¶
Audio Resamplers¶
- class av.audio.resampler.AudioResampler(format=None, layout=None, rate=None)¶
Bases:
object
- Parameters:
format (AudioFormat) – The target format, or string that parses to one (e.g.
"s16"
).layout (AudioLayout) – The target layout, or an int/string that parses to one (e.g.
"stereo"
).rate (int) – The target sample rate.
- resample(frame)¶
Convert the
sample_rate
,channel_layout
and/orformat
of aAudioFrame
.- Parameters:
frame (AudioFrame) – The frame to convert or None to flush.
- Returns:
A list of
AudioFrame
in new parameters. If the nothing is to be done return the same frame as a single element list.
- format¶
- frame_size¶
- is_passthrough¶
- layout¶
- rate¶