codec

Common code shared by audio and video codecs. This module is not part of the pyrana public API.

class pyrana.codec.BaseDecoder(input_codec, params=None, delay_open=False)

Decoder base class. Common both to audio and video decoders.

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.

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 Decoder from (around) a (cffi-wrapped) libav* decoder object. The libav object must be already initialized and ready to go. WARNING: raw access. Use with care.

open(ffh=None)

opens the codec into the codec context.

class pyrana.codec.BaseEncoder(output_codec, params, delay_open=False)

Encoder base class. Common both to audio and video encoders.

encode(frame)

Encode a logical frame in one or possibly more)packets, and return an iterable which will yield all the packets produced.

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 Encoder from (around) a (cffi-wrapped) libav* decoder object. The libav object must be already initialized and ready to go. WARNING: raw access. Use with care.

class pyrana.codec.BaseFrame

Abstract Frame class. Provides bookkeeping and access to attributes common to frames of all media types. Do not use directly.

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.

class pyrana.codec.CodecFlag

wrapper for the (wannabe) enum in avcodec.h CODEC_FLAG_*

class pyrana.codec.CodecFlag2

wrapper for the (wannabe) enum in avcodec.h CODEC_FLAG2_*

class pyrana.codec.CodecMixin(params=None)

Mixin. Abstracts the common codec attributes: parameters reference, read-only access, extradata management.

extra_data

bytearray-like, read-write

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.

class pyrana.codec.Payload

Generic media-agnostic frame payload.

blob()

returns the bytes() dump of the object.

pyrana.codec.bind_frame(*args, **kwds)

allocates an AVFrame and cleans it up on exception.

pyrana.codec.find_encoder(output_codec, ffh=None)

Finds a suitable encoder for the given output codec. Raises SetupError if the codec isn’t supported.

pyrana.codec.make_codec(vcodec, acodec, stream_id, ctx, *args)

builds the right decoder for a given stream of an AVCodecContext.

pyrana.codec.make_fetcher(seq)

Builds a callable which extracts, deletes from the originating sequence-like (either materialized or generating) and returns an item.

pyrana.codec.make_payload(cls, ffh, ppframe, parent)

Setups the common fields of every multimedia payload object.

pyrana.codec.wire_decoder(dec, av_decode, new_frame, mtype)

Injects the specific decoding hooks in a generic decoder.

pyrana.codec.wire_encoder(enc, av_encode, mtype)

Injects the specific encoding hooks in a generic encoder.