10sec video is saved as 1sec video

Hey all. I have this function:

void captureAndWriteVideoToSD(uint16_t videoDurationInSeconds) {
  Serial.println("Starting video capture...");
  
  File videoFile = SD_MMC.open("/video.mp4", FILE_WRITE);
  if (!videoFile) {
    Serial.println("Failed to open/create file for writing");
    return;
  }

  uint32_t startTime = millis();
  uint32_t endTime = startTime + (videoDurationInSeconds * 1000);
  
  while (millis() < endTime) {

    camera_fb_t *fb = esp_camera_fb_get();

    if (fb) {
      // Write frame data to the file
      if (videoFile.write(fb->buf, fb->len) != fb->len) {
        Serial.println("Write error occurred");
        esp_camera_fb_return(fb);
        break;
      }
      esp_camera_fb_return(fb);
    } else {
      Serial.println("Failed to capture frame");
      break;
    }
  }

  // Close the file
  if (videoFile) {
    videoFile.close();
    Serial.println("Video capture complete.");
  } else {
    Serial.println("Error: File not open.");
  }
}

It gets the seconds required to record (as an argument) and start to use the camera. For example, when I pass 10, it records for 10 seconds, i.e. taking frames for 10 seconds and puts into a video file which length is less than 1 second. I tried to play with delay function and change camera settings - no luck. Smells like I need to something with fb buffer. When it puts the data into a file.

Again, the camera captures for 10 second but the resulting video is less than 1 second.

This is the resulting video output in FB group

This is a TRUE-FALSE test. Is this what you really want to do?

By that way I check if the frame was captured. What eslse I can try here/

The way you have it coded, you only capture when fb is zero. Is that what you want? That seems to be what you are current;y getting. Perhaps you want !fb.

Im not sure if we understand each other. Here we see a peace of code, which checks, if frmae buffer is not false - put data into a file. Otherwise if something went wrong - break the loop.

I did what you said and got some exceptions (panic)

This code says if (fb) is true, meaning zero, do something. You are using (fb) as a Boolean in this code. Is this what you intended to write?

false is zero, meaning no frame buffer allocated.

Thanks.

So what I do guys?

Is there really a problem? The ESP32 is not fast enough to capture full frame video at standard rates to SD cards.

Have you counted how many frames are stored in 10 seconds and determined the actual frame rate?

What image size and compression did you specify?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.