Home
AV module

MultiplexEncoder

Multiplexing encoder that writes synchronized audio and video streams.

MultiplexEncoder

#include <icy/av/multiplexencoder.h>
class MultiplexEncoder

Defined in src/av/include/icy/av/multiplexencoder.h:41

Inherits: IEncoder Subclassed by: MultiplexPacketEncoder

Multiplexing encoder that writes synchronized audio and video streams.

List of all members

NameKindOwner
emittervariableDeclared here
MultiplexEncoderfunctionDeclared here
~MultiplexEncoderfunctionDeclared here
MultiplexEncoderfunctionDeclared here
operator=functionDeclared here
MultiplexEncoderfunctionDeclared here
operator=functionDeclared here
initfunctionDeclared here
uninitfunctionDeclared here
cleanupfunctionDeclared here
createVideofunctionDeclared here
freeVideofunctionDeclared here
encodeVideofunctionDeclared here
encodeVideofunctionDeclared here
encodeVideofunctionDeclared here
createAudiofunctionDeclared here
freeAudiofunctionDeclared here
encodeAudiofunctionDeclared here
encodeAudiofunctionDeclared here
flushfunctionDeclared here
optionsfunctionDeclared here
videofunctionDeclared here
audiofunctionDeclared here
_optionsvariableDeclared here
_formatCtxvariableDeclared here
_videovariableDeclared here
_audiovariableDeclared here
_ioCtxvariableDeclared here
_ioBuffervariableDeclared here
_videoPtsvariableDeclared here
_audioPtsvariableDeclared here
_mutexvariableDeclared here
writeOutputPacketfunctionDeclared here
updateStreamPtsfunctionDeclared here
onVideoEncodedfunctionDeclared here
onAudioEncodedfunctionDeclared here
initfunctionInherited from IEncoder
uninitfunctionInherited from IEncoder
cleanupfunctionInherited from IEncoder
optionsfunctionInherited from IEncoder
createVideofunctionInherited from IEncoder
freeVideofunctionInherited from IEncoder
encodeVideofunctionInherited from IEncoder
createAudiofunctionInherited from IEncoder
freeAudiofunctionInherited from IEncoder
flushfunctionInherited from IEncoder
isNonefunctionInherited from IEncoder
isReadyfunctionInherited from IEncoder
isEncodingfunctionInherited from IEncoder
isActivefunctionInherited from IEncoder
isStoppedfunctionInherited from IEncoder
isErrorfunctionInherited from IEncoder
TypeenumInherited from IEncoder
StateChangevariableInherited from Stateful
StatefulfunctionInherited from Stateful
~StatefulfunctionInherited from Stateful
stateEqualsfunctionInherited from Stateful
stateBetweenfunctionInherited from Stateful
statefunctionInherited from Stateful
statefunctionInherited from Stateful
_statevariableInherited from Stateful
beforeStateChangefunctionInherited from Stateful
onStateChangefunctionInherited from Stateful
setStatefunctionInherited from Stateful
setStatefunctionInherited from Stateful

Inherited from IEncoder

KindNameDescription
functioninit virtualInitialise the encoder, open codec contexts, and transition to Ready or Encoding state.
functionuninit virtualFlush remaining packets, close codec contexts, and release all encoder resources.
functioncleanup virtual inlinePerform any additional cleanup after uninit(). Default is a no-op.
functionoptions virtual const
functioncreateVideo virtual inlineInitialise the video codec context and stream.
functionfreeVideo virtual inlineFree the video codec context and stream.
functionencodeVideo virtual inlineEncode a single AVFrame of video.
functioncreateAudio virtual inlineInitialise the audio codec context and stream.
functionfreeAudio virtual inlineFree the audio codec context and stream.
functionflush virtual inlineFlush any internally buffered packets to the output.
functionisNone const inline
functionisReady const inline
functionisEncoding virtual const inline
functionisActive virtual const inline
functionisStopped virtual const inline
functionisError virtual const inline
enumType

Inherited from Stateful

KindNameDescription
variableStateChangeSignals when the state changes.
functionStateful inline
function~Stateful virtual inline
functionstateEquals virtual const inlineReturns true if the current state ID equals the given ID.
functionstateBetween virtual const inlineReturns true if the current state ID is in the inclusive range [lid, rid].
functionstate virtual inlineReturns a mutable reference to the current state.
functionstate virtual const inlineReturns a copy of the current state.
variable_state
functionbeforeStateChange virtual inlineOverride to handle pre state change logic. Return false to prevent state change.
functiononStateChange virtual inlineOverride to handle post state change logic.
functionsetState virtual inlineSets the state and sends the state signal if the state change was successful.
functionsetState virtual inlineSets the state and sends the state signal if the state change was successful.

Public Attributes

ReturnNameDescription
PacketSignalemitter

emitter

PacketSignal emitter

Defined in src/av/include/icy/av/multiplexencoder.h:130

Public Methods

ReturnNameDescription
MultiplexEncoderConstruct the encoder with the given options.
MultiplexEncoderDeleted constructor.
MultiplexEncoderDeleted constructor.
voidinit virtual overrideOpen the output container, create codec streams, and write the format header.
voiduninit virtual overrideFlush encoded packets, write the format trailer, and close the output container.
voidcleanup virtual overrideRelease all resources allocated by init() without writing a trailer.
voidcreateVideo virtual overrideCreate the video encoder and add the stream to the output container.
voidfreeVideo virtual overrideFlush and free the video encoder and its stream.
boolencodeVideo virtual overrideEncode 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 virtual overrideCreate the audio encoder and add the stream to the output container.
voidfreeAudio virtual overrideFlush and free the audio encoder and its stream.
boolencodeAudio virtualEncode a single interleaved audio frame.
boolencodeAudio virtualEncode a single planar audio frame.
voidflush virtual overrideFlush any buffered or queued packets to the output container.
const EncoderOptions &options virtual const override
VideoEncoder *video
AudioEncoder *audio

MultiplexEncoder

MultiplexEncoder(const EncoderOptions & options = EncoderOptions())

Defined in src/av/include/icy/av/multiplexencoder.h:46

Construct the encoder with the given options.

Parameters

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

MultiplexEncoder

MultiplexEncoder(const MultiplexEncoder &) = delete

Defined in src/av/include/icy/av/multiplexencoder.h:49

Deleted constructor.


MultiplexEncoder

MultiplexEncoder(MultiplexEncoder &&) = delete

Defined in src/av/include/icy/av/multiplexencoder.h:51

Deleted constructor.


init

virtual override

virtual void init() override

Defined in src/av/include/icy/av/multiplexencoder.h:55

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

Reimplements

uninit

virtual override

virtual void uninit() override

Defined in src/av/include/icy/av/multiplexencoder.h:58

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

Reimplements

cleanup

virtual override

virtual void cleanup() override

Defined in src/av/include/icy/av/multiplexencoder.h:61

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

Reimplements

createVideo

virtual override

virtual void createVideo() override

Defined in src/av/include/icy/av/multiplexencoder.h:64

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

Reimplements

freeVideo

virtual override

virtual void freeVideo() override

Defined in src/av/include/icy/av/multiplexencoder.h:67

Flush and free the video encoder and its stream.

Reimplements

encodeVideo

virtual override

virtual bool encodeVideo(AVFrame * frame) override

Defined in src/av/include/icy/av/multiplexencoder.h:71

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

Reimplements

encodeVideo

virtual

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

Defined in src/av/include/icy/av/multiplexencoder.h:83

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 = AV_NOPTS_VALUE)

Defined in src/av/include/icy/av/multiplexencoder.h:93

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 override

virtual void createAudio() override

Defined in src/av/include/icy/av/multiplexencoder.h:97

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

Reimplements

freeAudio

virtual override

virtual void freeAudio() override

Defined in src/av/include/icy/av/multiplexencoder.h:100

Flush and free the audio encoder and its stream.

Reimplements

encodeAudio

virtual

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

Defined in src/av/include/icy/av/multiplexencoder.h:107

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 = AV_NOPTS_VALUE)

Defined in src/av/include/icy/av/multiplexencoder.h:115

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 override

virtual void flush() override

Defined in src/av/include/icy/av/multiplexencoder.h:119

Flush any buffered or queued packets to the output container.

Reimplements

options

virtual const override

virtual const EncoderOptions & options() const override

Defined in src/av/include/icy/av/multiplexencoder.h:122

Returns

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

Reimplements

video

VideoEncoder * video()

Defined in src/av/include/icy/av/multiplexencoder.h:125

Returns

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


audio

AudioEncoder * audio()

Defined in src/av/include/icy/av/multiplexencoder.h:128

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_videoPts
int64_t_audioPts
std::mutex_mutex

_options

EncoderOptions _options

Defined in src/av/include/icy/av/multiplexencoder.h:144


_formatCtx

AVFormatContext * _formatCtx

Defined in src/av/include/icy/av/multiplexencoder.h:145


_video

std::unique_ptr< VideoEncoder > _video

Defined in src/av/include/icy/av/multiplexencoder.h:146


_audio

std::unique_ptr< AudioEncoder > _audio

Defined in src/av/include/icy/av/multiplexencoder.h:147


_ioCtx

AVIOContext * _ioCtx

Defined in src/av/include/icy/av/multiplexencoder.h:148


_ioBuffer

std::unique_ptr< uint8_t[]> _ioBuffer

Defined in src/av/include/icy/av/multiplexencoder.h:149


_videoPts

int64_t _videoPts

Defined in src/av/include/icy/av/multiplexencoder.h:150


_audioPts

int64_t _audioPts

Defined in src/av/include/icy/av/multiplexencoder.h:151


_mutex

std::mutex _mutex

Defined in src/av/include/icy/av/multiplexencoder.h:152

Protected Methods

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

writeOutputPacket

bool writeOutputPacket(AVPacket & packet)

Defined in src/av/include/icy/av/multiplexencoder.h:133


updateStreamPts

bool updateStreamPts(AVStream * stream, int64_t * pts)

Defined in src/av/include/icy/av/multiplexencoder.h:139

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)

Defined in src/av/include/icy/av/multiplexencoder.h:141


onAudioEncoded

void onAudioEncoded(av::AudioPacket & packet)

Defined in src/av/include/icy/av/multiplexencoder.h:142