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

Motion-JPEG video encoder: wraps TinyJPEGEncoder (https://github.com/pschatzmann/TinyJPEG) as a VideoEncoder - the MJPEG counterpart of H264Encoder (CodecH264.h), e.g. for VideoMuxer/ VideoMuxerWithTasks with a camera that delivers raw pictures. Configure it via setSize()/setVideoFormat() (RGB565 - the default -, RGB888 or RGB666, packed) and optionally setQuality()/setSubsample(), then feed raw pictures via write(): each one is encoded into one complete JPEG image, which is written to the target configured via setOutput() in a single write() call - as the muxers expect one frame per call. More...

#include <CodecJPEG.h>

Inheritance diagram for MJPEGEncoder:
VideoEncoder

Public Member Functions

 MJPEGEncoder (int width=0, int height=0)
 
 MJPEGEncoder (Print &out)
 
 MJPEGEncoder (VideoOutput &out)
 
bool begin () override
 Initializes the encoder (allocates its picture buffers, etc).
 
tinyjpeg::TinyJPEGEncoder & driver ()
 Direct access to the wrapped TinyJPEGEncoder.
 
void end () override
 Releases the encoder's resources.
 
void setBufferSize (size_t size)
 
void setOutput (Print &out) override
 Defines the target each encoded JPEG image is written to.
 
void setOutput (VideoOutput &out)
 
void setQuality (uint8_t quality)
 JPEG quality: 1 (smallest) to 100 (best) - see TinyJPEGEncoder::setQuality()
 
void setSize (int width, int height)
 Defines the picture size.
 
void setSubsample (bool enable)
 4:2:0 chroma subsampling on/off - see TinyJPEGEncoder::setSubsample()
 
void setVideoFormat (VideoFormat format) override
 
VideoInfo videoInfo () override
 Reports VideoFormat::MJPEG and the size set via setSize().
 
size_t write (const uint8_t *data, size_t len) override
 

Static Public Attributes

static constexpr size_t kDefaultBufferSize = 16384
 Default size (bytes) of the internal JPEG buffer - see setBufferSize().
 

Protected Member Functions

JERESULT encode (const uint8_t *data, size_t &size)
 

Protected Attributes

tinyjpeg::TinyJPEGEncoder encoder_
 
int height_ = 0
 
VideoFormat input_format = VideoFormat::RGB565
 
Vector< uint8_t > jpeg
 
Print * p_out = nullptr
 
VideoOutput * p_out_video = nullptr
 
int width_ = 0
 

Static Protected Attributes

static constexpr int kMaxGrowRetries = 4
 Number of times the buffer is doubled before giving up.
 

Detailed Description

Motion-JPEG video encoder: wraps TinyJPEGEncoder (https://github.com/pschatzmann/TinyJPEG) as a VideoEncoder - the MJPEG counterpart of H264Encoder (CodecH264.h), e.g. for VideoMuxer/ VideoMuxerWithTasks with a camera that delivers raw pictures. Configure it via setSize()/setVideoFormat() (RGB565 - the default -, RGB888 or RGB666, packed) and optionally setQuality()/setSubsample(), then feed raw pictures via write(): each one is encoded into one complete JPEG image, which is written to the target configured via setOutput() in a single write() call - as the muxers expect one frame per call.

The encoded image is assembled in an internal buffer, which starts at kDefaultBufferSize and grows (doubling, up to a few attempts) whenever an image doesn't fit - so it doesn't need to be sized by hand; use setBufferSize() to pre-size it.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ MJPEGEncoder() [1/3]

MJPEGEncoder ( int  width = 0,
int  height = 0 
)
inline

◆ MJPEGEncoder() [2/3]

MJPEGEncoder ( Print &  out)
inline

◆ MJPEGEncoder() [3/3]

MJPEGEncoder ( VideoOutput &  out)
inline

Member Function Documentation

◆ begin()

bool begin ( )
inlineoverridevirtual

Initializes the encoder (allocates its picture buffers, etc).

Implements VideoEncoder.

◆ driver()

tinyjpeg::TinyJPEGEncoder & driver ( )
inline

Direct access to the wrapped TinyJPEGEncoder.

◆ encode()

JERESULT encode ( const uint8_t *  data,
size_t &  size 
)
inlineprotected

◆ end()

void end ( )
inlineoverridevirtual

Releases the encoder's resources.

Implements VideoEncoder.

◆ setBufferSize()

void setBufferSize ( size_t  size)
inline

Pre-sizes the internal JPEG buffer (see class comment). Shrinks are ignored.

◆ setOutput() [1/2]

void setOutput ( Print &  out)
inlineoverridevirtual

Defines the target each encoded JPEG image is written to.

Implements VideoEncoder.

◆ setOutput() [2/2]

void setOutput ( VideoOutput &  out)
inline

◆ setQuality()

void setQuality ( uint8_t  quality)
inline

JPEG quality: 1 (smallest) to 100 (best) - see TinyJPEGEncoder::setQuality()

◆ setSize()

void setSize ( int  width,
int  height 
)
inline

Defines the picture size.

◆ setSubsample()

void setSubsample ( bool  enable)
inline

4:2:0 chroma subsampling on/off - see TinyJPEGEncoder::setSubsample()

◆ setVideoFormat()

void setVideoFormat ( VideoFormat  format)
inlineoverridevirtual

Selects the raw picture format write() expects: VideoFormat::RGB565 (the default), RGB888 or RGB666 (packed). Any other format is logged and ignored (previous format kept).

Implements VideoEncoder.

◆ videoInfo()

VideoInfo videoInfo ( )
inlineoverridevirtual

Reports VideoFormat::MJPEG and the size set via setSize().

Implements VideoEncoder.

◆ write()

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

Encodes one raw picture (setVideoFormat()'s format, setSize()'s size) and writes the JPEG image to the output - returns its size (0 if nothing was written, e.g. if len doesn't match the configured format and size).

Implements VideoEncoder.

Member Data Documentation

◆ encoder_

tinyjpeg::TinyJPEGEncoder encoder_
protected

◆ height_

int height_ = 0
protected

◆ input_format

VideoFormat input_format = VideoFormat::RGB565
protected

◆ jpeg

Vector<uint8_t> jpeg
protected

◆ kDefaultBufferSize

constexpr size_t kDefaultBufferSize = 16384
staticconstexpr

Default size (bytes) of the internal JPEG buffer - see setBufferSize().

◆ kMaxGrowRetries

constexpr int kMaxGrowRetries = 4
staticconstexprprotected

Number of times the buffer is doubled before giving up.

◆ p_out

Print* p_out = nullptr
protected

◆ p_out_video

VideoOutput* p_out_video = nullptr
protected

◆ width_

int width_ = 0
protected

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