Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect FPS logs - CameraWebServer Example Sketch fore ESP32-CAM #10920

Closed
1 task done
TNeutron opened this issue Jan 31, 2025 · 0 comments
Closed
1 task done

Incorrect FPS logs - CameraWebServer Example Sketch fore ESP32-CAM #10920

TNeutron opened this issue Jan 31, 2025 · 0 comments
Labels
Status: Awaiting triage Issue is waiting for triage

Comments

@TNeutron
Copy link
Contributor

TNeutron commented Jan 31, 2025

Board

AI Thinker ESP32-Cam

Device Description

Not attached to anything else.

Hardware Configuration

Using the example sketch directly without modification.

Version

latest master (checkout manually)

IDE Name

Arduino IDE

Operating System

Windows 10

Flash frequency

80

PSRAM enabled

yes

Upload speed

460800

Description

I am trying to get the FPS of the camera feed. The FPS logs are incorrect in the Debug logs.

The logs given appear when I start the server, and stream (320x240) quality frames in my browser.
The video feed looks fairly real-time, therefore, the FPS logged is evidently incorrect.

Sketch

#include "esp_camera.h"
#include <WiFi.h>

//
// WARNING!!! PSRAM IC required for UXGA resolution and high JPEG quality
//            Ensure ESP32 Wrover Module or other board with PSRAM is selected
//            Partial images will be transmitted if image exceeds buffer size
//
//            You must select partition scheme from the board menu that has at least 3MB APP space.
//            Face Recognition is DISABLED for ESP32 and ESP32-S2, because it takes up from 15
//            seconds to process single frame. Face Detection is ENABLED if PSRAM is enabled as well

// ===================
// Select camera model
// ===================
//#define CAMERA_MODEL_WROVER_KIT // Has PSRAM
// #define CAMERA_MODEL_ESP_EYE  // Has PSRAM
//#define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM
//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM
//#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM
//#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM
//#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM
//#define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM
//#define CAMERA_MODEL_M5STACK_CAMS3_UNIT  // Has PSRAM
#define CAMERA_MODEL_AI_THINKER // Has PSRAM
//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM
//#define CAMERA_MODEL_XIAO_ESP32S3 // Has PSRAM
// ** Espressif Internal Boards **
//#define CAMERA_MODEL_ESP32_CAM_BOARD
//#define CAMERA_MODEL_ESP32S2_CAM_BOARD
//#define CAMERA_MODEL_ESP32S3_CAM_LCD
//#define CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3 // Has PSRAM
//#define CAMERA_MODEL_DFRobot_Romeo_ESP32S3 // Has PSRAM
#include "camera_pins.h"

// ===========================
// Enter your WiFi credentials
// ===========================
const char *ssid = "*****";
const char *password = "*******";

void startCameraServer();
void setupLedFlash(int pin);

void setup() {
  Serial.begin(115200);
  Serial.setDebugOutput(true);
  Serial.println();

  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_UXGA;
  config.pixel_format = PIXFORMAT_JPEG;  // for streaming
  //config.pixel_format = PIXFORMAT_RGB565; // for face detection/recognition
  config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
  config.fb_location = CAMERA_FB_IN_PSRAM;
  config.jpeg_quality = 12;
  config.fb_count = 1;

  // if PSRAM IC present, init with UXGA resolution and higher JPEG quality
  //                      for larger pre-allocated frame buffer.
  if (config.pixel_format == PIXFORMAT_JPEG) {
    if (psramFound()) {
      config.jpeg_quality = 10;
      config.fb_count = 2;
      config.grab_mode = CAMERA_GRAB_LATEST;
    } else {
      // Limit the frame size when PSRAM is not available
      config.frame_size = FRAMESIZE_SVGA;
      config.fb_location = CAMERA_FB_IN_DRAM;
    }
  } else {
    // Best option for face detection/recognition
    config.frame_size = FRAMESIZE_240X240;
#if CONFIG_IDF_TARGET_ESP32S3
    config.fb_count = 2;
#endif
  }

#if defined(CAMERA_MODEL_ESP_EYE)
  pinMode(13, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
#endif

  // camera init
  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);
    return;
  }

  sensor_t *s = esp_camera_sensor_get();
  // initial sensors are flipped vertically and colors are a bit saturated
  if (s->id.PID == OV3660_PID) {
    s->set_vflip(s, 1);        // flip it back
    s->set_brightness(s, 1);   // up the brightness just a bit
    s->set_saturation(s, -2);  // lower the saturation
  }
  // drop down frame size for higher initial frame rate
  if (config.pixel_format == PIXFORMAT_JPEG) {
    s->set_framesize(s, FRAMESIZE_QVGA);
  }

