arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members

Common interface for muxers (MuxerAVI, MuxerMP4) that combine an already-encoded video track (and optionally an audio track) into a container written to a Print (a local File to record, or e.g. a network Client to publish a live stream to an HTTP/TCP client). Write code against this interface instead of a concrete class if it should work with either container format. More...

#include <ContainerCommon.h>

Inheritance diagram for Muxer:
VideoOutput MuxerAVI MuxerMP4 MuxerMPG

Public Member Functions

virtual size_t addAudioFrame (const uint8_t *data, size_t len)=0
 
virtual size_t addI420Frame (const uint8_t *data, size_t len)=0
 
virtual size_t addJpegFrame (const uint8_t *data, size_t len)=0
 
virtual size_t addRGB565Frame (const uint8_t *data, size_t len)=0
 
virtual size_t addVideoFrame (const uint8_t *data, size_t len, bool isKeyFrame=true)=0
 
virtual size_t addYUV422Frame (const uint8_t *data, size_t len)=0
 
virtual AudioInfoFormataudioInfo ()=0
 Provides read/write access to the audio track's AudioInfoFormat.
 
virtual bool begin ()=0
 
virtual void end ()=0
 Closes the muxer.
 
virtual void flush ()
 
float getAudioSamplesPerVideoFrame ()
 
virtual MuxerVideoConfig getVideoInfo ()=0
 Provides the video track configuration.
 
virtual uint32_t getWriteTimeMs () const
 Optional: returns the time (ms) spent in the last write() call.
 
virtual bool hadOutput () const
 
virtual bool isKeyFrame (const uint8_t *data, size_t len)
 
virtual const char * mimeVideo ()=0
 
virtual operator bool ()=0
 
virtual void setAudioInfo (AudioInfoFormat info)=0
 
virtual void setOutput (Print &out)=0
 Defines the output: e.g. a local File or a network Client.
 
virtual void setSkipRender (bool skip)
 
virtual void setStreamType (StreamContentType type)=0
 Selects whether write() feeds the video or the audio track.
 
virtual void setVideoInfo (MuxerVideoConfig config)=0
 Defines the video track configuration - call before begin()
 
virtual void setVideoInfoSource (VideoInfoSource &source)
 
virtual StreamContentType streamType ()=0
 The track write() currently targets (see setStreamType())
 
virtual uint64_t totalDecodeMs () const
 
virtual size_t write (const uint8_t *data, size_t len)=0
 

Protected Attributes

Printp_print = nullptr
 

Detailed Description

Common interface for muxers (MuxerAVI, MuxerMP4) that combine an already-encoded video track (and optionally an audio track) into a container written to a Print (a local File to record, or e.g. a network Client to publish a live stream to an HTTP/TCP client). Write code against this interface instead of a concrete class if it should work with either container format.

write() (VideoOutput) treats each call as one complete, already-encoded frame for both MuxerAVI and MuxerMP4 - callers must hand over the full frame in a single call, not build it up incrementally across several write() calls. flush() is a no-op for both.

Author
Phil Schatzmann

Member Function Documentation

◆ addAudioFrame()

virtual size_t addAudioFrame ( const uint8_t *  data,
size_t  len 
)
pure virtual

Writes one complete audio frame/block. Meaning is container- and codec-specific (e.g. one raw AAC frame vs. an arbitrary PCM block); see the concrete class.

Implemented in MuxerAVI, MuxerMP4, and MuxerMPG.

◆ addI420Frame()

virtual size_t addI420Frame ( const uint8_t *  data,
size_t  len 
)
pure virtual

Writes one planar 4:2:0 YUV (I420/IYUV) frame. Expects exactly width*height*3/2 bytes.

Implemented in MuxerAVI, MuxerMP4, and MuxerMPG.

◆ addJpegFrame()

virtual size_t addJpegFrame ( const uint8_t *  data,
size_t  len 
)
pure virtual

Writes one complete Motion-JPEG frame (a full, already-encoded JPEG image).

Implemented in MuxerAVI, MuxerMP4, and MuxerMPG.

◆ addRGB565Frame()

virtual size_t addRGB565Frame ( const uint8_t *  data,
size_t  len 
)
pure virtual

