Reputation: 11
I have this code in my esp32-cam there is no error, but when 20 seconds of video is recorded, an AVI file is created in the SD card, and it has no size, it is 0 KB and it doesn't show anything. No video or image.
The purpose of this program is to record video for 20 seconds and save it to the SD card
code:
#include "esp_camera.h"
#include "FS.h"
#include "SD_MMC.h"
#include "EEPROM.h"
// Pin definitions for AI-Thinker ESP32-CAM
#define LED_PIN 33
// Camera settings
#define CAMERA_FRAME_SIZE FRAMESIZE_QVGA
#define CAMERA_QUALITY 10
// SD card settings
#define SD_CS_PIN 5
void setup() {
Serial.begin(115200);
delay(1000);
// Initialize the camera
camera_config_t config;
config.ledc_channel = LEDC_CHANNEL_0;
config.ledc_timer = LEDC_TIMER_0;
config.pin_d0 = 5;
config.pin_d1 = 18;
config.pin_d2 = 19;
config.pin_d3 = 21;
config.pin_d4 = 36;
config.pin_d5 = 39;
config.pin_d6 = 34;
config.pin_d7 = 35;
config.pin_xclk = 0;
config.pin_pclk = 22;
config.pin_vsync = 25;
config.pin_href = 23;
config.pin_sscb_sda = 26;
config.pin_sscb_scl = 27;
config.pin_pwdn = 32;
config.pin_reset = -1;
config.pin_xclk = 0;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_JPEG;
config.frame_size = CAMERA_FRAME_SIZE;
config.jpeg_quality = CAMERA_QUALITY;
config.fb_count = 2;
// 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;
}
// Initialize SD card
if (!SD_MMC.begin()) {
Serial.println("SD Card Mount Failed");
return;
}
uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
Serial.printf("SD Card Size: %lluMB\n", cardSize);
// Initialize LED pin
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
}
void loop() {
unsigned long startTime = millis(); // Start time
File videoFile = SD_MMC.open("/video.avi", FILE_WRITE);
if (!videoFile) {
Serial.println("Failed to open file for writing");
return;
}
// AVI header setup
writeAVIHeader(videoFile, 20 * 30); // Approx. 20 seconds at 30 fps
while (millis() - startTime < 20000) { // Record for 20 seconds
camera_fb_t *fb = esp_camera_fb_get();
if (!fb) {
Serial.println("Camera capture failed");
return;
}
// Write the frame data to the AVI file
writeFrame(videoFile, fb);
esp_camera_fb_return(fb);
digitalWrite(LED_PIN, HIGH);
delay(50);
digitalWrite(LED_PIN, LOW);
delay(1000 / 30); // Attempt to maintain 30 fps
}
// Finalize AVI file
finalizeAVIFile(videoFile);
videoFile.close();
Serial.println("Recording complete");
while (true); // Stop further execution
}
// Function to write the AVI header
void writeAVIHeader(File &videoFile, int frameCount) {
// Header code goes here (omitted for brevity)
}
// Function to write a frame to the AVI file
void writeFrame(File &videoFile, camera_fb_t *fb) {
// Frame writing code goes here (omitted for brevity)
}
// Function to finalize the AVI file (e.g., writing index)
void finalizeAVIFile(File &videoFile) {
// Finalization code goes here (omitted for brevity)
}
I asked AI but no answers.
Help!!!!!
Upvotes: 0
Views: 65