#if defined(CAMERA_MODEL_M5STACK_WIDE) || defined(CAMERA_MODEL_M5STACK_ESP32CAM)
  s->set_vflip(s, 1);
  s->set_hmirror(s, 1);
#endif

#if defined(CAMERA_MODEL_ESP32S3_EYE)
  s->set_vflip(s, 1);
#endif

// Setup LED FLash if LED pin is defined in camera_pins.h
#if defined(LED_GPIO_NUM)
  setupLedFlash(LED_GPIO_NUM);
#endif

  WiFi.begin(ssid, password);
  WiFi.setSleep(false);

  Serial.print("WiFi connecting");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  startCameraServer();

  Serial.print("Camera Ready! Use 'http://");
  Serial.print(WiFi.localIP());
  Serial.println("' to connect");
}

void loop() {
  // Do nothing. Everything is done in another task by the web server
  delay(10000);
}

Debug Message

For the following lines in "app_httpd.cpp" -

log_i(
    "MJPG: %uB %ums (%.1ffps), AVG: %ums (%.1ffps)", (uint32_t)(_jpg_buf_len), (uint32_t)frame_time, 1000.0 / (uint32_t)frame_time, avg_frame_time,
     1000.0 / avg_frame_time
   );

We get the following incorrect logs

19:54:58.017 -> ============ After Setup End =============
19:55:05.596 -> [ 79427][I][app_httpd.cpp:103] enable_led(): Set LED intensity to 0
19:55:05.629 -> [ 79462][I][app_httpd.cpp:288] stream_handler(): MJPG: 6931B 35ms (28.6fps), AVG: 35ms (28.6fps)
19:55:05.629 -> [ 79480][I][app_httpd.cpp:288] stream_handler(): MJPG: 6931B 53ms (18.9fps), AVG: 44ms (22.7fps)
19:55:05.673 -> [ 79499][I][app_httpd.cpp:288] stream_handler(): MJPG: 8109B 72ms (13.9fps), AVG: 53ms (18.9fps)
19:55:05.705 -> [ 79532][I][app_httpd.cpp:288] stream_handler(): MJPG: 8109B 105ms (9.5fps), AVG: 66ms (15.2fps)
19:55:05.705 -> [ 79553][I][app_httpd.cpp:288] stream_handler(): MJPG: 6928B 126ms (7.9fps), AVG: 78ms (12.8fps)
19:55:05.750 -> [ 79579][I][app_httpd.cpp:288] stream_handler(): MJPG: 8109B 152ms (6.6fps), AVG: 90ms (11.1fps)
19:55:05.750 -> [ 79601][I][app_httpd.cpp:288] stream_handler(): MJPG: 8109B 174ms (5.7fps), AVG: 102ms (9.8fps)
19:55:05.783 -> [ 79631][I][app_httpd.cpp:288] stream_handler(): MJPG: 8109B 204ms (4.9fps), AVG: 115ms (8.7fps)
19:55:05.828 -> [ 79656][I][app_httpd.cpp:288] stream_handler(): MJPG: 8188B 229ms (4.4fps), AVG: 127ms (7.9fps)
19:55:05.873 -> [ 79680][I][app_httpd.cpp:288] stream_handler(): MJPG: 6569B 253ms (4.0fps), AVG: 140ms (7.1fps)
19:55:05.873 -> [ 79700][I][app_httpd.cpp:288] stream_handler(): MJPG: 6926B 273ms (3.7fps), AVG: 152ms (6.6fps)
19:55:05.912 -> [ 79742][I][app_httpd.cpp:288] stream_handler(): MJPG: 8188B 315ms (3.2fps), AVG: 165ms (6.1fps)
19:55:05.912 -> [ 79763][I][app_httpd.cpp:288] stream_handler(): MJPG: 6680B 336ms (3.0fps), AVG: 179ms (5.6fps)
19:55:05.985 -> [ 79810][I][app_httpd.cpp:288] stream_handler(): MJPG: 7111B 383ms (2.6fps), AVG: 193ms (5.2fps)
19:55:05.985 -> [ 79836][I][app_httpd.cpp:288] stream_handler(): MJPG: 7111B 409ms (2.4fps), AVG: 207ms (4.8fps)
19:55:06.021 -> [ 79872][I][app_httpd.cpp:288] stream_handler(): MJPG: 8212B 445ms (2.2fps), AVG: 222ms (4.5fps)
19:55:06.090 -> [ 79920][I][app_httpd.cpp:288] stream_handler(): MJPG: 7013B 492ms (2.0fps), AVG: 238ms (4.2fps)
19:55:06.090 -> [ 79941][I][app_httpd.cpp:288] stream_handler(): MJPG: 7093B 514ms (1.9fps), AVG: 253ms (4.0fps)
19:55:06.225 -> [ 80076][I][app_httpd.cpp:288] stream_handler(): MJPG: 7303B 649ms (1.5fps), AVG: 274ms (3.6fps)
19:55:06.258 -> [ 80103][I][app_httpd.cpp:288] stream_handler(): MJPG: 6693B 676ms (1.5fps), AVG: 294ms (3.4fps)
19:55:06.303 -> [ 80131][I][app_httpd.cpp:288] stream_handler(): MJPG: 6693B 703ms (1.4fps), AVG: 328ms (3.0fps)
19:55:06.340 -> [ 80163][I][app_httpd.cpp:288] stream_handler(): MJPG: 6699B 736ms (1.4fps), AVG: 362ms (2.8fps)
19:55:06.340 -> [ 80191][I][app_httpd.cpp:288] stream_handler(): MJPG: 7361B 764ms (1.3fps), AVG: 396ms (2.5fps)
19:55:06.379 -> [ 80216][I][app_httpd.cpp:288] stream_handler(): MJPG: 6936B 789ms (1.3fps), AVG: 431ms (2.3fps)
19:55:06.424 -> [ 80239][I][app_httpd.cpp:288] stream_handler(): MJPG: 7714B 812ms (1.2fps), AVG: 465ms (2.2fps)
19:55:06.456 -> [ 80280][I][app_httpd.cpp:288] stream_handler(): MJPG: 7714B 853ms (1.2fps), AVG: 500ms (2.0fps)
19:55:06.456 -> [ 80300][I][app_httpd.cpp:288] stream_handler(): MJPG: 6536B 872ms (1.1fps), AVG: 535ms (1.9fps)
19:55:06.488 -> [ 80337][I][app_httpd.cpp:288] stream_handler(): MJPG: 8124B 909ms (1.1fps), AVG: 570ms (1.8fps)
19:55:06.527 -> [ 80355][I][app_httpd.cpp:288] stream_handler(): MJPG: 6495B 927ms (1.1fps), AVG: 605ms (1.7fps)
19:55:06.527 -> [ 80378][I][app_httpd.cpp:288] stream_handler(): MJPG: 8124B 951ms (1.1fps), AVG: 640ms (1.6fps)
19:55:06.609 -> [ 80423][I][app_httpd.cpp:288] stream_handler(): MJPG: 6936B 996ms (1.0fps), AVG: 676ms (1.5fps)
19:55:06.651 -> [ 80477][I][app_httpd.cpp:288] stream_handler(): MJPG: 8124B 1050ms (1.0fps), AVG: 713ms (1.4fps)
19:55:06.651 -> [ 80502][I][app_httpd.cpp:288] stream_handler(): MJPG: 6654B 1075ms (0.9fps), AVG: 750ms (1.3fps)
19:55:06.733 -> [ 80549][I][app_httpd.cpp:288] stream_handler(): MJPG: 8124B 1122ms (0.9fps), AVG: 787ms (1.3fps)
19:55:06.817 -> [ 80667][I][app_httpd.cpp:288] stream_handler(): MJPG: 7021B 1240ms (0.8fps), AVG: 828ms (1.2fps)
19:55:06.936 -> [ 80760][I][app_httpd.cpp:288] stream_handler(): MJPG: 8124B 1333ms (0.8fps), AVG: 873ms (1.1fps)
19:55:06.936 -> [ 80787][I][app_httpd.cpp:288] stream_handler(): MJPG: 6550B 1360ms (0.7fps), AVG: 916ms (1.1fps)
19:55:06.977 -> [ 80807][I][app_httpd.cpp:288] stream_handler(): MJPG: 8124B 1380ms (0.7fps), AVG: 959ms (1.0fps)
19:55:07.017 -> [ 80835][I][app_httpd.cpp:288] stream_handler(): MJPG: 6956B 1407ms (0.7fps), AVG: 997ms (1.0fps)
19:55:07.017 -> [ 80868][I][app_httpd.cpp:288] stream_handler(): MJPG: 8124B 1441ms (0.7fps), AVG: 1036ms (1.0fps)
19:55:07.100 -> [ 80906][I][app_httpd.cpp:288] stream_handler(): MJPG: 6563B 1479ms (0.7fps), AVG: 1074ms (0.9fps)
19:55:07.100 -> [ 80924][I][app_httpd.cpp:288] stream_handler(): MJPG: 7057B 1497ms (0.7fps), AVG: 1112ms (0.9fps)
19:55:07.143 -> [ 80959][I][app_httpd.cpp:288] stream_handler(): MJPG: 7057B 1531ms (0.7fps), AVG: 1151ms (0.9fps)
19:55:07.143 -> [ 80994][I][app_httpd.cpp:288] stream_handler(): MJPG: 8124B 1567ms (0.6fps), AVG: 1190ms (0.8fps)
19:55:07.175 -> [ 81026][I][app_httpd.cpp:288] stream_handler(): MJPG: 6428B 1598ms (0.6fps), AVG: 1229ms (0.8fps)
19:55:07.208 -> [ 81048][I][app_httpd.cpp:288] stream_handler(): MJPG: 6806B 1621ms (0.6fps), AVG: 1267ms (0.8fps)
19:55:07.245 -> [ 81071][I][app_httpd.cpp:288] stream_handler(): MJPG: 7034B 1644ms (0.6fps), AVG: 1306ms (0.8fps)
19:55:07.245 -> [ 81096][I][app_httpd.cpp:288] stream_handler(): MJPG: 7139B 1669ms (0.6fps), AVG: 1344ms (0.7fps)
19:55:07.277 -> [ 81120][I][app_httpd.cpp:288] stream_handler(): MJPG: 8124B 1693ms (0.6fps), AVG: 1382ms (0.7fps)
19:55:07.310 -> [ 81160][I][app_httpd.cpp:288] stream_handler(): MJPG: 8124B 1733ms (0.6fps), AVG: 1421ms (0.7fps)
19:55:07.343 -> [ 81194][I][app_httpd.cpp:288] stream_handler(): MJPG: 8124B 1767ms (0.6fps), AVG: 1460ms (0.7fps)
19:55:07.375 -> [ 81219][I][app_httpd.cpp:288] stream_handler(): MJPG: 6764B 1791ms (0.6fps), AVG: 1497ms (0.7fps)
19:55:07.455 -> [ 81276][I][app_httpd.cpp:288] stream_handler(): MJPG: 8124B 1849ms (0.5fps), AVG: 1536ms (0.7fps)
19:55:07.547 -> [ 81376][I][app_httpd.cpp:288] stream_handler(): MJPG: 6826B 1949ms (0.5fps), AVG: 1577ms (0.6fps)
19:55:07.579 -> [ 81400][I][app_httpd.cpp:288] stream_handler(): MJPG: 6826B 1972ms (0.5fps), AVG: 1614ms (0.6fps)
19:55:07.579 -> [ 81423][I][app_httpd.cpp:288] stream_handler(): MJPG: 8124B 1996ms (0.5fps), AVG: 1647ms (0.6fps)
19:55:07.617 -> [ 81444][I][app_httpd.cpp:288] stream_handler(): MJPG: 6966B 2016ms (0.5fps), AVG: 1680ms (0.6fps)
19:55:07.617 -> [ 81467][I][app_httpd.cpp:288] stream_handler(): MJPG: 8124B 2040ms (0.5fps), AVG: 1713ms (0.6fps)
19:55:07.687 -> [ 81509][I][app_httpd.cpp:288] stream_handler(): MJPG: 7040B 2081ms (0.5fps), AVG: 1746ms (0.6fps)
19:55:07.687 -> [ 81535][I][app_httpd.cpp:288] stream_handler(): MJPG: 7040B 2108ms (0.5fps), AVG: 1780ms (0.6fps)
19:55:07.720 -> [ 81568][I][app_httpd.cpp:288] stream_handler(): MJPG: 8124B 2141ms (0.5fps), AVG: 1813ms (0.6fps)
19:55:07.760 -> [ 81588][I][app_httpd.cpp:288] stream_handler(): MJPG: 6700B 2161ms (0.5fps), AVG: 1846ms (0.5fps)
19:55:07.800 -> [ 81631][I][app_httpd.cpp:288] stream_handler(): MJPG: 6940B 2204ms (0.5fps), AVG: 1880ms (0.5fps)
19:55:07.800 -> [ 81651][I][app_httpd.cpp:288] stream_handler(): MJPG: 6940B 2223ms (0.4fps), AVG: 1912ms (0.5fps)
19:55:07.834 -> [ 81679][I][app_httpd.cpp:288] stream_handler(): MJPG: 8124B 2252ms (0.4fps), AVG: 1945ms (0.5fps)
19:55:07.868 -> [ 81704][I][app_httpd.cpp:288] stream_handler(): MJPG: 6814B 2277ms (0.4fps), AVG: 1978ms (0.5fps)
19:55:07.905 -> [ 81736][I][app_httpd.cpp:288] stream_handler(): MJPG: 8124B 2309ms (0.4fps), AVG: 2011ms (0.5fps)
19:55:07.905 -> [ 81756][I][app_httpd.cpp:288] stream_handler(): MJPG: 7000B 2329ms (0.4fps), AVG: 2044ms (0.5fps)
19:55:07.945 -> [ 81775][I][app_httpd.cpp:288] stream_handler(): MJPG: 7000B 2348ms (0.4fps), AVG: 2077ms (0.5fps)
19:55:07.989 -> [ 81815][I][app_httpd.cpp:288] stream_handler(): MJPG: 8124B 2388ms (0.4fps), AVG: 2110ms (0.5fps)
19:55:07.989 -> [ 81840][I][app_httpd.cpp:288] stream_handler(): MJPG: 6466B 2413ms (0.4fps), AVG: 2142ms (0.5fps)
19:55:08.064 -> [ 81894][I][app_httpd.cpp:288] stream_handler(): MJPG: 6572B 2467ms (0.4fps), AVG: 2176ms (0.5fps)
19:55:08.064 -> [ 81915][I][app_httpd.cpp:288] stream_handler(): MJPG: 6985B 2488ms (0.4fps), AVG: 2208ms (0.5fps)
19:55:08.145 -> [ 81956][I][app_httpd.cpp:288] stream_handler(): MJPG: 7082B 2529ms (0.4fps), AVG: 2237ms (0.4fps)
19:55:08.190 -> [ 82040][I][app_httpd.cpp:288] stream_handler(): MJPG: 7082B 2613ms (0.4fps), AVG: 2269ms (0.4fps)
19:55:08.637 -> [ 82443][I][app_httpd.cpp:288] stream_handler(): MJPG: 7082B 3015ms (0.3fps), AVG: 2320ms (0.4fps)

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@TNeutron TNeutron added the Status: Awaiting triage Issue is waiting for triage label Jan 31, 2025
TNeutron added a commit to TNeutron/arduino-esp32 that referenced this issue Jan 31, 2025
Previously, last_frame was only updated once at the beginning of stream_handler,
leading to incorrect FPS and avg_frame_time computation.

This commit ensures last_frame is updated on each iteration after last FPS computation,
resulting in accurate FPS logging.

Fixes espressif#10920
TNeutron added a commit to TNeutron/arduino-esp32 that referenced this issue Jan 31, 2025
Corrected and tested change in FPS computation, suggested by @me-no-dev and found working with correct numbers.

Previously, last_frame was only updated once at the beginning of stream_handler,
leading to incorrect FPS and avg_frame_time computation.

This commit ensures last_frame is updated on each iteration after last FPS computation,
resulting in accurate FPS logging.

Fixes espressif#10920
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting triage Issue is waiting for triage
Projects
None yet
Development

No branches or pull requests

1 participant