Home
AV module

AudioEncoder

Encodes raw audio samples into a compressed format.

AudioEncoder

#include <icy/av/audioencoder.h>

Inherits: AudioContext Subclassed by: AudioPacketEncoder

Encodes raw audio samples into a compressed format.

Public Attributes

ReturnNameDescription
av::AudioBufferfifo
AVFormatContext *format
int64_tnextOutputPtsRunning PTS counter for encoder output, in encoder time_base units. Anchored to the first input packet's PTS, then advanced by frame->nb_samples per encoded frame. AV_NOPTS_VALUE before anchoring.

fifo

av::AudioBuffer fifo

format

AVFormatContext * format

nextOutputPts

int64_t nextOutputPts = AV_NOPTS_VALUE

Running PTS counter for encoder output, in encoder time_base units. Anchored to the first input packet's PTS, then advanced by frame->nb_samples per encoded frame. AV_NOPTS_VALUE before anchoring.

Public Methods

ReturnNameDescription
AudioEncoderConstruct an encoder, optionally tied to an existing muxer context.
voidcreate virtualInitialise the AVCodecContext using oparams. Adds an audio stream to format if one was provided at construction.
voidclose virtualClose and free the AVCodecContext, FIFO buffer, and associated resources.
boolencode virtualEncode interleaved audio samples.
boolencode virtualEncode planar audio samples.
boolencode virtualEncode a single AVFrame (typically from a decoder or resampler).
voidflush virtualFlush remaining packets to be encoded. This method should be called once before stream closure.

AudioEncoder

AudioEncoder(AVFormatContext * format)

Construct an encoder, optionally tied to an existing muxer context.

Parameters

  • format The AVFormatContext that will receive encoded packets, or nullptr for standalone use.

create

virtual

virtual void create()

Initialise the AVCodecContext using oparams. Adds an audio stream to format if one was provided at construction.


close

virtual

virtual void close()

Close and free the AVCodecContext, FIFO buffer, and associated resources.


encode

virtual

virtual bool encode(uint8_t * samples, const int numSamples, const int64_t pts)

Encode interleaved audio samples.

Parameters

  • samples The input samples to encode.

  • numSamples The number of input samples per channel.

  • pts The input samples presentation timestamp.


encode

virtual

virtual bool encode(uint8_t * samples, const int numSamples, const int64_t pts)

Encode planar audio samples.

Parameters

  • samples The input samples to encode.

  • numSamples The number of input samples per channel.

  • pts The input samples presentation timestamp.


encode

virtual

virtual bool encode(AVFrame * iframe)

Encode a single AVFrame (typically from a decoder or resampler).

Parameters

  • iframe The source audio frame with all fields set.

Returns

True if an encoded packet was produced and emitted.


flush

virtual

virtual void flush()

Flush remaining packets to be encoded. This method should be called once before stream closure.