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>
|
| JERESULT | encode (const uint8_t *data, size_t &size) |
| |
|
| static constexpr int | kMaxGrowRetries = 4 |
| | Number of times the buffer is doubled before giving up.
|
| |
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
- Copyright
- GPLv3
◆ MJPEGEncoder() [1/3]
◆ MJPEGEncoder() [2/3]
◆ MJPEGEncoder() [3/3]
◆ begin()
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()
◆ 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]
◆ 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()
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()
◆ 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.
◆ encoder_
| tinyjpeg::TinyJPEGEncoder encoder_ |
|
protected |
◆ height_
◆ input_format
◆ jpeg
◆ kDefaultBufferSize
| constexpr size_t kDefaultBufferSize = 16384 |
|
staticconstexpr |
◆ kMaxGrowRetries
| constexpr int kMaxGrowRetries = 4 |
|
staticconstexprprotected |
Number of times the buffer is doubled before giving up.
◆ p_out
◆ p_out_video
◆ width_
The documentation for this class was generated from the following file: