arduino-audio-tools
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Attributes | List of all members
H264EncoderESP32S3< Alloc > Class Template Reference

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>

Inheritance diagram for H264EncoderESP32S3< Alloc >:
VideoEncoder

Classes

class  DualOutputPrint
 

Public Member Functions

 H264EncoderESP32S3 ()
 
 H264EncoderESP32S3 (Print &out)
 
 H264EncoderESP32S3 (VideoOutput &out)
 
bool begin () override
 Initializes the encoder - see esp_h264::H264Encoder::begin().
 
esp_h264::H264Encoder< Alloc > & driver ()
 
void end () override
 Releases the encoder's resources - see esp_h264::H264Encoder::end().
 
void setBitrate (int bitsPerSecond)
 
void setFrameRate (int fps)
 
void setGop (int gop)
 
void setOutput (Print &out) override
 
void setOutput (VideoOutput &out)
 
void setOutputBufferSize (size_t size)
 
void setQpRange (int qpMin, int qpMax)
 
void setSize (int width, int height)
 
void setVideoFormat (VideoFormat format) override
 
VideoInfo videoInfo () override
 
size_t write (const uint8_t *data, size_t len) override
 

Protected Attributes

esp_h264::H264Encoder< Alloc >::Config config_
 
DualOutputPrint dual_out_
 
esp_h264::H264Encoder< Alloc > encoder_
 
VideoFormat input_format = VideoFormat::I420
 
Printp_out = nullptr
 
VideoOutputp_out_video = nullptr
 

Detailed Description

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

Constructor & Destructor Documentation

◆ H264EncoderESP32S3() [1/3]

template<typename Alloc = H264_DEFAULT_ALLOCATOR>
H264EncoderESP32S3 ( )
inline

◆ H264EncoderESP32S3() [2/3]

template<typename Alloc = H264_DEFAULT_ALLOCATOR>
H264EncoderESP32S3 ( Print out)
inline

◆ H264EncoderESP32S3() [3/3]

template<typename Alloc = H264_DEFAULT_ALLOCATOR>
H264EncoderESP32S3 ( VideoOutput out)
inline

Member Function Documentation

◆ begin()

template<typename Alloc = H264_DEFAULT_ALLOCATOR>
bool begin ( )
inlineoverridevirtual

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>
void end ( )
inlineoverridevirtual

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>
void setGop ( int  gop)
inline

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

Defines the target each write() call writes its encoded bitstream to.

Implements VideoEncoder.

◆ setOutput() [2/2]

template<typename Alloc = H264_DEFAULT_ALLOCATOR>
void setOutput ( VideoOutput out)
inline

◆ 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>
void setVideoFormat ( VideoFormat  format)
inlineoverridevirtual

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>
VideoInfo videoInfo ( )
inlineoverridevirtual

Reports the codec/dimensions of the bitstream written to setOutput()'s target - format is always VideoFormat::H264 (NOT setVideoFormat()'s raw input format); width/height match setSize() (0 if that was never called).

Implements VideoEncoder.

◆ 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.

Member Data Documentation

◆ config_

template<typename Alloc = H264_DEFAULT_ALLOCATOR>
esp_h264::H264Encoder<Alloc>::Config config_
protected

◆ dual_out_

template<typename Alloc = H264_DEFAULT_ALLOCATOR>
DualOutputPrint dual_out_
protected

◆ encoder_

template<typename Alloc = H264_DEFAULT_ALLOCATOR>
esp_h264::H264Encoder<Alloc> encoder_
protected

◆ input_format

template<typename Alloc = H264_DEFAULT_ALLOCATOR>
VideoFormat input_format = VideoFormat::I420
protected

◆ p_out

template<typename Alloc = H264_DEFAULT_ALLOCATOR>
Print* p_out = nullptr
protected

◆ p_out_video

template<typename Alloc = H264_DEFAULT_ALLOCATOR>
VideoOutput* p_out_video = nullptr
protected

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