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

H.264 video encoder for ESP32-P4: wraps esp_h264_p4::H264EncoderP4 (https://github.com/pschatzmann/codec-h264-ESP32P4), which drives ESP32-P4's dedicated H.264 hardware encoder block - the ESP32-P4-specific counterpart of H264Encoder (CodecH264.h, the portable TinyH264-based software encoder) and a hardware-backed sibling of H264EncoderESP32S3 (whose wrapped esp_h264::H264Encoder is software-only, since the S3 has no H.264 hardware block). More...

#include <CodecH264ESP32P4.h>

Inheritance diagram for H264EncoderESP32P4< Alloc >:
VideoEncoder

Classes

class  DualOutputPrint
 

Public Member Functions

 H264EncoderESP32P4 ()
 
 H264EncoderESP32P4 (Print &out)
 
 H264EncoderESP32P4 (VideoOutput &out)
 
bool begin () override
 Initializes the encoder - see esp_h264_p4::H264EncoderP4::begin().
 
esp_h264_p4::H264EncoderP4< Alloc > & driver ()
 Direct access to the wrapped esp_h264_p4::H264EncoderP4.
 
void end () override
 
esp_h264_frame_type_t lastFrameType () const
 
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_p4::H264EncoderP4< Alloc >::Config config_
 
DualOutputPrint dual_out_
 
esp_h264_p4::H264EncoderP4< Alloc > encoder_
 
VideoFormat input_format = VideoFormat::I420
 
Printp_out = nullptr
 
VideoOutputp_out_video = nullptr
 

Detailed Description

template<typename Alloc = H264P4_DEFAULT_ALLOCATOR>
class audio_tools::H264EncoderESP32P4< Alloc >

H.264 video encoder for ESP32-P4: wraps esp_h264_p4::H264EncoderP4 (https://github.com/pschatzmann/codec-h264-ESP32P4), which drives ESP32-P4's dedicated H.264 hardware encoder block - the ESP32-P4-specific counterpart of H264Encoder (CodecH264.h, the portable TinyH264-based software encoder) and a hardware-backed sibling of H264EncoderESP32S3 (whose wrapped esp_h264::H264Encoder is software-only, since the S3 has no H.264 hardware block).

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().

Unlike RGB565/YUV422 (packed formats the hardware encoder consumes as-is), I420 (planar Y/U/V) is not one of the hardware's accepted raw layouts - write() instead routes it through esp_h264_p4::H264EncoderP4::encodeYUV420Planar(), which repacks it into the hardware's required ESP_H264_RAW_FMT_O_UYY_E_VYY layout internally.

The Alloc template parameter is forwarded to esp_h264_p4::H264EncoderP4

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ H264EncoderESP32P4() [1/3]

template<typename Alloc = H264P4_DEFAULT_ALLOCATOR>
H264EncoderESP32P4 ( )
inline

◆ H264EncoderESP32P4() [2/3]

template<typename Alloc = H264P4_DEFAULT_ALLOCATOR>
H264EncoderESP32P4 ( Print out)
inline

◆ H264EncoderESP32P4() [3/3]

template<typename Alloc = H264P4_DEFAULT_ALLOCATOR>
H264EncoderESP32P4 ( VideoOutput out)
inline

Member Function Documentation

◆ begin()

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

Initializes the encoder - see esp_h264_p4::H264EncoderP4::begin().

Implements VideoEncoder.

◆ driver()

template<typename Alloc = H264P4_DEFAULT_ALLOCATOR>
esp_h264_p4::H264EncoderP4< Alloc > & driver ( )
inline

Direct access to the wrapped esp_h264_p4::H264EncoderP4.

◆ end()

template<typename Alloc = H264P4_DEFAULT_ALLOCATOR>
void end ( )
inlineoverridevirtual

Releases the encoder's resources - see esp_h264_p4::H264EncoderP4::end().

Implements VideoEncoder.

◆ lastFrameType()

template<typename Alloc = H264P4_DEFAULT_ALLOCATOR>
esp_h264_frame_type_t lastFrameType ( ) const
inline

Frame type of the most recent successful encode (IDR/I/P) - see esp_h264_p4::H264EncoderP4::lastFrameType().

◆ setBitrate()

template<typename Alloc = H264P4_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 = H264P4_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 = H264P4_DEFAULT_ALLOCATOR>
void setGop ( int  gop)
inline

Group-of-Pictures size (keyframe interval, in frames) - unlike the software encoder (H264EncoderESP32S3), 0 is invalid here; defaults to setFrameRate()'s fps if never called. Call before begin().

◆ setOutput() [1/2]

template<typename Alloc = H264P4_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 = H264P4_DEFAULT_ALLOCATOR>
void setOutput ( VideoOutput out)
inline

◆ setOutputBufferSize()

template<typename Alloc = H264P4_DEFAULT_ALLOCATOR>
void setOutputBufferSize ( size_t  size)
inline

Output buffer size (bytes) the wrapped encoder allocates for the encoded bitstream - defaults to width*height*bytes-per-pixel (for the selected raw format) if never called. Call before begin().

◆ setQpRange()

template<typename Alloc = H264P4_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 [25, 30] if never called. Call before begin().

◆ setSize()

template<typename Alloc = H264P4_DEFAULT_ALLOCATOR>
void setSize ( int  width,
int  height 
)
inline

Picture size - must match the raw frame data passed to write(). Hardware limits apply (max 1920x2032, min 80x80 - see esp_h264_types.h). Call before begin().

◆ setVideoFormat()

template<typename Alloc = H264P4_DEFAULT_ALLOCATOR>
void setVideoFormat ( VideoFormat  format)
inlineoverridevirtual

Selects the raw picture format write() expects - this backend (esp_h264_p4) supports VideoFormat::I420 (the default: planar Y/U/V, no row padding - repacked internally, see class comment), 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 begin() - it also selects the hardware's raw pixel format (Config::pic_type).

Implements VideoEncoder.

◆ videoInfo()

template<typename Alloc = H264P4_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() (640x480 if never called - see Config's defaults).

Implements VideoEncoder.

◆ write()

template<typename Alloc = H264P4_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 or YUV422 likewise, passed straight through to the hardware), and writes the result to setOutput() - len must be at least width*height*3/2 (I420) or width*height*2 (RGB565/YUV422). Returns 1 on success (see class comment - not an exact byte count, the underlying esp_h264_p4::H264EncoderP4 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 = H264P4_DEFAULT_ALLOCATOR>
esp_h264_p4::H264EncoderP4<Alloc>::Config config_
protected

◆ dual_out_

template<typename Alloc = H264P4_DEFAULT_ALLOCATOR>
DualOutputPrint dual_out_
protected

◆ encoder_

template<typename Alloc = H264P4_DEFAULT_ALLOCATOR>
esp_h264_p4::H264EncoderP4<Alloc> encoder_
protected

◆ input_format

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

◆ p_out

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

◆ p_out_video

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

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