Page 1 of 1

Espressif/esp_camera library and support of JPEG output.

Posted: Mon Dec 29, 2025 10:08 am
by technicalsquirrel
Good morning,

I am quite new to ESP-IDF and so far quite enjoying it.
I have however got a couple questions about the ESP Camera library/driver.
https://github.com/espressif/esp32-camera

I am able to capture JPEG images with little issue with the OV2640 camera modules but it seems that I have issues when swapping it out with say the OV3660 or OV5640.

I am reading the datasheet for the OV3660 for example and it seems the register(s) for JPEG are not the same for the modules.
I.e.
OV2640 has at address `0xDA` 'IMAGE_MODE' which bit 4 enables JPEG output. I assume this is how the esp camera driver works when initialising the camera via config.

OV3660 seems to have different registers for "compression mode" and seems to generally have more "options":
0x3821 COMPRESSION ENABLE
0x4713 COMPRESSION MODE SELECT

The OV5640 seems to again be more similar to OV3660 but has even more options for example:
0x4713 JPG MODE SELECT

I keep scouring the library source code for where these registers are configured but cant seem to see it.
Or is this just the current state of the library and I will need to manually set the registers to get JPEG/Compression working well across the OV* range?

I assume my issues with the OV>2* models is that I am getting bad "jpeg frames" as the output from the sensors is not what the driver expects.

Thank you for any guidance.

Re: Espressif/esp_camera library and support of JPEG output.

Posted: Mon Dec 29, 2025 1:48 pm
by technicalsquirrel
Sorry I eventually found the "camera_model_settings" header files.
For example:
https://github.com/espressif/esp32-came ... settings.h

So I guess this is being handled, but then I keep getting various JPEG issues.
This is with the ESP32S3 with an OV3360.

Code: Select all

