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

Configuration for the (single) video track written by MuxerAVI. More...

#include <ContainerAVI.h>

Inheritance diagram for MuxerAVI:
Muxer VideoOutput

Public Member Functions

 MuxerAVI ()
 
 MuxerAVI (Print &out)
 
size_t addAudioFrame (const uint8_t *data, size_t len) override
 
size_t addI420Frame (const uint8_t *data, size_t len) override
 
size_t addJpegFrame (const uint8_t *data, size_t len) override
 
size_t addRGB565Frame (const uint8_t *data, size_t len) override
 
size_t addVideoFrame (const uint8_t *data, size_t len, bool isKeyFrame=true) override
 
size_t addYUV422Frame (const uint8_t *data, size_t len) override
 
uint32_t audioChunkCount ()
 Number of audio chunks written so far.
 
AudioInfoFormataudioInfo () override
 Provides read/write access to the audio track's AudioInfoFormat.
 
bool begin () override
 
void beginFrame (size_t size)
 
void end () override
 Closes the encoder: no trailer is written (streaming AVI has no idx1)
 
uint32_t endFrame ()
 Closes the current video frame (word-aligns the chunk)
 
virtual void flush ()
 
float getAudioSamplesPerVideoFrame ()
 
MuxerVideoConfig getVideoInfo () override
 
const char * mime () override
 
 operator bool () override
 
void setAudioInfo (AudioInfoFormat info) override
 
void setOutput (Print &out) override
 Defines the output: e.g. a local File or a network Client.
 
void setStreamType (StreamContentType type) override
 
void setVideoInfo (MuxerVideoConfig config) override
 Defines the video track configuration - call before begin()
 
StreamContentType streamType () override
 The track write() currently targets (see setStreamType())
 
uint32_t videoFrameCount ()
 Number of video frames written so far.
 
size_t write (const uint8_t *data, size_t len) override
 
size_t writeFrame (const uint8_t *data, size_t len)
 

Protected Member Functions

uint32_t audioStrlSize ()
 
uint16_t biBitCount ()
 
uint32_t biSizeImage ()
 
void checkRawFrame (VideoFormat expected, size_t len)
 
void checkVideoFormat (VideoFormat expected)
 
size_t expectedRawFrameSize (VideoFormat format)
 
const char * fourCC ()
 
bool isBitfields ()
 
uint32_t videoStrfSize ()
 
uint32_t videoStrlSize ()
 
void writeAudioStrl ()
 
void writeBiCompression ()
 
void writeChunkHeader (const char *id, uint32_t size)
 
void writeFourCC (const char *cc)
 
void writeHeader ()
 
void writeI16 (int16_t v)
 
void writeMainHeader ()
 
void writeU16 (uint16_t v)
 
void writeU32 (uint32_t v)
 
void writeU8 (uint8_t v)
 
void writeVideoStrl ()
 
void writeZeros (int n)
 

Protected Attributes

uint32_t audio_chunk_count = 0
 
AudioInfoFormat audio_info
 
bool frame_open = false
 
bool frame_pad = false
 
size_t frame_remaining = 0
 
bool has_audio = false
 
bool is_open = false
 
Printp_out = nullptr
 
Printp_print = nullptr
 
MuxerVideoConfig video_cfg
 
uint32_t video_frame_count = 0
 
StreamContentType write_stream_type = StreamContentType::Video
 

Static Protected Attributes

static const uint32_t AVIF_ISINTERLEAVED = 0x00000100
 

Detailed Description

Configuration for the (single) video track written by MuxerAVI.

AVI Container Encoder: muxes an already-encoded video stream (e.g. H.264 access units) and an optional PCM/compressed audio stream into a RIFF/AVI 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).

This is a streaming writer: since the total number of frames/bytes is usually not known upfront, the RIFF/movi sizes and stream dwLength fields are written as "unknown" (0xFFFFFFFF) and no idx1 index is appended - the same technique used by live IP-camera AVI/MJPEG streams. This is sufficient for sequential playback (ffplay/VLC/mpv opening the stream, or a file written for later playback) but the result is not seekable. All structural sizes a parser needs while walking the file sequentially (avih/strh/strf chunk sizes, hdrl LIST size) are written exactly.

Note
Classic AVI has no official H.264 standardization (unlike MP4/TS): common players (VLC, ffplay, mpv) handle "H264-in-AVI" fine, but it is not as universally supported as fragmented MP4 or MPEG-TS (e.g. it will not play in a browser <video> tag).

Usage:

MuxerAVI avi(client); // any Print: File, WiFiClient, ...
cfg.width = 640;
cfg.height = 480;
cfg.fps = 25;
avi.setVideoInfo(cfg);
avi.begin();
// for each encoded H.264 access unit:
avi.addVideoFrame(h264_data, h264_len);
Configuration for the (single) video track written by MuxerAVI.
Definition ContainerAVI.h:906
Shared video track configuration for muxers (MuxerAVI, MuxerMP4) - call before begin().
Definition ContainerCommon.h:11
float fps
Definition ContainerCommon.h:14
uint16_t height
Definition ContainerCommon.h:13
uint16_t width
Definition ContainerCommon.h:12
VideoFormat format
Definition ContainerCommon.h:15
Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ MuxerAVI() [1/2]

