Audio¶
Audio Streams¶
- class av.audio.stream.AudioStream¶
 Bases:
Stream- decode(Packet packet: Packet | None = None)¶
 Decode a
Packetand return a list ofAudioFrame.- Return type:
 
See also
This is a passthrough to
CodecContext.decode().
- encode(AudioFrame frame: AudioFrame | None = None)¶
 Encode an
AudioFrameand 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:
objectDescriptor 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
ContainerFormatwhich 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:
FrameA 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:
objectA 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
ptsandtime_baseandsample_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
AudioFrameorNone(if empty).
If the incoming frames had valid a
time_base,sample_rateandpts, the returned frames will have accurate timing.
- read_many(samples, partial=False)¶
 Read as many frames as we can.
- format¶
 The
AudioFormatof this FIFO.
- layout¶
 The
AudioLayoutof 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_layoutand/orformatof aAudioFrame.- Parameters:
 frame (AudioFrame) – The frame to convert or None to flush.
- Returns:
 A list of
AudioFramein 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¶