Writes one uncompressed RGB565 (16-bit, 5-6-5) frame. Expects exactly width*height*2 bytes.

Implemented in MuxerAVI, MuxerMP4, and MuxerMPG.

◆ addVideoFrame()

virtual size_t addVideoFrame ( const uint8_t *  data,
size_t  len,
bool  isKeyFrame = true 
)
pure virtual

Writes one complete, already-encoded video frame (e.g. one H.264 access unit).

Parameters
isKeyFramehints that the frame is independently decodable (a sync/seek point) - used where the container format can express it (e.g. MP4's 'trun' sample flags); ignored where it can't (AVI).

Implemented in MuxerAVI, MuxerMP4, and MuxerMPG.

◆ addYUV422Frame()

virtual size_t addYUV422Frame ( const uint8_t *  data,
size_t  len 
)
pure virtual

Writes one packed 4:2:2 YUV frame (YUY2/YUYV byte order). Expects exactly width*height*2 bytes.

Implemented in MuxerAVI, MuxerMP4, and MuxerMPG.

◆ audioInfo()

virtual AudioInfoFormat & audioInfo ( )
pure virtual

Provides read/write access to the audio track's AudioInfoFormat.

Implemented in MuxerAVI, MuxerMP4, and MuxerMPG.

◆ begin()

virtual bool begin ( )
pure virtual

Writes the container header. Call after configuring video (and audio, if any) and before writing any frames.

Implemented in MuxerAVI, MuxerMP4, and MuxerMPG.

◆ end()

virtual void end ( )
pure virtual

Closes the muxer.

Implemented in MuxerAVI, MuxerMP4, and MuxerMPG.

◆ flush()

virtual void flush ( )
inlinevirtual

Finalizes the frame most recently written via one or more write() calls - see class comment. Default no-op for implementations that display/decode synchronously in write() instead.

Reimplemented from VideoOutput.

◆ getAudioSamplesPerVideoFrame()

float getAudioSamplesPerVideoFrame ( )
inline

Average number of audio samples per video frame, derived from audioInfo().sample_rate and getVideoInfo().fps - the natural audio chunk size to write once per video frame if you want to keep both tracks advancing at roughly the same pace as you write them (not a hard requirement - see addAudioFrame()/addVideoFrame()). 0 if fps hasn't been set.

◆ getVideoInfo()

virtual MuxerVideoConfig getVideoInfo ( )
pure virtual

Provides the video track configuration.

Implemented in MuxerAVI, MuxerMP4, and MuxerMPG.

◆ getWriteTimeMs()

virtual uint32_t getWriteTimeMs ( ) const
inlinevirtualinherited

Optional: returns the time (ms) spent in the last write() call.

Reimplemented in OutputTFT_eSPI, OutputTinyGPU, and OutputOpenCV.

◆ hadOutput()

virtual bool hadOutput ( ) const
inlinevirtualinherited

True if the most recent write()+flush() call actually produced a displayable picture - default true, matching every synchronous decoder (H264Decoder, MJPEGDecoder, ...), which always decodes and pushes pixels fully within that one call. Override this only if your decoder can legitimately accept/decode a frame's bytes without emitting a picture during that same call - e.g. MPGDecoder, whose B-picture display-order reordering can hold a just-decoded picture back and instead emit an earlier one (or nothing at all) from a given write(), see its own override. Used by PacedVideoOutput to avoid counting/timing a call that did no real rendering work as a rendered frame - without this, its outputFPS()/frameCountI()/ frameCountP()/avgFrameMs() would overcount for such a decoder.

Reimplemented in MPGDecoder.

◆ isKeyFrame()

virtual bool isKeyFrame ( const uint8_t *  data,
size_t  len 
)
inlinevirtualinherited

True if data (one complete encoded frame, as handed to write()) is a keyframe/sync-sample - self-contained, decodable without any earlier frame. Used e.g. by PacedVideoOutput to decide which frames are safe to drop, and whether it's safe to resume decoding after abandoning a backlog (see its own class comment). Default false: a plain VideoOutput doesn't know or care about codec structure - override this in a decoder for the bitstream format it actually parses (see H264Decoder/H264DecoderESP32S3's isH264KeyFrame()-based override, MPGDecoder's isMpeg1KeyFrame()- based one). Getting this right matters beyond bookkeeping: a target whose frames are never recognized as keyframes can leave a caller like PacedVideoOutput unable to ever resume after a resync.

Reimplemented in PacedVideoOutput, H264Decoder, H264DecoderESP32S3< Alloc >, MJPEGDecoder, MPGDecoder, MultiVideoDecoder, and OutputFPSMeter.

◆ mimeVideo()

virtual const char * mimeVideo ( )
pure virtual

The container's MIME type (e.g. "video/avi", "video/mp4") - useful for e.g. an HTTP Content-Type header when streaming the muxed output to a client.

Implemented in MuxerAVI, MuxerMP4, and MuxerMPG.

◆ operator bool()

virtual operator bool ( )
pure virtual

Implemented in MuxerAVI, MuxerMP4, and MuxerMPG.

◆ setAudioInfo()

virtual void setAudioInfo ( AudioInfoFormat  info)
pure virtual

Adds an (optional) interleaved audio track, including the codec selection (the 'format' field) - which AudioFormat values are actually supported (and what they mean, e.g. default codec if unset) is container-specific; see the concrete class. Call before begin().

Implemented in MuxerAVI, MuxerMP4, and MuxerMPG.

◆ setOutput()

virtual void setOutput ( Print out)
pure virtual

Defines the output: e.g. a local File or a network Client.

Implemented in MuxerAVI, MuxerMP4, and MuxerMPG.

◆ setSkipRender()

virtual void setSkipRender ( bool  skip)
inlinevirtualinherited

Hint to skip the expensive part of displaying the next frame(s) (e.g. the panel refresh) while still accepting and fully processing write() calls - used to recover from falling behind the playback schedule without breaking a codec's decode state (e.g. H.264 inter-prediction reference chain, which requires every frame to still be decoded even if it's never shown). Default no-op: implementations that can't skip rendering cheaply just ignore it and always render.