MuxerAVI ( )
inline

◆ MuxerAVI() [2/2]

MuxerAVI ( Print out)
inline

Member Function Documentation

◆ addAudioFrame()

size_t addAudioFrame ( const uint8_t *  data,
size_t  len 
)
inlineoverridevirtual

Writes one interleaved audio block as a single '01wb' chunk. Ignored (returns 0) if no audio track was configured via setAudioInfo().

Implements Muxer.

◆ addI420Frame()

size_t addI420Frame ( const uint8_t *  data,
size_t  len 
)
inlineoverridevirtual

Writes one planar 4:2:0 YUV (I420/IYUV) frame: a full-resolution Y plane followed by quarter-resolution U and V planes. Expects exactly width*height*3/2 bytes.

Implements Muxer.

◆ addJpegFrame()

size_t addJpegFrame ( const uint8_t *  data,
size_t  len 
)
inlineoverridevirtual

Writes one complete Motion-JPEG frame: a full, already-encoded JPEG image (e.g. as produced by an ESP32-CAM or other hardware JPEG encoder). Length is inherently variable, so only the configured format is validated, not the size.

Implements Muxer.

◆ addRGB565Frame()

size_t addRGB565Frame ( const uint8_t *  data,
size_t  len 
)
inlineoverridevirtual

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

Implements Muxer.

◆ addVideoFrame()

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

Convenience: writes one complete, already-encoded video frame (e.g. one H.264 access unit, or one raw pixel buffer) as a single '00dc' chunk. Works for any VideoFormat - the format-specific addXxxFrame() methods below are thin wrappers that additionally validate the format and (for fixed-size raw formats) the buffer length.

Parameters
isKeyFrameaccepted for interface compatibility with Muxer::addVideoFrame() - AVI has no per-frame sync-sample flag to write it into, so it is ignored.

Implements Muxer.

◆ addYUV422Frame()

size_t addYUV422Frame ( const uint8_t *  data,
size_t  len 
)
inlineoverridevirtual

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

Implements Muxer.

◆ audioChunkCount()

uint32_t audioChunkCount ( )
inline

Number of audio chunks written so far.

◆ audioInfo()

AudioInfoFormat & audioInfo ( )
inlineoverridevirtual

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

Implements Muxer.

◆ audioStrlSize()

uint32_t audioStrlSize ( )
inlineprotected

Bytes following the audio strl LIST's own size field (only valid if has_audio)

◆ begin()

bool begin ( )
inlineoverridevirtual

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

Implements Muxer.

◆ beginFrame()

void beginFrame ( size_t  size)
inline

Starts a new video ('00dc') chunk of the given size. This is MuxerAVI's own API for incremental frame construction (not part of the VideoOutput interface - RIFF chunks are length-prefixed, so the size must be known upfront, unlike the write()/flush() contract VideoOutput consumers use).

◆ biBitCount()

uint16_t biBitCount ( )
inlineprotected

Bits per pixel written into biBitCount; purely informational for compressed formats

◆ biSizeImage()

uint32_t biSizeImage ( )
inlineprotected

biSizeImage: the uncompressed buffer size for raw formats, 0 (unknown/ variable) for compressed ones

◆ checkRawFrame()

void checkRawFrame ( VideoFormat  expected,
size_t  len 
)
inlineprotected

Validates both the configured format and (for fixed-size raw formats) that len matches width*height based expectations

◆ checkVideoFormat()

void checkVideoFormat ( VideoFormat  expected)
inlineprotected

Logs a warning if getVideoInfo().format was not set to the format that an addXxxFrame() convenience method was called for

◆ end()

void end ( )
inlineoverridevirtual

Closes the encoder: no trailer is written (streaming AVI has no idx1)

Implements Muxer.

◆ endFrame()

uint32_t endFrame ( )
inline

Closes the current video frame (word-aligns the chunk)

◆ expectedRawFrameSize()

size_t expectedRawFrameSize ( VideoFormat  format)
inlineprotected

Number of raw bytes a single frame must have for the given (uncompressed, fixed-size) format; 0 for compressed/variable-size formats where this check does not apply

◆ flush()

virtual void flush ( )
inlinevirtualinherited

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.

◆ fourCC()

const char * fourCC ( )
inlineprotected

◆ getAudioSamplesPerVideoFrame()

float getAudioSamplesPerVideoFrame ( )
inlineinherited

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()

MuxerVideoConfig getVideoInfo ( )
inlineoverridevirtual

Provides the video track configuration, analogous to DemuxerAVI's getVideoInfo() getter.

Implements Muxer.

◆ isBitfields()

bool isBitfields ( )
inlineprotected

