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

Feeds a Muxer (MuxerAVI, MuxerMP4, ...) from a single copy() call. More...

#include <VideoMuxer.h>

Public Member Functions

 VideoMuxer ()=default
 
 VideoMuxer (Muxer &muxer)
 
bool begin ()
 
size_t copy ()
 
void end ()
 Closes the Muxer.
 
void setAudioEncoder (AudioEncoder &encoder)
 
void setAudioInfo (AudioInfo info)
 
void setAudioSource (AudioStream &out)
 Defines the AudioSource that we can configure with setAudioInfo()
 
void setAudioSource (Stream &pcm)
 
void setMuxer (Muxer &muxer)
 Defines the Muxer copy() writes to - call before begin().
 
void setVideoEncoder (VideoEncoder &encoder)
 
void setVideoSource (VideoFrameSource &video)
 

Protected Member Functions

size_t copyAudio ()
 
bool copyVideo ()
 
bool copyVideoPaced ()
 

Protected Attributes

AudioInfo audio_info
 
uint64_t audio_samples_written = 0
 
uint32_t bytes_per_sample = 0
 
bool have_audio = false
 
bool have_video = false
 
Streamp_audio = nullptr
 
AudioEncoderp_audio_encoder = nullptr
 
Muxerp_muxer = nullptr
 
AudioInfoSupportp_source_audio_info = nullptr
 
VideoFrameSourcep_video = nullptr
 
VideoEncoderp_video_encoder = nullptr
 
uint32_t sample_rate = 0
 
float video_fps = 0
 
uint32_t video_frame_count = 0
 
uint32_t video_interval_ms = 33
 
MuxerVideoSink video_sink
 

Static Protected Attributes

static constexpr size_t kAudioReadChunkSize = 512
 

Detailed Description

Feeds a Muxer (MuxerAVI, MuxerMP4, ...) from a single copy() call.

setAudioSource() is what drives time, so it's effectively required for the faster-than-real-time benefit; without one, there's no audio time to derive video timing from, so copy() instead paces itself against wall-clock time via VideoFrameSource::videoInfo().fps (like VideoMuxerWithTasks's own video task does), compensating for time spent encoding so the real capture cadence matches the fps written into the Muxer's video track. Configuration (setAudioEncoder()/setAudioInfo()/setVideoSource()/ setVideoEncoder()) and what begin() derives/configures automatically work exactly like VideoMuxerWithTasks's own - see that class's comment for the details not repeated here. end() closes the Muxer.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ VideoMuxer() [1/2]

VideoMuxer ( )
default

◆ VideoMuxer() [2/2]

VideoMuxer ( Muxer muxer)
inline

Member Function Documentation

◆ begin()

bool begin ( )
inline

Configures the Muxer's video/audio tracks from the source/encoder objects above and calls Muxer::begin() - see VideoMuxerWithTasks's own begin() comment for exactly what that derives; the only Muxer setup still needed from the caller is Muxer::setOutput().

◆ copy()

size_t copy ( )
inline

With an audio source: reads and writes one PCM chunk, then mux/encodes however many video frames that much audio now covers (see class comment), returning the number of audio bytes processed - 0 once setAudioSource() has no more data, the signal to stop calling this. Without an audio source: pulls/writes exactly one video frame, paced against wall-clock time by VideoFrameSource::videoInfo().fps (see class comment), returning 1 (written) or 0 (setVideoSource() has none left/wasn't set).

◆ copyAudio()

size_t copyAudio ( )
inlineprotected

◆ copyVideo()

bool copyVideo ( )
inlineprotected

◆ copyVideoPaced()

bool copyVideoPaced ( )
inlineprotected

No-audio fallback: paces copyVideo() against wall-clock time via video_interval_ms, sleeping only the remainder of the interval left after encoding - same compensation VideoMuxerWithTasks's video task applies, so a slow encoder doesn't slip the real capture cadence behind the fps written into the Muxer's video track.

◆ end()

void end ( )
inline

Closes the Muxer.

◆ setAudioEncoder()

void setAudioEncoder ( AudioEncoder encoder)
inline

Defines the (optional) encoder each PCM chunk is handed to - responsible for framing and writing the encoded result to the Muxer itself; its setOutput() is pointed at the Muxer by begin(). Leave unset to write setAudioSource()'s PCM straight through instead (see setAudioInfo()).

◆ setAudioInfo()

void setAudioInfo ( AudioInfo  info)
inline

Defines the sample_rate/channels/bits_per_sample of setAudioSource()'s PCM data - only used (instead of AudioEncoder::audioInfo()) when no setAudioEncoder() was called. Call before begin().

◆ setAudioSource() [1/2]

void setAudioSource ( AudioStream out)
inline

Defines the AudioSource that we can configure with setAudioInfo()

◆ setAudioSource() [2/2]

void setAudioSource ( Stream pcm)
inline

Defines the raw PCM source copy() reads from - drives this class's timeline (see class comment). On its own (no setAudioEncoder()) each chunk is written to the Muxer as raw PCM - call setAudioInfo() too in that case.

◆ setMuxer()

void setMuxer ( Muxer muxer)
inline

Defines the Muxer copy() writes to - call before begin().

◆ setVideoEncoder()

void setVideoEncoder ( VideoEncoder encoder)
inline

Defines the (optional) encoder each raw picture from setVideoSource() is handed to - e.g. an H264Encoder (AudioTools/Video/CodecH264.h), configured as usual (setSize()/setVideoFormat()/...) before passing it here. Leave unset to write setVideoSource()'s bytes straight through as already-encoded frames instead.

◆ setVideoSource()

void setVideoSource ( VideoFrameSource video)
inline

Defines the video frame provider copy() pulls frames from - already-encoded unless setVideoEncoder() is also called. Leave unset to write audio only.

Member Data Documentation

◆ audio_info

AudioInfo audio_info
protected

◆ audio_samples_written

uint64_t audio_samples_written = 0
protected

◆ bytes_per_sample

uint32_t bytes_per_sample = 0
protected

◆ have_audio

bool have_audio = false
protected

◆ have_video

bool have_video = false
protected

◆ kAudioReadChunkSize

constexpr size_t kAudioReadChunkSize = 512
staticconstexprprotected

◆ p_audio

Stream* p_audio = nullptr
protected

◆ p_audio_encoder

AudioEncoder* p_audio_encoder = nullptr
protected

◆ p_muxer

Muxer* p_muxer = nullptr
protected

◆ p_source_audio_info

AudioInfoSupport* p_source_audio_info = nullptr
protected

◆ p_video

VideoFrameSource* p_video = nullptr
protected

◆ p_video_encoder

VideoEncoder* p_video_encoder = nullptr
protected

◆ sample_rate

uint32_t sample_rate = 0
protected

◆ video_fps

float video_fps = 0
protected

◆ video_frame_count

uint32_t video_frame_count = 0
protected

◆ video_interval_ms

uint32_t video_interval_ms = 33
protected

◆ video_sink

MuxerVideoSink video_sink
protected

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