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