True if this format is written as uncompressed RGB565 using BI_BITFIELDS (which needs 3 extra DWORD color masks in 'strf')

◆ mime()

const char * mime ( )
inlineoverridevirtual

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.

Implements Muxer.

◆ operator bool()

operator bool ( )
inlineoverridevirtual

Implements Muxer.

◆ setAudioInfo()

void setAudioInfo ( AudioInfoFormat  info)
inlineoverridevirtual

Adds an (optional) interleaved audio track. 'info.format' selects the WAVEFORMATEX tag written for the audio track (default: AudioFormat::PCM). Only uncompressed PCM has been validated for playback in common players; other tags are written through as-is. Call before begin().

Implements Muxer.

◆ setOutput()

void setOutput ( Print out)
inlineoverridevirtual

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

Implements Muxer.

◆ setStreamType()

void setStreamType ( StreamContentType  type)
inlineoverridevirtual

Selects whether write() feeds the video or the audio track. Defaults to StreamContentType::Video; switch to StreamContentType::Audio (and back) around calls when using MuxerAVI as a plain sink for both.

Implements Muxer.

◆ setVideoInfo()

void setVideoInfo ( MuxerVideoConfig  config)
inlineoverridevirtual

Defines the video track configuration - call before begin()

Implements Muxer.

◆ streamType()

StreamContentType streamType ( )
inlineoverridevirtual

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

Implements Muxer.

◆ videoFrameCount()

uint32_t videoFrameCount ( )
inline

Number of video frames written so far.

◆ videoStrfSize()

uint32_t videoStrfSize ( )
inlineprotected

Size of the 'strf' chunk payload: the base 40-byte BITMAPINFOHEADER, plus 3 extra DWORD color masks for BI_BITFIELDS formats (RGB565)

◆ videoStrlSize()

uint32_t videoStrlSize ( )
inlineprotected

Bytes following the video strl LIST's own size field: the "strl" list-type FOURCC plus the nested strh/strf chunks (each incl. header)

◆ write()

size_t write ( const uint8_t *  data,
size_t  len 
)
inlineoverridevirtual

VideoOutput API / generic sink: writes one complete frame to whichever track streamType() currently selects (see setStreamType()). For video, dispatches to the addXxxFrame() matching getVideoInfo().format; for audio, calls addAudioFrame(). Lets MuxerAVI be used as a plain one-call-per-frame Print-like sink (e.g. from a camera driver, or an audio encoder) without the caller needing to know which addXxxFrame() applies.

Implements VideoOutput.

◆ writeAudioStrl()

void writeAudioStrl ( )
inlineprotected

◆ writeBiCompression()

void writeBiCompression ( )
inlineprotected

Writes the biCompression field: numeric BI_RGB(0)/BI_BITFIELDS(3) for uncompressed RGB, or the FOURCC codec tag for everything else

◆ writeChunkHeader()

void writeChunkHeader ( const char *  id,
uint32_t  size 
)
inlineprotected

◆ writeFourCC()

void writeFourCC ( const char *  cc)
inlineprotected

◆ writeFrame()

size_t writeFrame ( const uint8_t *  data,
size_t  len 
)
inline

Appends data to the currently open video frame - requires a prior beginFrame() (and a later endFrame()); use this for incremental/ streaming sources that hand over a frame in pieces. For a single complete frame per call, use write() (dispatches by getVideoInfo().format) or one of the addXxxFrame() methods instead.

◆ writeHeader()

void writeHeader ( )
inlineprotected

◆ writeI16()

void writeI16 ( int16_t  v)
inlineprotected

◆ writeMainHeader()

void writeMainHeader ( )
inlineprotected

◆ writeU16()

void writeU16 ( uint16_t  v)
inlineprotected

◆ writeU32()

void writeU32 ( uint32_t  v)
inlineprotected

◆ writeU8()

void writeU8 ( uint8_t  v)
inlineprotected

◆ writeVideoStrl()

void writeVideoStrl ( )
inlineprotected

◆ writeZeros()

void writeZeros ( int  n)
inlineprotected

Member Data Documentation

◆ audio_chunk_count

uint32_t audio_chunk_count = 0
protected

◆ audio_info

AudioInfoFormat audio_info
protected

◆ AVIF_ISINTERLEAVED

const uint32_t AVIF_ISINTERLEAVED = 0x00000100
staticprotected

◆ frame_open

bool frame_open = false
protected

◆ frame_pad

bool frame_pad = false
protected

◆ frame_remaining

size_t frame_remaining = 0
protected

◆ has_audio

bool has_audio = false
protected

◆ is_open

bool is_open = false
protected

◆ p_out

Print* p_out = nullptr
protected

◆ p_print

Print* p_print = nullptr
protectedinherited

◆ video_cfg

MuxerVideoConfig video_cfg
protected

◆ video_frame_count

uint32_t video_frame_count = 0
protected

◆ write_stream_type

StreamContentType write_stream_type = StreamContentType::Video
protected

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