audio¶
this module provides the audio codec interface. Encoders, Decoders and their support code.
- class pyrana.audio.AVRounding¶
Rounding methods. Maybe should be moved into a more generic module.
- class pyrana.audio.Decoder(input_codec, params=None)¶
Decodes audio Packets into audio Frames.
- decode(packets)¶
Decode data from a logical stream of packets, and returns when the first next frame is available. The input stream can be - a materialized sequence of packets (list, tuple...) - a generator (e.g. Demuxer.stream()).
- decode_packet(packet)¶
Generator method. Decode a single packet (as in returned by a Demuxer) and extracts all the frames encoded into it. An encoded packet can legally contain more than one frame, altough this is not so common. This method deals with the [one packet -> many frames] scenario. The internal underlying decoder does its own buffer, so you can freely dispose the packet(s) fed into this method after it exited. raises ProcessingError if decoding fails; raises NeedFeedError if decoding partially succeeds, but more data is needed to reconstruct a full frame.
- extra_data¶
bytearray-like, read-write
- flush()¶
emits all frames that can be recostructed by the data buffered into the Decoder, and empties such buffers. Call it last, do not intermix with decode*() calls. caution: more than one frame can be buffered. Raises NeedFeedError if all the internal buffers are empty.
- classmethod from_cdata(ctx)¶
builds a pyrana Audio Decoder from (around) a (cffi-wrapped) libav* (audio)decoder object. The libav object must be already initialized and ready to go. WARNING: raw access. Use with care.
- media_type¶
the codec media type.
- open(ffh=None)¶
opens the codec into the codec context.
- params¶
the codec parameters.
- ready¶
is the codec readu to go?
- setup()¶
Dispach the given parameters to the internal (FFmpeg) data structures.
- static wire(dec)¶
wire up the Decoder. See codec.wire_decoder
- class pyrana.audio.Encoder(output_codec, params)¶
Encode audio Frames into Packets.
- encode(frame)¶
Encode a logical frame in one or possibly more)packets, and return an iterable which will yield all the packets produced.
- extra_data¶
bytearray-like, read-write
- flush()¶
emits all packets which may have been buffered by the Encoder and empties such buffers. Call it last, do not intermix with encode*() calls. caution: more than one encoded frame (thus many packets) can be buffered. Raises NeedFeedError if all the internal buffers are empty.
- classmethod from_cdata(ctx, params, codec=None)¶
builds a pyrana audio Encoder from (around) a (cffi-wrapped) liabv* (audio) context. WARNING: raw access. Use with care.
- media_type¶
the codec media type.
- open(ffh=None)¶
opens the codec into the codec context.
- params¶
the codec parameters.
- ready¶
is the codec readu to go?
- static wire(enc)¶
wire up the Encoder. See codec.wire_encoder
- class pyrana.audio.Frame(rate, layout, samplefmt)¶
An Audio frame.
- cdata¶
Direct access to the internal C AVFrame object.
- classmethod from_cdata(ppframe)¶
builds a pyrana generic Base Frame from (around) a (cffi-wrapped) libav* AVFrame object. The libav object must be already initialized and ready to go. WARNING: raw access. Use with care.
- is_key¶
Is this a key frame?
- pts¶
The Presentation TimeStamp of this Frame.
- samples(smpfmt=None)¶
Returns a new Image object which provides access to the Picture (thus the pixel as bytes()) data.
- class pyrana.audio.Samples¶
Represents the Sample data inside a Frame.
- blob()¶
returns the bytes() dump of the object
- bps¶
Bytes per sample.
- channel(idx)¶
Read-only byte access to a single channel of the Samples.
- channels¶
The number of audio channels, only used for audio.
- convert(smpfmt)¶
convert the Samples data in a new SampleFormat. returns a brand new, independent Image.
- classmethod from_cdata(ppframe, swr=None, parent=None)¶
builds a pyrana Image from a (cffi-wrapped) libav* Frame object. The Picture data itself will still be hold in the Frame object. The libav object must be already initialized and ready to go. WARNING: raw access. Use with care.
Is the underlying C-Frame shared with the parent py-Frame?
- num_samples¶
The number of audio samples (per channel) described by this frame.
- sample_format¶
Frame sample format. Expected to be always equal to the stream sample format.
- sample_rate¶
Sample rate of the audio data.
- pyrana.audio.fill_s16(frame)¶
fill a audio frame with a single tone sound