H.264 video encoder for ESP32-S3: wraps esp_h264::H264Encoder (https://github.com/pschatzmann/ESP32S3-h264) - the ESP32-S3-specific counterpart of H264Encoder (CodecH264.h, the portable TinyH264-based encoder). Configure via setSize()/setFrameRate()/setBitrate()/ setGop()/setQpRange()/setVideoFormat() (I420 - the default -, RGB565 or YUV422), then feed raw pictures via write() - it writes the resulting Annex-B bitstream straight to the Print target passed to setOutput() (the underlying esp_h264::H264Encoder methods already take a Print& and handle the write, retrying on partial writes - see H264Encoder.h's encode()).
More...
#include <CodecH264ESP32S3.h>
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
class audio_tools::H264EncoderESP32S3< Alloc >
H.264 video encoder for ESP32-S3: wraps esp_h264::H264Encoder (https://github.com/pschatzmann/ESP32S3-h264) - the ESP32-S3-specific counterpart of H264Encoder (CodecH264.h, the portable TinyH264-based encoder). Configure via setSize()/setFrameRate()/setBitrate()/ setGop()/setQpRange()/setVideoFormat() (I420 - the default -, RGB565 or YUV422), then feed raw pictures via write() - it writes the resulting Annex-B bitstream straight to the Print target passed to setOutput() (the underlying esp_h264::H264Encoder methods already take a Print& and handle the write, retrying on partial writes - see H264Encoder.h's encode()).
Unlike esp_h264::H264Encoder itself, this wrapper does not drive an attached camera (its use_camera/pin/captureH264() surface) - it only covers the encode-a-buffer-you-already-have path, matching H264Encoder's (CodecH264.h) scope; use esp_h264::H264Encoder directly (via driver()) if you want its built-in camera capture loop instead.
The Alloc template parameter is forwarded to esp_h264::H264Encoder - see that class's own file comment (H264Encoder.h) for the PSRAM- vs. internal-RAM allocator choice (H264EncoderPSRAM/H264EncoderRAM aliases). Defaults to H264_DEFAULT_ALLOCATOR.
- Author
- Phil Schatzmann
- Copyright
- GPLv3
◆ H264EncoderESP32S3() [1/3]
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
◆ H264EncoderESP32S3() [2/3]
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
◆ H264EncoderESP32S3() [3/3]
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
◆ begin()
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
Initializes the encoder - see esp_h264::H264Encoder::begin().
Implements VideoEncoder.
◆ driver()
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
| esp_h264::H264Encoder< Alloc > & driver |
( |
| ) |
|
|
inline |
Direct access to the wrapped esp_h264::H264Encoder, e.g. for its camera-capture surface (begin() with use_camera/pin fields set, captureH264()) - not exposed through this wrapper.
◆ end()
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
Releases the encoder's resources - see esp_h264::H264Encoder::end().
Implements VideoEncoder.
◆ setBitrate()
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
| void setBitrate |
( |
int |
bitsPerSecond | ) |
|
|
inline |
Target bitrate (bits/sec) - defaults to width*height*fps*30/100 if never called. Call before begin().
◆ setFrameRate()
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
| void setFrameRate |
( |
int |
fps | ) |
|
|
inline |
Target frames/sec - also the default GOP size (see setGop()) unless overridden. Call before begin().
◆ setGop()
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
Group-of-Pictures size (keyframe interval, in frames) - defaults to setFrameRate()'s fps if never called. Call before begin().
◆ setOutput() [1/2]
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
| void setOutput |
( |
Print & |
out | ) |
|
|
inlineoverridevirtual |
◆ setOutput() [2/2]
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
◆ setOutputBufferSize()
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
| void setOutputBufferSize |
( |
size_t |
size | ) |
|
|
inline |
Output buffer size (bytes) the wrapped encoder allocates for the encoded bitstream - defaults to one uncompressed I420 frame's worth if never called. Call before begin().
◆ setQpRange()
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
| void setQpRange |
( |
int |
qpMin, |
|
|
int |
qpMax |
|
) |
| |
|
inline |
Quantizer parameter range [0, 51] the encoder's rate control stays within - lower is better quality/higher bitrate. Defaults to [28, 30] if never called. Call before begin().
◆ setSize()
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
| void setSize |
( |
int |
width, |
|
|
int |
height |
|
) |
| |
|
inline |
Picture size - must match the raw frame data passed to write(). Call before begin().
◆ setVideoFormat()
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
Selects the raw picture format write() expects - this backend (esp_h264) supports VideoFormat::I420 (the default: planar Y/U/V, no row padding), RGB565 (16-bit, 5-6-5 packed, little-endian) and YUV422 (packed YUYV); any other value is logged and ignored (the previously selected format stays in effect). Call before the first write().
Implements VideoEncoder.
◆ videoInfo()
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
◆ write()
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
| size_t write |
( |
const uint8_t * |
data, |
|
|
size_t |
len |
|
) |
| |
|
inlineoverridevirtual |
Encodes one raw picture, in setVideoFormat()'s format (I420 by default: Y, then U, then V, no row padding; RGB565 - converted internally to I420 - or YUV422, likewise), and writes the result to setOutput() - len must be at least width*height*3/2 (I420) or width*height*2 (RGB565/YUV422). Returns the number of bytes written on success (see class comment - not an exact byte count, the underlying esp_h264::H264Encoder only reports success/failure), or 0 on failure (e.g. setOutput() wasn't configured, len too small, or the format is unsupported).
Implements VideoEncoder.
◆ config_
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
| esp_h264::H264Encoder<Alloc>::Config config_ |
|
protected |
◆ dual_out_
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
◆ encoder_
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
| esp_h264::H264Encoder<Alloc> encoder_ |
|
protected |
◆ input_format
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
◆ p_out
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
◆ p_out_video
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
The documentation for this class was generated from the following file: