ESP32 Camera motion capture application to record JPEGs to SD card as AVI files and stream to browser as MJPEG. If a microphone is installed then a WAV file is
ESP32 Camera motion capture application to record JPEGs to SD card as AVI files and stream to browser as MJPEG. If a microphone is installed then a WAV file is
Application for ESP32 / ESP32S3 with OV2640 / OV3660 / OV5640 / PY260 camera to record JPEGs to SD card as AVI files and playback to browser as an MJPEG stream. The AVI format allows recordings to replay at correct frame rate on media players. If a microphone is installed then a WAV file is also created and stored in the AVI file.
The application supports:
The ESP32 cannot support all of the features as it will run out of heap space. For better functionality and performance, use one of the new ESP32S3 camera boards, eg Freenove ESP32S3 Cam, ESP32S3 XIAO Sense, ESP32-S3-Cam (AI Thinker style), but avoid no-name boards marked ESPS3 RE:1.0
This is a complex app and some users are raising issues when the app reports a warning, but this is the app notifying the user that there is an problem with their setup, which only the user can fix. Be aware that some clone boards have different specs to the original, eg PSRAM size. Please only raise issues for actual bugs (ERR messages, unhandled library error or crash). Thanks.
To suggest an improvement or enhancement use Discussions.
Changes for version up to 10.9.5:
CAMERA_MODEL_Waveshare_ESP32_S3_ETHThe application enables video capture of motion detection or continuous recording. Examples include security cameras, wildlife monitoring, rocket flight monitoring, FPV vehicle control.
Saving a set of JPEGs as a single file is faster than as individual files and is easier to manage, particularly for small image sizes. Actual rate depends on quality and size of SD card and complexity and quality of images. A no-name 4GB SDHC labelled as Class 6 was 3 times slower than a genuine Sandisk 4GB SDHC Class 2. The following recording rates were achieved on a freshly formatted Sandisk 4GB SDHC Class 2 on a AI Thinker OV2640 board, set to maximum JPEG quality and clock rate of 20MHz. With a clock rate of 24Mhz on ESP32S3, the maximum frame rates can increase 50->60, 25->30 but it may be necessary to reduce JPEG quality.
| Frame Size | OV2640 camera max fps | mjpeg2sd max fps | Detection time ms |
|---|---|---|---|
| 96X96 | 50 | 45 | 15 |
| QQVGA | 50 | 45 | 20 |
| QCIF | 50 | 45 | 30 |
| HQVGA | 50 | 45 | 40 |
| 240X240 | 50 | 45 | 55 |
| QVGA | 50 | 40 | 70 |
| CIF | 50 | 40 | 110 |
| HVGA | 50 | 40 | 130 |
| VGA | 25 | 20 | 80 |
| SVGA | 25 | 20 | 120 |
| XGA | 12.5 | 5 | 180 |
| HD | 12.5 | 5 | 220 |
| SXGA | 12.5 | 5 | 300 |
| UXGA | 12.5 | 5 | 450 |
The ESP32S3 (using Freenove ESP32S3 Cam board hosting ESP32S3 N8R8 module) runs the app about double the speed of the ESP32 mainly due to much faster PSRAM. It can record at the maximum OV2640 frame rates including audio for all frame sizes except UXGA (max 10fps).
The ESP32 Cam module has 4MB of PSRAM (8MB on most ESP32S3) which is used to buffer the camera frames and the construction of the AVI file to minimise the number of SD file writes, and optimise the writes by aligning them with the SD card sector size. For playback the AVI is read from SD into a multiple sector sized buffer, and sent to the browser as timed individual frames. By dewfault the SD card is used in MMC 1 line mode, as this is practically as fast as MMC 4 line mode on the ESP32 and frees up pin 4 (connected to onboard Lamp), and pin 12 which can be used for eg a PIR. On the ESP32S3 however, tests by @josef2600 indicate that MMC 4 line mode provides a doubling of speed.
The AVI files are named using a date time format YYYYMMDD_HHMMSS with added frame size, FPS recording rate, duration in secs, eg 20200130_201015_VGA_15_60.avi, and stored in a per day folder YYYYMMDD. If audio is included the filename ends with _S. If telemetry is available the filename ends with _M.
The ESP32 time is set from an NTP server or connected browser client.
Download github files into the Arduino IDE sketch folder, removing -master from the application folder name.
Compile with at least arduino-esp32 core v3.1.1 which contains network fixes and frame selection changes.
Select the required ESP-CAM board by uncommenting ONE only of the #define CAMERA_MODEL_* in ESP32-CAM_MJPEG2SD.h unless using the one of the defaults:
CAMERA_MODEL_AI_THINKERCAMERA_MODEL_FREENOVE_ESP32S3_CAMOptional features are not included by default. To include a feature, in ESP32-CAM_MJPEG2SD.h set relevant #define INCLUDE_* to true.
Select the ESP32 or ESP32S3 Dev Module board and compile with PSRAM enabled and the following Partition scheme:
Minimal SPIFFS (...)8M with spiffs (...) or 16MB(3MB APP...)NOTE:
arduino-esp32 core library in the IDE to latest v3.x
using Boards ManagerStartup Failure: Check SD card inserted, or Camera init error 0x105 it is usually a camera board selection issueCrash loop detected, check log, it is usually an inadequate power supply.On first installation, the application will start in wifi AP mode - connect to SSID: ESP-CAM_MJPEG_..., to allow router to be selected and router password entered via the web page on 192.168.4.1. The configuration data file (except passwords) is automatically created, and the application web pages automatically downloaded from GitHub to the SD card /data folder when an internet connection is available.
Subsequent updates to the application, or to the /data folder files, can be made using the OTA Upload tab. The /data folder can also be reloaded from GitHub using the Reload /data button on the Edit Config tab, or by using a WebDAV client.
An alternative installation process by @ldijkman is described here.
Browser functions only fully tested on Chrome.
A recording is generated either by the camera itself detecting motion, or by holding a given pin high (kept low by internal pulldown when released), eg by using an active high motion sensor such as a PIR (HC-SR501) or microwave radar (CWL-0516), or an I2C accelerometer (MPU6050), or a non motion detector such as a sound sensor (KY-037). In addition a recording can be requested manually using the Start Recording button on the web page.
To play back a recording, select the file using Playback & File Transfers sidebar button to select the day folder then the required AVI file. After selecting the AVI file, press Start Playback button to playback the recording. The Start Stream button shows a live video only feed from the camera.
Recordings can then be uploaded to an FTP or HTTPS server or downloaded to the browser for playback on a media application, eg VLC.
To incorporate FTP or HTTPS server, set #define INCLUDE_FTP_HFS to true.
A time lapse feature is available which can run in parallel with motion capture. Select Time Lapse button under Motion Detect & Recording sidebar button. Time Lapse configuration is under Motion button in Edit Config tab. Time lapse files have the format 20200130_201015_VGA_15_60_T.avi.
A continuous recording feature generates a sequence of files from power up, similar to dashcam recording style. Use DashCam slider in Motion Detect & Recording sidebar button to select a value representing the length in minutes of each file. Need to press Save Settings button then Reboot ESP to commence recording. Select slider value 0 to switch off feature. Creates file names with format 20200130_201015_VGA_15_60_C.avi. Motion detection is disabled while continuous recording is running.
Time Lapse & Dashcam features are mutually exclusive.
The operation of the application can be modified dynamically as below, by using the main web page, which should mostly be self explanatory.
Connections:
http://[Host Name] instead of ip address.To change the recording parameters:
Resolution is the pixel size of each frameFrame Rate is the required frames per secondQuality is the level of JPEG compression which affects image size.SD storage management:
View application log via web page, displayed using Show Log tab:
No open issues yet, or sync has not completed.