AV module

MultiplexEncoder

Multiplexing encoder that writes synchronized audio and video streams.

MultiplexEncoder

#include <icy/av/multiplexencoder.h>

Inherits: IEncoder Subclassed by: MultiplexPacketEncoder

Multiplexing encoder that writes synchronized audio and video streams.

Public Attributes

ReturnNameDescription
PacketSignalemitter

emitter

PacketSignal emitter

Public Methods

ReturnNameDescription
MultiplexEncoderConstruct the encoder with the given options.
MultiplexEncoderDeleted constructor.
MultiplexEncoderDeleted constructor.
voidinit virtualOpen the output container, create codec streams, and write the format header.
voiduninit virtualFlush encoded packets, write the format trailer, and close the output container.
voidcleanup virtualRelease all resources allocated by init() without writing a trailer.
voidcreateVideo virtualCreate the video encoder and add the stream to the output container.
voidfreeVideo virtualFlush and free the video encoder and its stream.
boolencodeVideo virtualEncode a single video frame. All frame values must be set, such as size, pixel format, and PTS.
boolencodeVideo virtualEncode a single interleaved video frame. If the frame time is specified it should be the microseconds offset since the start of the input stream. If no time is specified a real-time value will be assigned to the frame.
boolencodeVideo virtualEncode a single planar video frame.
voidcreateAudio virtualCreate the audio encoder and add the stream to the output container.
voidfreeAudio virtualFlush and free the audio encoder and its stream.
boolencodeAudio virtualEncode a single interleaved audio frame.
boolencodeAudio virtualEncode a single planar audio frame.
voidflush virtualFlush any buffered or queued packets to the output container.
const EncoderOptions &options virtual const#### Returns
VideoEncoder *video#### Returns
AudioEncoder *audio#### Returns

MultiplexEncoder

MultiplexEncoder(const EncoderOptions & options)

Construct the encoder with the given options.

Parameters

  • options The encoder configuration (input/output formats and file paths).

MultiplexEncoder

MultiplexEncoder(const MultiplexEncoder &) = delete

Deleted constructor.


MultiplexEncoder

MultiplexEncoder(MultiplexEncoder &&) = delete

Deleted constructor.


init

virtual

virtual void init()

Open the output container, create codec streams, and write the format header.


uninit

virtual

virtual void uninit()

Flush encoded packets, write the format trailer, and close the output container.


cleanup

virtual

virtual void cleanup()

Release all resources allocated by init() without writing a trailer.


createVideo

virtual

virtual void createVideo()

Create the video encoder and add the stream to the output container.


freeVideo

virtual

virtual void freeVideo()

Flush and free the video encoder and its stream.


encodeVideo

virtual

virtual bool encodeVideo(AVFrame * frame)

Encode a single video frame. All frame values must be set, such as size, pixel format, and PTS.


encodeVideo

virtual

virtual bool encodeVideo(uint8_t * buffer, int bufferSize, int width, int height, int64_t time)

Encode a single interleaved video frame. If the frame time is specified it should be the microseconds offset since the start of the input stream. If no time is specified a real-time value will be assigned to the frame.

Parameters

  • buffer The raw video frame buffer.

  • bufferSize The buffer size in bytes.

  • width The frame width in pixels.

  • height The frame height in pixels.

  • time The timestamp in microseconds, or AV_NOPTS_VALUE for realtime.


encodeVideo

virtual

virtual bool encodeVideo(uint8_t * data, int linesize, int width, int height, int64_t time)

Encode a single planar video frame.

Parameters

  • data Array of per-plane data pointers (up to 4 planes).

  • linesize Array of per-plane byte strides.

  • width The frame width in pixels.

  • height The frame height in pixels.

  • time The timestamp in microseconds, or AV_NOPTS_VALUE for realtime.


createAudio

virtual

virtual void createAudio()

Create the audio encoder and add the stream to the output container.


freeAudio

virtual

virtual void freeAudio()

Flush and free the audio encoder and its stream.


encodeAudio

virtual

virtual bool encodeAudio(uint8_t * buffer, int numSamples, int64_t time)

Encode a single interleaved audio frame.

Parameters

  • buffer The interleaved audio sample buffer.

  • numSamples The number of samples per channel.

  • time The timestamp in microseconds, or AV_NOPTS_VALUE for realtime.


encodeAudio

virtual

virtual bool encodeAudio(uint8_t * data, int numSamples, int64_t time)

Encode a single planar audio frame.

Parameters

  • data Array of per-plane sample buffers (one per channel).

  • numSamples The number of samples per channel.

  • time The timestamp in microseconds, or AV_NOPTS_VALUE for realtime.


flush

virtual

virtual void flush()

Flush any buffered or queued packets to the output container.


options

virtual const

virtual const EncoderOptions & options() const

Returns

A read-only view of the encoder's configuration options.


video

VideoEncoder * video()

Returns

The active VideoEncoder, or nullptr if video has not been created.


audio

AudioEncoder * audio()

Returns

The active AudioEncoder, or nullptr if audio has not been created.

Protected Attributes

ReturnNameDescription
EncoderOptions_options
AVFormatContext *_formatCtx
std::unique_ptr< VideoEncoder >_video
std::unique_ptr< AudioEncoder >_audio
AVIOContext *_ioCtx
std::unique_ptr< uint8_t[]>_ioBuffer
int64_t_pts
std::mutex_mutex

_options

EncoderOptions _options

_formatCtx

AVFormatContext * _formatCtx

_video

std::unique_ptr< VideoEncoder > _video

_audio

std::unique_ptr< AudioEncoder > _audio

_ioCtx

AVIOContext * _ioCtx

_ioBuffer

std::unique_ptr< uint8_t[]> _ioBuffer

_pts

int64_t _pts

_mutex

std::mutex _mutex

Protected Methods

ReturnNameDescription
boolwriteOutputPacket
boolupdateStreamPtsConvert input microseconds to the stream time base.
voidonVideoEncoded
voidonAudioEncoded

writeOutputPacket

bool writeOutputPacket(AVPacket & packet)

updateStreamPts

bool updateStreamPts(AVStream * stream, int64_t * pts)

Convert input microseconds to the stream time base.

Parameters

  • stream The target stream for time base conversion.

  • pts Pointer to the timestamp; converted in place.


onVideoEncoded

void onVideoEncoded(av::VideoPacket & packet)

onAudioEncoded

void onAudioEncoded(av::AudioPacket & packet)