Reimplemented in MultiVideoDecoder, OutputFPSMeter, OutputTinyGPU, PacedVideoOutput, and VideoFrameMeter.

◆ setStreamType()

virtual void setStreamType ( StreamContentType  type)
pure virtual

Selects whether write() feeds the video or the audio track.

Implemented in MuxerAVI, MuxerMP4, and MuxerMPG.

◆ setVideoInfo()

virtual void setVideoInfo ( MuxerVideoConfig  config)
pure virtual

Defines the video track configuration - call before begin()

Implemented in MuxerAVI, MuxerMP4, and MuxerMPG.

◆ setVideoInfoSource()

virtual void setVideoInfoSource ( VideoInfoSource source)
inlinevirtualinherited

Optional: registers where width/height/fps/format (VideoInfo) come from - e.g. the demuxer feeding this output, so it can size its own buffers/panel setup without the caller having to duplicate that call per sketch (VideoPlayer::begin() does this automatically for whichever VideoOutput it was given). Default no-op: only implementations that actually need VideoInfo (OutputTinyGPU/ OutputOpenCV/OutputTFT_eSPI) override this.

Reimplemented in MultiVideoDecoder, OutputOpenCV, OutputTFT_eSPI, and OutputTinyGPU.

◆ streamType()

virtual StreamContentType streamType ( )
pure virtual

The track write() currently targets (see setStreamType())

Implemented in MuxerAVI, MuxerMP4, and MuxerMPG.

◆ totalDecodeMs()

virtual uint64_t totalDecodeMs ( ) const
inlinevirtualinherited

Optional: sum of time (ms) spent purely decoding (excluding any surrounding convert/render/SPI work a subclass's write() also does) since begin() - see H264Decoder's own override for the only current implementation. Default 0: only meaningful for a decoder that separates decode time from render time internally: PacedVideoOutput:: logTo() prints a decode-vs-render split under "avg decode ms:" only when this returns nonzero.

Reimplemented in H264Decoder, and MultiVideoDecoder.

◆ write()

virtual size_t write ( const uint8_t *  data,
size_t  len 
)
pure virtualinherited

Member Data Documentation

◆ p_print

Print* p_print = nullptr
protected

The documentation for this class was generated from the following file: