4
5
6
7
8
16#include "esp_camera.h"
17#include "h264/esp_h264_enc_single.h"
18#include "h264/esp_h264_enc_single_sw.h"
19#include "h264/esp_h264_types.h"
20#include "h264/h264_color_convert.h"
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74template <
typename Alloc = H264_DEFAULT_ALLOCATOR>
78 static constexpr const char*
TAG =
"H264Encoder";
81
82
83
84
85
86
121
122
123
124
125
126
127
128
129
130
131
132
134 ESP_LOGD(
TAG,
"defaultConfig");
139 cfg.outBufferSize = 0;
140 cfg.pixel_format = PIXFORMAT_YUV422;
145
146
147
148
149
150
151
152
153
154
156 ESP_LOGI(
TAG,
"defaultConfig for camera preset: %s", camera);
157 for (
const auto& mapping : kFallbackMappings) {
158 if (strstr(mapping.name, camera) !=
nullptr) {
159 Config cfg = defaultConfig();
160 applyPinMapping(cfg, mapping);
161 ESP_LOGI(
TAG,
"Using default config for camera preset: %s", camera);
165 ESP_LOGW(
TAG,
"No preset found for camera: %s, using generic defaults",
167 return defaultConfig();
171
172
173
174
175
179
180
181
182
183
184
185
187 ESP_LOGD(
TAG,
"~H264Encoder");
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
210 ESP_LOGD(
TAG,
"begin");
215 if (!initEncoder())
return false;
217 if (cfg_.use_camera) {
218 if (!initCamera())
return false;
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
240 ESP_LOGD(
TAG,
"captureFrame");
241 if (!dst)
return false;
242 return captureFrameI420(dst, dst_len);
246
247
248
249
250
251
252
253
254 bool encodeYUV422(
const uint8_t* raw_data, size_t raw_len, Print& out) {
255 ESP_LOGD(TAG,
"encodeYUV422: %u bytes", (
unsigned)raw_len);
257 ESP_LOGE(
TAG,
"Invalid encoder handle in encodeYUV422");
260 if (!raw_data || raw_len == 0) {
262 "No data provided to encodeYUV422 (raw_data=%p, raw_len=%u)",
263 raw_data, (
unsigned)raw_len);
266 if (in_buf_.empty()) {
267 ESP_LOGE(
TAG,
"Input buffer is empty in encodeYUV422");
270 if (out_buf_.empty()) {
271 ESP_LOGE(
TAG,
"Output buffer is empty in encodeYUV422");
276 size_t expected = (size_t)cfg_.width * (size_t)cfg_.height * 2;
277 if (raw_len < expected) {
280 "Insufficient data for encodeYUV422: expected %u bytes, got %u bytes",
281 (
unsigned)expected, (
unsigned)raw_len);
286 yuyv2iyuv_esp32s3((uint32_t)cfg_.height, (uint32_t)cfg_.width,
287 (uint8_t*)raw_data, in_buf_.data());
289 yuyv2iyuv((uint32_t)cfg_.height, (uint32_t)cfg_.width, (uint8_t*)raw_data,
293 return encode(in_buf_.data(), in_buf_.size(), out);
297
298
299
300
301
302
303
304
305 bool encodeRGB565(
const uint8_t* raw_data, size_t raw_len, Print& out) {
306 ESP_LOGD(TAG,
"encodeRGB565: %u bytes", (
unsigned)raw_len);
308 ESP_LOGE(
TAG,
"Invalid encoder handle in encodeRGB565");
311 if (!raw_data || raw_len == 0) {
313 "No data provided to encodeRGB565 (raw_data=%p, raw_len=%u)",
314 raw_data, (
unsigned)raw_len);
317 if (in_buf_.empty()) {
318 ESP_LOGE(
TAG,
"Input buffer is empty in encodeRGB565");
321 if (out_buf_.empty()) {
322 ESP_LOGE(
TAG,
"Output buffer is empty in encodeRGB565");
325 size_t expected = (size_t)cfg_.width * (size_t)cfg_.height * 2;
326 if (raw_len < expected) {
329 "Insufficient data for encodeRGB565: expected %u bytes, got %u bytes",
330 (
unsigned)expected, (
unsigned)raw_len);
333 size_t expected_i420 = (size_t)cfg_.width * (size_t)cfg_.height * 3 / 2;
334 if (in_buf_.size() < expected_i420) {
336 "Input buffer too small for I420: need %u bytes, got %u bytes",
337 (
unsigned)expected_i420, (
unsigned)in_buf_.size());
341 "Converting RGB565 to I420 for encoding: input %u bytes, output "
343 (
unsigned)raw_len, (
unsigned)in_buf_.size());
345 rgb565_to_i420(raw_data, in_buf_.data(), cfg_.width, cfg_.height);
346 return encode(in_buf_.data(), expected_i420, out);
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366 bool encode(
const uint8_t* raw_data, size_t raw_len, Print& out) {
367 ESP_LOGD(TAG,
"encode: %u bytes", (
unsigned)raw_len);
369 ESP_LOGE(
TAG,
"Invalid encoder handle in encode()");
372 if (!raw_data || raw_len == 0) {
373 ESP_LOGE(TAG,
"Invalid input data for encode(): raw_data=%p, raw_len=%u",
374 raw_data, (
unsigned)raw_len);
377 if (out_buf_.empty()) {
378 ESP_LOGE(
TAG,
"Output buffer is empty in encode()");
382 esp_h264_enc_in_frame_t in_frame{};
383 esp_h264_enc_out_frame_t out_frame{};
385 in_frame.raw_data.len = raw_len;
391 "Starting encoding: input size=%u bytes, output buffer size=%u bytes",
392 (
unsigned)raw_len, (
unsigned)out_buf_.size());
396 ESP_LOGE(
TAG,
"Encoding failed with error code: %d", r);
403 size_t to_write = out_frame.length;
404 const int max_retries = 5;
406 while (written < to_write && attempts < max_retries) {
407 size_t n = out.write(buf + written, to_write - written);
417 if (written < to_write) {
418 ESP_LOGW(TAG,
"Partial write: expected %u bytes, wrote %u bytes",
419 (
unsigned)to_write, (
unsigned)written);
423 ESP_LOGI(
TAG,
"Encoded frame: i420=%u bytes, h264=%u bytes",
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
452 ESP_LOGD(
TAG,
"captureH264");
454 if (in_buf_.empty())
return false;
455 if (!enc_handle_)
return false;
458 unsigned long frame_ms = (cfg_.fps > 0) ? (1000u / (
unsigned)cfg_.fps) : 0u;
459 unsigned long start = millis();
462 if (!captureFrameI420(in_buf_.data(), in_buf_.size())) {
467 if (!encode(in_buf_.data(), in_buf_.size(), out)) {
473 unsigned long elapsed = millis() - start;
474 if (elapsed < frame_ms) delay(frame_ms - elapsed);
481
482
483
484
485
486
487
488
489
490
491
492
493
495 ESP_LOGD(
TAG,
"end");
500 enc_handle_ =
nullptr;
502 if (!in_buf_.empty()) {
505 if (!out_buf_.empty()) {
532 static constexpr PinMapping kFallbackMappings[] = {
533 {
"ESP32-S3-N16R8-CAM", -1, -1, 15, 4, 5, 11, 9, 8, 10, 12, 18, 17, 16, 6,
535 {
"ESP32-S3-CAM", 38, -1, 15, 4, 5, 11, 9, 8, 10, 12, 18, 17, 16, 6, 7,
537 {
"ESP32-S3-GOOUUU", -1, -1, 15, 4, 5, 11, 9, 8, 10, 12, 18, 17, 16, 6, 7,
539 {
"LILYGO-TCAM-PLUS-S3-V1.2", 4, -1, 7, 1, 2, 12, 14, 11, 9, 8, 6, 15, 13,
541 {
"LILYGO-TCAM-PLUS-S3-V1.0", -1, 3, 7, 1, 2, 12, 14, 11, 13, 8, 6, 15, 9,
543 {
"DFROBOT-FIREBEETLE2", -1, -1, 15, 4, 5, 11, 9, 8, 10, 12, 18, 17, 16, 6,
545 {
"ESP32-S3-12K", 2, 21, 38, 4, 11, 6, 5, 8, 10, 12, 18, 17, 39, 13, 14,
547 {
"ESP32-S3-XIAO", -1, -1, 10, 40, 39, 15, 17, 18, 16, 14, 12, 11, 48, 38,
549 {
"ESP32-S3-CAM-TS", -1, -1, 33, 37, 36, 7, 5, 4, 6, 8, 42, 48, 47, 35, 34,
551 {
"GENERIC_S3_CAM", -1, -1, 40, 17, 18, 39, 41, 42, 12, 3, 14, 47, 13, 21,
553 {
"ESP32-S3-KORVO", -1, -1, 40, 17, 18, 13, 47, 14, 3, 12, 42, 41, 39, 21,
559 std::vector<uint8_t, Alloc> in_buf_;
560 std::vector<uint8_t, Alloc> out_buf_;
561 sensor_t* sensor =
nullptr;
564
565
566
567
568
569
570
571
572
574 ESP_LOGD(
TAG,
"initCamera");
576 auto pick_frame_size = [](
int w,
int h) -> framesize_t {
577 if (w == 160 && h == 120)
return FRAMESIZE_QQVGA;
578 if (w == 320 && h == 240)
return FRAMESIZE_QVGA;
579 if (w == 640 && h == 480)
return FRAMESIZE_VGA;
580 if (w == 800 && h == 600)
return FRAMESIZE_SVGA;
581 if (w == 1024 && h == 768)
return FRAMESIZE_XGA;
583 ESP_LOGI(TAG,
"Unsupported resolution %dx%d, defaulting to VGA", w, h);
584 return FRAMESIZE_VGA;
586 framesize_t fs = pick_frame_size(cfg_.width, cfg_.height);
587 if (!tryInitCamera(fs, cfg_,
"current-config")) {
588 for (
const auto& mapping : kFallbackMappings) {
590 applyPinMapping(fallback, mapping);
591 if (samePins(cfg_, fallback)) {
594 if (tryInitCamera(fs, fallback, mapping.name)) {
600 if (!cameraInitialized()) {
602 "esp_camera_init failed for all known ESP32-S3 camera pin "
606 "Likely causes: unsupported camera sensor in esp_camera, "
607 "custom/non-standard ESP32-S3 board pinout, or incorrect wiring");
611 ESP_LOGD(
TAG,
"Camera initialized successfully");
613 sensor = esp_camera_sensor_get();
615 ESP_LOGI(TAG,
"PID: 0x%02X", sensor->id.PID);
616 sensor->set_framesize(sensor, fs);
623
624
627 size_t in_len = (size_t)cfg_.width * (size_t)cfg_.height * 3 / 2;
628 size_t out_len = cfg_.outBufferSize > 0 ? cfg_.outBufferSize : in_len;
633 in_buf_.resize(in_len);
634 out_buf_.resize(out_len);
635 }
catch (
const std::bad_alloc& e) {
636 ESP_LOGE(
TAG,
"Failed to allocate buffers: %s", e.what());
644 void applyPinMapping(
Config& config,
const PinMapping& mapping)
const {
645 config.pwdn_pin = mapping.pwdn_pin;
646 config.reset_pin = mapping.reset_pin;
647 config.xclk_pin = mapping.xclk_pin;
648 config.siod_pin = mapping.siod_pin;
649 config.sioc_pin = mapping.sioc_pin;
650 config.y2_pin = mapping.y2_pin;
651 config.y3_pin = mapping.y3_pin;
652 config.y4_pin = mapping.y4_pin;
653 config.y5_pin = mapping.y5_pin;
654 config.y6_pin = mapping.y6_pin;
655 config.y7_pin = mapping.y7_pin;
656 config.y8_pin = mapping.y8_pin;
657 config.y9_pin = mapping.y9_pin;
658 config.vsync_pin = mapping.vsync_pin;
659 config.href_pin = mapping.href_pin;
660 config.pclk_pin = mapping.pclk_pin;
663 bool cameraInitialized()
const {
return esp_camera_sensor_get() !=
nullptr; }
665 static constexpr unsigned long kCameraRetryDelayMs = 80;
667 bool tryInitCamera(framesize_t fs,
const Config& camera_cfg,
668 const char* preset_name =
nullptr) {
669 if (camera_cfg.y2_pin == -1 || camera_cfg.y3_pin == -1 ||
670 camera_cfg.y4_pin == -1 || camera_cfg.y5_pin == -1 ||
671 camera_cfg.y6_pin == -1 || camera_cfg.y7_pin == -1 ||
672 camera_cfg.y8_pin == -1 || camera_cfg.y9_pin == -1 ||
673 camera_cfg.xclk_pin == -1 || camera_cfg.pclk_pin == -1 ||
674 camera_cfg.vsync_pin == -1 || camera_cfg.href_pin == -1 ||
675 camera_cfg.siod_pin == -1 || camera_cfg.sioc_pin == -1) {
678 if (preset_name && preset_name[0] !=
'\0') {
679 ESP_LOGI(
TAG,
"Trying camera preset: %s", preset_name);
683 "Trying camera pins: pwdn=%d reset=%d xclk=%d siod=%d sioc=%d y2=%d "
684 "y3=%d y4=%d y5=%d y6=%d y7=%d y8=%d y9=%d vsync=%d href=%d pclk=%d",
685 camera_cfg.pwdn_pin, camera_cfg.reset_pin, camera_cfg.xclk_pin,
686 camera_cfg.siod_pin, camera_cfg.sioc_pin, camera_cfg.y2_pin,
687 camera_cfg.y3_pin, camera_cfg.y4_pin, camera_cfg.y5_pin,
688 camera_cfg.y6_pin, camera_cfg.y7_pin, camera_cfg.y8_pin,
689 camera_cfg.y9_pin, camera_cfg.vsync_pin, camera_cfg.href_pin,
690 camera_cfg.pclk_pin);
692 camera_config_t config{};
693 config.ledc_channel = LEDC_CHANNEL_0;
694 config.ledc_timer = LEDC_TIMER_0;
695 config.pin_d0 = camera_cfg.y2_pin;
696 config.pin_d1 = camera_cfg.y3_pin;
697 config.pin_d2 = camera_cfg.y4_pin;
698 config.pin_d3 = camera_cfg.y5_pin;
699 config.pin_d4 = camera_cfg.y6_pin;
700 config.pin_d5 = camera_cfg.y7_pin;
701 config.pin_d6 = camera_cfg.y8_pin;
702 config.pin_d7 = camera_cfg.y9_pin;
703 config.pin_xclk = camera_cfg.xclk_pin;
704 config.pin_pclk = camera_cfg.pclk_pin;
705 config.pin_vsync = camera_cfg.vsync_pin;
706 config.pin_href = camera_cfg.href_pin;
707 config.pin_sccb_sda = camera_cfg.siod_pin;
708 config.pin_sccb_scl = camera_cfg.sioc_pin;
709 config.pin_pwdn = camera_cfg.pwdn_pin;
710 config.pin_reset = camera_cfg.reset_pin;
711 config.xclk_freq_hz = 20000000;
712 config.frame_size = fs;
713 config.pixel_format = cfg_.pixel_format;
716 config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
717 esp_err_t err = esp_camera_init(&config);
719 sensor = esp_camera_sensor_get();
720 ESP_LOGI(TAG,
"PID: 0x%02X", sensor->id.PID);
724 ESP_LOGW(TAG,
"esp_camera_init '%s' failed with error 0x%x",
725 preset_name ? preset_name :
"unknown", (
unsigned)err);
727 delay(kCameraRetryDelayMs);
731 bool samePins(
const Config& lhs,
const Config& rhs)
const {
732 return lhs.pwdn_pin == rhs.pwdn_pin && lhs.reset_pin == rhs.reset_pin &&
733 lhs.xclk_pin == rhs.xclk_pin && lhs.siod_pin == rhs.siod_pin &&
734 lhs.sioc_pin == rhs.sioc_pin && lhs.y2_pin == rhs.y2_pin &&
735 lhs.y3_pin == rhs.y3_pin && lhs.y4_pin == rhs.y4_pin &&
736 lhs.y5_pin == rhs.y5_pin && lhs.y6_pin == rhs.y6_pin &&
737 lhs.y7_pin == rhs.y7_pin && lhs.y8_pin == rhs.y8_pin &&
738 lhs.y9_pin == rhs.y9_pin && lhs.vsync_pin == rhs.vsync_pin &&
739 lhs.href_pin == rhs.href_pin && lhs.pclk_pin == rhs.pclk_pin;
743
744
745
746
747
748
749
751 ESP_LOGD(
TAG,
"initEncoder");
756 enc_cfg
.fps = (uint8_t)cfg_.fps;
757 enc_cfg
.gop = (cfg_.gop > 0) ? (uint8_t)cfg_.gop : (uint8_t)cfg_.fps;
761 ? (uint32_t)cfg_.bitrate
762 : (uint32_t)(cfg_.width * cfg_.height * cfg_.fps * 30 / 100);
763 enc_cfg
.rc.qp_min = (cfg_.qp_min >= 0) ? (uint8_t)cfg_.qp_min : 28;
764 enc_cfg
.rc.qp_max = (cfg_.qp_max >= 0) ? (uint8_t)cfg_.qp_max : 30;
767 "Encoder settings: width=%u, height=%u, fps=%u, gop=%u, "
768 "pic_type=0x%08X, bitrate=%u, qp_min=%u, qp_max=%u",
770 (
unsigned)enc_cfg
.fps, (
unsigned)enc_cfg
.gop,
776 ESP_LOGE(
TAG,
"esp_h264_enc_sw_new failed: %d", (
int)res);
781 ESP_LOGE(
TAG,
"esp_h264_enc_open failed: %d", (
int)res);
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804 bool captureFrameI420(uint8_t* dst, size_t dst_len) {
805 ESP_LOGD(
TAG,
"captureFrameI420");
806 if (!dst)
return false;
807 camera_fb_t* fb = esp_camera_fb_get();
808 if (!fb)
return false;
812 size_t expected = (size_t)w * (size_t)h * 3 / 2;
813 if (dst_len < expected) {
814 ESP_LOGE(TAG,
"Destination buffer too small: need %u got %u",
815 (
unsigned)expected, (
unsigned)dst_len);
816 esp_camera_fb_return(fb);
821 switch (fb->format) {
822 case PIXFORMAT_RGB565:
823 res = captureFrameI420_RGB565(dst, dst_len, fb, w, h);
825 case PIXFORMAT_YUV422:
826 res = captureFrameI420_YUV422(dst, dst_len, fb, w, h);
829 ESP_LOGE(TAG,
"Unsupported camera pixel format: %d", fb->format);
831 esp_camera_fb_return(fb);
839
840
841
842
843
844
845 void rgb565_to_i420(
const uint8_t* src, uint8_t* dst,
int w,
int h) {
847 for (
int y = 0; y < h; ++y) {
848 for (
int x = 0; x < w; ++x) {
849 int i = (y * w + x) * 2;
851 uint16_t val = src[i] | (src[i + 1] << 8);
856 uint8_t r = ((val >> 11) & 0x1F);
857 uint8_t g = ((val >> 5) & 0x3F);
858 uint8_t b = (val & 0x1F);
860 r = (r << 3) | (r >> 2);
861 g = (g << 2) | (g >> 4);
862 b = (b << 3) | (b >> 2);
864 int yv = ((66 * r + 129 * g + 25 * b + 128) >> 8) + 16;
865 dst[y * w + x] = (uint8_t)std::clamp(yv, 0, 255);
869 uint8_t* uplane = dst + w * h;
870 uint8_t* vplane = uplane + (w / 2) * (h / 2);
876 for (
int y = 0; y < h; y += 2) {
877 for (
int x = 0; x < w; x += 2) {
878 int sumU = 0, sumV = 0;
880 for (
int dy = 0; dy < 2; ++dy) {
881 for (
int dx = 0; dx < 2; ++dx) {
882 int i = ((y + dy) * w + (x + dx)) * 2;
883 uint16_t val = src[i] | (src[i + 1] << 8);
885 uint8_t r = ((val >> 11) & 0x1F);
886 uint8_t g = ((val >> 5) & 0x3F);
887 uint8_t b = (val & 0x1F);
889 r = (r << 3) | (r >> 2);
890 g = (g << 2) | (g >> 4);
891 b = (b << 3) | (b >> 2);
893 int u = ((-38 * r - 74 * g + 112 * b + 128) >> 8) + 128;
894 int v = ((112 * r - 94 * g - 18 * b + 128) >> 8) + 128;
903 int pos = uy * (w / 2) + ux;
906 uplane[pos] = (uint8_t)std::clamp(sumU / 4, 0, 255);
907 vplane[pos] = (uint8_t)std::clamp(sumV / 4, 0, 255);
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930 bool captureFrameI420_RGB565(uint8_t* dst, size_t ,
931 camera_fb_t* fb,
int w,
int h) {
932 ESP_LOGD(
TAG,
"captureFrameI420_RGB565");
933 rgb565_to_i420(fb->buf, dst, w, h);
934 esp_camera_fb_return(fb);
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959 bool captureFrameI420_YUV422(uint8_t* dst, size_t ,
960 camera_fb_t* fb,
int w,
int h) {
961 ESP_LOGD(
TAG,
"captureFrameI422_YUV422");
962 uint8_t* p = fb->buf;
967 yuyv2iyuv_esp32s3((uint32_t)h, (uint32_t)w, p, dst);
973 esp_camera_fb_return(fb);
979
980
981
982
983
984
985
986
987
988
989
990
994
995
996
997
998
999
1000
1001
1002
1003
1004
1010using namespace esp_h264;
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
H264Encoder()
Default constructor.
Definition: H264Encoder.h:176
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.
Definition: H264Encoder.h:254
sensor_t * getSensor()
Definition: H264Encoder.h:510
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.
Definition: H264Encoder.h:305
bool begin(Config cfg)
Initialize WiFi, camera and H.264 encoder.
Definition: H264Encoder.h:209
void end()
Cleanup and release camera resources.
Definition: H264Encoder.h:494
bool captureFrame(uint8_t *dst, size_t dst_len)
Capture a single frame and write raw I420 data to buffer.
Definition: H264Encoder.h:239
Config defaultConfig()
Create a default configuration with reasonable defaults.
Definition: H264Encoder.h:133
Config defaultConfig(const char *camera)
Create a default configuration based on camera preset name.
Definition: H264Encoder.h:155
static constexpr const char * TAG
Logging tag for ESP32 log system.
Definition: H264Encoder.h:78
~H264Encoder()
Destructor.
Definition: H264Encoder.h:186
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.
Definition: H264Encoder.h:366
esp_h264_err_t esp_h264_enc_close(esp_h264_enc_handle_t enc)
This function closes the H.264 encoder instance specified by enc
Definition: esp_h264_enc_single.c:28
esp_h264_err_t esp_h264_enc_open(esp_h264_enc_handle_t enc)
This function opens an H.264 encoder in single stream.
Definition: esp_h264_enc_single.c:12
esp_h264_err_t esp_h264_enc_process(esp_h264_enc_handle_t enc, esp_h264_enc_in_frame_t *in_frame, esp_h264_enc_out_frame_t *out_frame)
This function performs single encoding of H.264 video frames. To encode one image using an image enco...
Definition: esp_h264_enc_single.c:19
esp_h264_err_t esp_h264_enc_del(esp_h264_enc_handle_t enc)
This function is used to delete an H.264 encoder.
Definition: esp_h264_enc_single.c:35
struct esp_h264_enc_if * esp_h264_enc_handle_t
H.264 single stream encoder handle.
Definition: esp_h264_enc_single.h:19
esp_h264_err_t esp_h264_enc_sw_new(const esp_h264_enc_cfg_sw_t *cfg, esp_h264_enc_handle_t *out_enc)
This function is used to create a new instance of the esp_h264_enc_t data structure,...
Definition: esp_h264_enc_single_sw.c:183
esp_h264_enc_cfg_t esp_h264_enc_cfg_sw_t
Configuration type for software-based H.264 encoder.
Definition: esp_h264_enc_single_sw.h:24
@ ESP_H264_RAW_FMT_I420
Definition: esp_h264_types.h:61
@ ESP_H264_ERR_OK
Definition: esp_h264_types.h:24
void yuyv2iyuv(uint32_t height, uint32_t width, uint8_t *in, uint8_t *out)
Convert YUYV data to I420 data.
Definition: h264_color_convert.c:9
Definition: H264Decoder.h:31
Configuration structure for camera, WiFi, and encoder settings.
Definition: H264Encoder.h:87
int qp_min
Minimum quantizer parameter (default: 28)
Definition: H264Encoder.h:96
size_t outBufferSize
Output buffer size for encoded H.264 data (bytes)
Definition: H264Encoder.h:91
int y8_pin
Camera Y8 pin.
Definition: H264Encoder.h:113
int width
Frame width in pixels.
Definition: H264Encoder.h:88
int reset_pin
Camera RESET pin.
Definition: H264Encoder.h:103
int y4_pin
Camera Y4 pin.
Definition: H264Encoder.h:109
int pwdn_pin
Camera PWDN pin.
Definition: H264Encoder.h:102
int fps
Target frames per second.
Definition: H264Encoder.h:90
int y2_pin
Camera Y2 pin.
Definition: H264Encoder.h:107
pixformat_t pixel_format
Pixel format for camera capture.
Definition: H264Encoder.h:100
int y9_pin
Camera Y9 pin.
Definition: H264Encoder.h:114
int qp_max
Maximum quantizer parameter (default: 30)
Definition: H264Encoder.h:97
int siod_pin
Camera SIOD pin.
Definition: H264Encoder.h:105
int xclk_pin
Camera XCLK pin.
Definition: H264Encoder.h:104
int vsync_pin
Camera VSYNC pin.
Definition: H264Encoder.h:115
int y5_pin
Camera Y5 pin.
Definition: H264Encoder.h:110
int bitrate
Bitrate in bps (default: width*height*fps*30/100)
Definition: H264Encoder.h:95
int pclk_pin
Camera PCLK pin.
Definition: H264Encoder.h:117
int y3_pin
Camera Y3 pin.
Definition: H264Encoder.h:108
int sioc_pin
Camera SIOC pin.
Definition: H264Encoder.h:106
int height
Frame height in pixels.
Definition: H264Encoder.h:89
bool use_camera
Internal flag to track camera state.
Definition: H264Encoder.h:99
int href_pin
Camera HREF pin.
Definition: H264Encoder.h:116
int y7_pin
Camera Y7 pin.
Definition: H264Encoder.h:112
int y6_pin
Camera Y6 pin.
Definition: H264Encoder.h:111
int gop
Group of Pictures (default: fps)
Definition: H264Encoder.h:94
esp_h264_resolution_t res
Definition: esp_h264_types.h:160
uint8_t fps
Definition: esp_h264_types.h:155
esp_h264_raw_format_t pic_type
Definition: esp_h264_types.h:151
uint8_t gop
Definition: esp_h264_types.h:152
esp_h264_enc_rc_t rc
Definition: esp_h264_types.h:161
esp_h264_pkt_t raw_data
Definition: esp_h264_types.h:187
esp_h264_pkt_t raw_data
Definition: esp_h264_types.h:169
uint32_t length
Definition: esp_h264_types.h:170
uint32_t bitrate
Definition: esp_h264_types.h:136
uint8_t qp_max
Definition: esp_h264_types.h:142
uint8_t qp_min
Definition: esp_h264_types.h:140
uint8_t * buffer
Definition: esp_h264_types.h:100
uint32_t len
Definition: esp_h264_types.h:101
uint16_t height
Definition: esp_h264_types.h:119
uint16_t width
Definition: esp_h264_types.h:110