I (24) boot: ESP-IDF v5.5.1 2nd stage bootloader
I (24) boot: compile time Dec 23 2025 14:28:28
I (24) boot: Multicore bootloader
I (25) boot: chip revision: v0.2
I (27) boot: efuse block revision: v1.3
I (31) boot.esp32s3: Boot SPI Speed : 80MHz
I (34) boot.esp32s3: SPI Mode       : DIO
I (38) boot.esp32s3: SPI Flash Size : 2MB
I (42) boot: Enabling RNG early entropy source...
I (46) boot: Partition Table:
I (49) boot: ## Label            Usage          Type ST Offset   Length
I (55) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (62) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (68) boot:  2 factory          factory app      00 00 00010000 00100000
I (75) boot: End of partition table
I (78) esp_image: segment 0: paddr=00010020 vaddr=3c040020 size=12a98h ( 76440) map
I (99) esp_image: segment 1: paddr=00022ac0 vaddr=3fc95800 size=056a0h ( 22176) load
I (104) esp_image: segment 2: paddr=00028168 vaddr=40374000 size=07eb0h ( 32432) load
I (112) esp_image: segment 3: paddr=00030020 vaddr=42000020 size=3b8cch (243916) map
I (155) esp_image: segment 4: paddr=0006b8f4 vaddr=4037beb0 size=09894h ( 39060) load
I (164) esp_image: segment 5: paddr=00075190 vaddr=50000000 size=00024h (    36) load
I (165) esp_image: segment 6: paddr=000751bc vaddr=600fe000 size=0006ch (   108) load
I (176) boot: Loaded app from partition at offset 0x10000
I (176) boot: Disabling RNG early entropy source...
I (190) octal_psram: vendor id    : 0x0d (AP)
I (190) octal_psram: dev id       : 0x02 (generation 3)
I (190) octal_psram: density      : 0x03 (64 Mbit)
I (192) octal_psram: good-die     : 0x01 (Pass)
I (196) octal_psram: Latency      : 0x01 (Fixed)
I (201) octal_psram: VCC          : 0x01 (3V)
I (205) octal_psram: SRF          : 0x01 (Fast Refresh)
I (210) octal_psram: BurstType    : 0x01 (Hybrid Wrap)
I (214) octal_psram: BurstLen     : 0x01 (32 Byte)
I (219) octal_psram: Readlatency  : 0x02 (10 cycles@Fixed)
I (224) octal_psram: DriveStrength: 0x00 (1/1)
I (228) esp_psram: Found 8MB PSRAM device
I (232) esp_psram: Speed: 40MHz
I (235) cpu_start: Multicore app
I (969) esp_psram: SPI SRAM memory test OK
I (978) cpu_start: Pro cpu start user code
I (978) cpu_start: cpu freq: 160000000 Hz
I (978) app_init: Application information:
I (978) app_init: Project name:     YLAH
I (982) app_init: App version:      1
I (985) app_init: Compile time:     Dec 29 2025 12:21:07
I (990) app_init: ELF file SHA256:  9f3bd3d05...
I (994) app_init: ESP-IDF:          v5.5.1
I (998) efuse_init: Min chip rev:     v0.0
I (1002) efuse_init: Max chip rev:     v0.99 
I (1006) efuse_init: Chip rev:         v0.2
I (1010) heap_init: Initializing. RAM available for dynamic allocation:
I (1016) heap_init: At 3FC9C130 len 0004D5E0 (309 KiB): RAM
I (1022) heap_init: At 3FCE9710 len 00005724 (21 KiB): RAM
I (1027) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (1032) heap_init: At 600FE06C len 00001F7C (7 KiB): RTCRAM
I (1038) esp_psram: Adding pool of 8192K of PSRAM memory to heap allocator
I (1045) spi_flash: detected chip: generic
I (1048) spi_flash: flash io: dio
W (1051) spi_flash: Detected size(8192k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (1063) sleep_gpio: Configure to isolate all GPIO pins in sleep state
I (1070) sleep_gpio: Enable automatic switching of GPIO sleep configuration
I (1077) main_task: Started on CPU0
I (1087) esp_psram: Reserving pool of 32K of internal memory for DMA/internal allocations
I (1087) main_task: Calling app_main()
I (1127) SD: SD card mounted successfully
I (1127) PSRAM: Free: 8356400 bytes
I (1137) s3 ll_cam: DMA Channel=0
I (1137) cam_hal: cam init ok
I (1137) sccb-ng: pin_sda 4 pin_scl 5
I (1137) sccb-ng: sccb_i2c_port=1
I (1147) camera: Camera PID=0x3660 VER=0x00 MIDL=0x00 MIDH=0x00
I (1147) camera: Detected OV3660 camera
I (1147) camera: Detected camera at address=0x3c
I (1457) cam_hal: PSRAM DMA mode enabled
I (1457) cam_hal: buffer_size: 96000, half_buffer_size: 1024, node_buffer_size: 1024, node_cnt: 93, total_cnt: 94
I (1457) cam_hal: Allocating 97040 Byte frame buffer in PSRAM
I (1457) cam_hal: Frame[0]: Offset: 16, Addr: 0x3C0682B0
I (1467) cam_hal: cam config ok
I (1477) ov3660: Calculated VCO: 200000000 Hz, PLLCLK: 200000000 Hz, SYSCLK: 50000000 Hz, PCLK: 10000000 Hz
I (1497) CAM: ESP-CAMERA configured for 4:11
I (1497) CAM: Model:OV3660 ModelEnum:2 JPEGSupport:1 
cam_hal: NO-EOI - JPEG end marker missing
W (5497) cam_hal: Failed to get frame: timeout
E (5497) CAM: FAILURE TO CAPTURE IMAGE!

Code: Select all

 boot_count++;

    // ============ CAPTURE IMAGES ================

    ESP_ERROR_CHECK(init_camera_x(PIXFORMAT_JPEG, FRAMESIZE_SVGA));

    camera_fb_t *jpg = esp_camera_fb_get();
    IF_CAM_FB_NULL(jpg);
    LOG_CAM_FRAME_DETAILS(jpg);
    sprintf(path, "/sdcard/%i.j", boot_count);
    ESP_ERROR_CHECK(save_to_sd(path, jpg->buf, jpg->len));
    esp_camera_fb_return(jpg);

    ESP_ERROR_CHECK(init_camera_x(PIXFORMAT_GRAYSCALE, FRAMESIZE_SVGA));
    camera_fb_t *gs = esp_camera_fb_get();
    IF_CAM_FB_NULL(gs);
    LOG_CAM_FRAME_DETAILS(gs);
    sprintf(path, "/sdcard/%i.bin", boot_count);
    ESP_ERROR_CHECK(save_to_sd(path, gs->buf, gs->len));
    esp_camera_fb_return(gs);

    multi_heap_info_t info;
    heap_caps_get_info(&info, MALLOC_CAP_SPIRAM);
    ESP_LOGI("MEM", "PSRAM total: %u, free: %u, largest block: %u", info.total_free_bytes, info.total_allocated_bytes, info.largest_free_block);

Code: Select all

esp_err_t init_camera_x(pixformat_t pixformat, framesize_t framesize_t)
{
    camera_config_t config;
    config.ledc_channel = LEDC_CHANNEL_0;
    config.ledc_timer = LEDC_TIMER_0;
    config.pin_d0 = Y2_GPIO_NUM;
    config.pin_d1 = Y3_GPIO_NUM;
    config.pin_d2 = Y4_GPIO_NUM;
    config.pin_d3 = Y5_GPIO_NUM;
    config.pin_d4 = Y6_GPIO_NUM;
    config.pin_d5 = Y7_GPIO_NUM;
    config.pin_d6 = Y8_GPIO_NUM;
    config.pin_d7 = Y9_GPIO_NUM;
    config.pin_xclk = XCLK_GPIO_NUM;
    config.pin_pclk = PCLK_GPIO_NUM;
    config.pin_vsync = VSYNC_GPIO_NUM;
    config.pin_href = HREF_GPIO_NUM;
    config.pin_sccb_sda = SIOD_GPIO_NUM;
    config.pin_sccb_scl = SIOC_GPIO_NUM;
    config.pin_pwdn = PWDN_GPIO_NUM;
    config.pin_reset = RESET_GPIO_NUM;
    config.xclk_freq_hz = 20000000;
    config.frame_size = framesize_t;
    config.pixel_format = pixformat;
    config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
    config.fb_location = CAMERA_FB_IN_PSRAM;
    config.jpeg_quality = 12;
    config.fb_count = 1;

    // camera init
    esp_err_t err = esp_camera_reconfigure(&config);
    if (err != ESP_OK)
    {
        ESP_LOGE("CAM", "Camera init failed with error 0x%x", err);
        return err;
    }

    sensor_t *s = esp_camera_sensor_get();
    camera_sensor_info_t *si = esp_camera_sensor_get_info(&s->id);

    ESP_LOGI("CAM", "ESP-CAMERA configured for %i:%i", pixformat, framesize_t);
    ESP_LOGI("CAM", "Model:%s ModelEnum:%i JPEGSupport:%i ", si->name, si->model, si->support_jpeg);
    return ESP_OK;
}