Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
E

ESP32-CAM_MJPEG2SD

> 开发工具
Open source

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

1.7K stars0 likes2 views
WebsiteGitHub

About

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-CAM_MJPEG2SD

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:

  • Motion detection by camera or PIR / radar sensor / accelerometer
  • Continuous recording - Time lapse or dashcam style
  • Audio Recording from I2S or PDM microphones
  • Camera pan / tilt servos and lamp control
  • RTSP Server stream Video, Audio and Subtitles
  • Telemetry Recording during camera recording.
  • Remote Control of camera mounted vehicle.
  • Alert notification using Telegram or Email
  • Concurrent streaming to web browser and remote NVR using HTTP or RTSP
  • Transfer recordings using FTP, HTTPS, WebDAV, or download from browser
  • MQTT control with Home Assistant integration.
  • External Heartbeat support.
  • Support for peripherals: SG90 servos, MX1508 H-bridge, 28BYJ-48 stepper, HW-504 joystick, BMP280, MPU9250, MY9221 / WS2812 / SK6812 Led
  • Support for I2C devices: BMP280, BME280, MPU6050, MPU9250, SSD1306, LCD1602, etc.
  • Interface for Machine Learning support.
  • Camera Hub feature to access other ESP32-CAM_MJPEG2SD devices.
  • Photogrammetry feature to capture photos for 3D imaging.
  • Use of Auxiliary Board for additional pins.
  • Intercom feature using mic and speaker on ESP and mic and speaker on user device browser.
  • Option of Ethernet network selection instead of Wifi

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:

  • Addition of Ethernet network selection instead of Wifi
  • Pins added for CAMERA_MODEL_Waveshare_ESP32_S3_ETH
  • Define pins for external W5500 Ethernet controller
  • Fix for issue #650
  • Motion detection by MPU6050 or MPU9250 accelerometer
  • Support for OV5640 auto focus
  • Logging and memory usage improvements
  • Fix for issue #697
  • Fix for issue #698
  • Internal improvements
  • Night time duration based on location

Purpose

The 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).

Design

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.

Installation

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:

  • ESP32 Cam board - CAMERA_MODEL_AI_THINKER
  • Freenove ESP32S3 Cam board - CAMERA_MODEL_FREENOVE_ESP32S3_CAM

Optional 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:

  • ESP32 - Minimal SPIFFS (...)
  • ESP32S3 - 8M with spiffs (...) or 16MB(3MB APP...)

NOTE:

  • If you get compilation errors you need to update your arduino-esp32 core library in the IDE to latest v3.x using Boards Manager
  • If you get error: Startup Failure: Check SD card inserted, or Camera init error 0x105 it is usually a camera board selection issue
  • If you get warning: Crash 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.

Main Function

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.

Continuous Recording

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.

Other Functions and Configuration

The operation of the application can be modified dynamically as below, by using the main web page, which should mostly be self explanatory.

Connections:

  • The Wifi/Ethernet choice, Time zone, FTP/HTTPS, SMTP, and authentication parameters can be defined in Access Settings sidebar button.
    • for Time Zone use dropdown, or paste in values from second column here
  • To make the changes persistent, press the Save button
    • For network changes, ESP must be rebooted.
  • mdns name services in order to use http://[Host Name] instead of ip address.

To change the recording parameters:

  • Resolution is the pixel size of each frame
  • Frame Rate is the required frames per second
  • Quality is the level of JPEG compression which affects image size.

SD storage management:

  • Folders or files within folders can be deleted by selecting the required file or folder from the drop down list then pressing the Delete button and confirming.
  • Folders or files within folders can be uploaded to a remote server via FTP / HTTPS by selecting the required file or folder from the drop down list then pressing the File Upload button. Can be uploaded in AVI format.
  • Download selected AVI file from SD card to browser using Download button.
  • Delete, or upload and delete oldest folder when card free space is running out.

View application log via web page, displayed using Show Log tab:

  • Select log type for display:
    • RTC RAM: Cyclic 7KB log saved in RTC RAM (default)
    • Websocket: log is dynamically output via websocket
    • SD card: Unlimited si

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C++arduino-esp32avicameraesp32

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category开发工具
PricingOpen source

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具