Audio¶
Audio Streams¶
-
class
av.audio.stream.AudioStream¶ Bases:
av.stream.Stream
Audio Context¶
-
class
av.audio.codeccontext.AudioCodecContext¶ Bases:
av.codec.context.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.
>>> SampleFormat('s16p').bits 16
-
bytes¶ Number of bytes per sample.
>>> SampleFormat('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.
>>> SampleFormat('s16p').name 's16p'
-
packed¶ The packed variant of this format.
Is itself when packed:
>>> fmt = Format('s16') >>> fmt.packed is fmt True
-
planar¶ The planar variant of this format.
Is itself when planar:
>>> fmt = Format('s16p') >>> fmt.planar is fmt True
-
Audio Layouts¶
-
class
av.audio.layout.AudioLayout(layout)¶ Bases:
object-
channels¶ A tuple of
AudioChannelobjects.- Type
-
name¶ The canonical name of the audio layout.
-
Audio Frames¶
-
class
av.audio.frame.AudioFrame¶ Bases:
av.frame.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(**kwargs)¶ 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.
- Returns
A new
AudioFramein new parameters, or the same frame if there is nothing to be done.- Raises
ValueErrorifFrame.ptsis set and non-simple.
-
format¶
-
is_passthrough¶
-
layout¶
-
pts_per_sample_in¶
-
rate¶
-
samples_in¶
-
samples_out¶
-
simple_pts_out¶