MultiplexEncoder
MultiplexEncoder
#include <icy/av/multiplexencoder.h>Inherits:
IEncoderSubclassed by:MultiplexPacketEncoder
Multiplexing encoder that writes synchronized audio and video streams.
Public Attributes
| Return | Name | Description |
|---|---|---|
PacketSignal | emitter |
emitter
PacketSignal emitterPublic Methods
| Return | Name | Description |
|---|---|---|
MultiplexEncoder | Construct the encoder with the given options. | |
MultiplexEncoder | Deleted constructor. | |
MultiplexEncoder | Deleted constructor. | |
void | init virtual | Open the output container, create codec streams, and write the format header. |
void | uninit virtual | Flush encoded packets, write the format trailer, and close the output container. |
void | cleanup virtual | Release all resources allocated by init() without writing a trailer. |
void | createVideo virtual | Create the video encoder and add the stream to the output container. |
void | freeVideo virtual | Flush and free the video encoder and its stream. |
bool | encodeVideo virtual | Encode a single video frame. All frame values must be set, such as size, pixel format, and PTS. |
bool | encodeVideo virtual | 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. |
bool | encodeVideo virtual | Encode a single planar video frame. |
void | createAudio virtual | Create the audio encoder and add the stream to the output container. |
void | freeAudio virtual | Flush and free the audio encoder and its stream. |
bool | encodeAudio virtual | Encode a single interleaved audio frame. |
bool | encodeAudio virtual | Encode a single planar audio frame. |
void | flush virtual | Flush 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
optionsThe encoder configuration (input/output formats and file paths).
MultiplexEncoder
MultiplexEncoder(const MultiplexEncoder &) = deleteDeleted constructor.
MultiplexEncoder
MultiplexEncoder(MultiplexEncoder &&) = deleteDeleted 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
bufferThe raw video frame buffer.bufferSizeThe buffer size in bytes.widthThe frame width in pixels.heightThe frame height in pixels.timeThe 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
dataArray of per-plane data pointers (up to 4 planes).linesizeArray of per-plane byte strides.widthThe frame width in pixels.heightThe frame height in pixels.timeThe 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
bufferThe interleaved audio sample buffer.numSamplesThe number of samples per channel.timeThe 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
dataArray of per-plane sample buffers (one per channel).numSamplesThe number of samples per channel.timeThe 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() constReturns
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
| Return | Name | Description |
|---|---|---|
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 _mutexProtected Methods
| Return | Name | Description |
|---|---|---|
bool | writeOutputPacket | |
bool | updateStreamPts | Convert input microseconds to the stream time base. |
void | onVideoEncoded | |
void | onAudioEncoded |
writeOutputPacket
bool writeOutputPacket(AVPacket & packet)updateStreamPts
bool updateStreamPts(AVStream * stream, int64_t * pts)Convert input microseconds to the stream time base.
Parameters
streamThe target stream for time base conversion.ptsPointer to the timestamp; converted in place.
onVideoEncoded
void onVideoEncoded(av::VideoPacket & packet)onAudioEncoded
void onAudioEncoded(av::AudioPacket & packet)