|
| Config | defaultConfig () |
| | Create a default configuration with reasonable defaults.
|
| |
| Config | defaultConfig (const char *camera) |
| | Create a default configuration based on camera preset name.
|
| |
| | H264Encoder () |
| | Default constructor.
|
| |
| | ~H264Encoder () |
| | Destructor.
|
| |
| bool | begin (Config cfg) |
| | Initialize WiFi, camera and H.264 encoder.
|
| |
| bool | captureFrame (uint8_t *dst, size_t dst_len) |
| | Capture a single frame and write raw I420 data to buffer.
|
| |
| bool | encodeYUV422 (const uint8_t *raw_data, size_t raw_len, Print &out) |
| | Encode raw YUV422 frame data to H.264 and write to Print stream.
|
| |
| bool | encodeRGB565 (const uint8_t *raw_data, size_t raw_len, Print &out) |
| | Encode raw RGB565 frame data to H.264 and write to Print stream.
|
| |
| bool | encode (const uint8_t *raw_data, size_t raw_len, Print &out) |
| | Encode raw I420 frame data to H.264 and write to Print stream.
|
| |
| bool | captureH264 (Print &out) |
| | Capture frame, encode to H.264, and stream with frame rate control.
|
| |
| void | end () |
| | Cleanup and release camera resources.
|
| |
| sensor_t * | getSensor () |
| |
template<typename Alloc = H264_DEFAULT_ALLOCATOR>
class esp_h264::H264Encoder< Alloc >
Template class for capturing frames from ESP32 camera and encoding to H.264.
H264Encoder is a lightweight, header-only class that wraps camera initialization, pixel format conversions (RGB565/YUV422 → I420), H.264 encoder lifecycle, and streaming to any Arduino Print implementation.
The class is templated on an allocator type to allow customization of memory allocation strategy (e.g., PSRAM vs regular heap).
- Template Parameters
-
- Note
- This class intentionally keeps implementation in the header for easy integration into Arduino sketches without separate .cpp files
-
The pixel format conversions are straightforward and not highly optimized
-
Requires ESP32 with camera module and sufficient memory for frame buffers
Example usage:
void setup() {
cfg.ssid = "MyWiFi";
cfg.password = "MyPassword";
cfg.height = 480;
cfg.fps = 15;
udpOut.begin("192.168.1.100", 5000);
if (!streamer.
begin(cfg)) {
Serial.println("Failed to start camera streamer");
}
}
void loop() {
udpOut.flush();
}
Header-only helper to capture frames from ESP32 camera and encode to H.264.
header-only Arduino Print implementation that sends data over
Template class for capturing frames from ESP32 camera and encoding to H.264.
Definition: H264Encoder.h:75
bool captureH264(Print &out)
Capture frame, encode to H.264, and stream with frame rate control.
Definition: H264Encoder.h:451
bool begin(Config cfg)
Initialize WiFi, camera and H.264 encoder.
Definition: H264Encoder.h:209
Config defaultConfig()
Create a default configuration with reasonable defaults.
Definition: H264Encoder.h:133
A Print implementation that buffers and sends data over UDP.
Definition: UDPPrint.h:35
int width
Frame width in pixels.
Definition: H264Encoder.h:88
| bool captureH264 |
( |
Print & |
out | ) |
|
|
inline |
Capture frame, encode to H.264, and stream with frame rate control.
High-level method that performs the complete streaming pipeline:
- Captures one frame from the camera
- Converts pixel format to I420 if needed
- Encodes frame using H.264 software encoder
- Writes encoded data to the provided Print stream
- Enforces configured frame rate by delaying remaining time
This method measures processing time and only delays for the remainder of the target frame interval, ensuring consistent frame rate regardless of processing time variations.
- Parameters
-
| out | Print stream to receive encoded H.264 NAL units |
- Returns
- true if capture, encoding, and streaming succeeded, false otherwise
- Note
- Frame rate is controlled by Config::fps setting
-
Processing time is subtracted from frame interval delay
-
This is the main method most applications should use
-
On failure, no delay is applied (to avoid blocking on errors)