jameszah / ESP32-CAM-Video-Recorder

Video Recorder for ESP32-CAM with http server for config and ftp (or http) server to download video
GNU General Public License v3.0
456 stars 102 forks source link
avi esp32 esp32-cam esp32-cam-video-recorder ftp-server mjpeg ov2640 pir video-recorder

ESP32-CAM-Video-Recorder

Video Recorder for ESP32-CAM with http server for config and ftp server to download video

TimeLapseAvi

ESP32-CAM Video Recorder

This program records an MJPEG AVI video on the SD Card of an ESP32-CAM.

by James Zahary July 20, 2019 jamzah.plc@gmail.com

https://github.com/jameszah/ESP32-CAM-Video-Recorder

jameszah/ESP32-CAM-Video-Recorder is licensed under the GNU General Public License v3.0

vA1 for arduino-esp32 2.0.2
v99 for arduino-esp32 1.0.6
v98 for arduino-esp32 1.0.4

Update Jan 12, 2022 - esp32-arduino 2.0.2 and replace ftp with http file transfer

Version A1 - Jan 1, 2022

The esp32-arduino 2.0.2 contains some nicer camera code that clears away little glitches that used to pop up.
It is very clean now!

You can hardcode your ssid and password into settings.h, or put in a 1 character long ssid, and it will use WiFiManager to set your ssid and password. If you want Telegram bot to work, you still have to hardcode them into settings.h

More commentary coming ... and refinements ... test it before you use it.

Also the newer quicker version (with fewer features) over at https://github.com/jameszah/ESP32-CAM-Video-Recorder-junior

You can download the videos to your computer or phone with just a click on the file from your browser -- no need for an ftp program anymore!

If you have the telegram bot turned on, it will send your telegram app the first frame of a new recording, and give you a link to the previous recording for you to download to your phone or computer with one click.

Jan 17, 2022 - small update to fix the file delete when disk full required by 2.0.2


old stuff below - might contain details not applicable to current version


Note line 1413 -- this current version uses the WiFiManager for all WiFi setup. Change this line if you want to use the previous version of hardcoded ssid and password.

https://github.com/jameszah/ESP32-CAM-Video-Recorder/blob/f90207b74c8ac247ef20f3cde9664b5f80844a02/v99/TimeLapseAvi99x.ino#L1413

Update Sep 1, 2021 - small update for arduino-esp32 1.0.6

Minimal update for arduino-esp32 1.0.6.

The framesizes numbers changed which I had used on the http url command, so those were updated.
Add the new frame size HD (1280x720).
Some updates for the new SSL libraries to keep the telegram interface working.
You need all the files in the v99 folder. And Arduino esp32 board library set to 1.0.6.
You can still use the previous version with the esp32 board library set to 1.0.4.

Lightly tested!

More frequent updates with better code at these spin-offs of this original project.

https://github.com/jameszah/ESP32-CAM-Video-Recorder-junior
This simple fast recording and streaming, with http just for information - no controls or ftp.

https://github.com/jameszah/ESP32-CAM-Video-Telegram
This records and sends a short video to telegram on request or PIR event, using the telegram interface.

Update Jun 10, 2021 - new program to check out

It records a video and sends it to your Telegram account - no SD card! Now I just need to do some updates on this one!

https://github.com/jameszah/ESP32-CAM-Video-Telegram

Update Mar 17, 2021 - arduino-esp32 ver 1.05

It would be best to use arduino-esp32 version 1.04 until I scan through this for update problems.
1.05 was released in late Feb 2021, has has some new framesizes, aspect rations, and some changes in the WiFi, that need some code changes.

image

Update Jan 06, 2021 - Version 98-WiFiMan

Just the same as Verion 98, but you can configure the ssid and password using WiFiManager.
Use the normal WiFiManager procedure to set up ssid with 192.168.4.1 etc https://github.com/tzapu/WiFiManager The only difference is that you have to reboot the esp32 after you have set the ssid/pass for it to work correctly. Read more about it here https://github.com/tzapu/WiFiManager/issues/1184

And you must use the latest WiFiManager code which supports the ESP32 - currently 2.0.3-alpha which can be installed from Arduino IDE - Manage Libraries. The WiFiManager could be enhanced to set parameters that cannot be set from hhtp, such as Telegram name and password, but haven't done that yet.

https://github.com/jameszah/ESP32-CAM-Video-Recorder/tree/master/v98-WiFiMan

Update Sep 29, 2020 - Version 98

Added a feature to automatically delete your oldest day of videos when the SD reaches 90% full.

There are also some compile directives in the settings.h file to cut out entire sections of code like the ftp or telegram, if you need resouces to add your own stuff.

Update Sep 13, 2020

Check out a much simpler, somewhat faster version ESP32-CAM-Video_Recorder-junior.

It gets rid of wifi, http, time, ftp, telegram, pir, touch, .... and just records very fast -- pretty much at the full speed of the camera -- with a decent SD card and reasonable quality parameters.

The latest version of junior v07 adds back the streaming video, and series of photos over wifi, and will record at 6 fps UXGA and 24 fps SVGA, but otherwise remains quite uncomplicated.

https://github.com/jameszah/ESP32-CAM-Video-Recorder-junior

Update Aug 29, 2020 Version 94 - live stream and filter bad jpegs

A couple new things.

I added some code to filter out bad jpegs. This happens when you have high quality jpeg settings, and then take a movie in bright light, and some of the jpegs exceed the memory allocated, and you get a partial jpeg, which will screw up the index, and break an entire avi. So there is now code to find those bad jpegs, and get a new frame that is good. Read more about this here if interested. https://github.com/espressif/esp32-camera/issues/162

This means it is safe to increase the jpeg quality to 7 (maybe 6?) from the standard setting of 10, or 12 in bright sun. Lower number is higher quality. Higher quality will mean more bytes, bigger files, and slower to write. It is debatable if you want very high quality jpegs if they are flashing along at 24 frames per second.

Another new feature is a streaming video. There is the single frame on the main status screen so you code see what your camera sees, but the streaming has been much requested to get a better look through the viewfinder, and maybe save the stream.

You set a parameter in settings.h of milli-seconds between updates, and then click on the /stream link on the main web page and it will stream to a new browser window. Hit "back" to get back to the main page.

To save the video coming to the browser, do the following -- I tried to figure this out before but could not find it on google.

  1. Click on the /stream on the web page, and you will see the moving picture.
  2. Right-click and select "save image as ...", type a name, and it will start saving the series of jpegs to a file.
  3. You have to stop the save, which as far as I can figure out, you have to select cancel from the menu of the ever increasing file. But that will delete the file that you have been saving. So the kludge is to "show in folder" to find the file, then copy the file, then do the cancel. Then you have to rename that file to x.mjpeg, and then you can play it. Most programs that play .avi files will not play the .mjpeg, but some will. See VLC below. Very inelegant.

Another method is to use the VLC media player program.

  1. Media - Open Network Stream - paste in the url such as http://192.168.1.90/stream
  2. Then in the Play menu, switch it to Convert, click on "Dump Raw Input" and type filename ending in .mjpeg, and click Start. When you are down saving, click the square stop button. You will get a .mjpeg file which can be played in VLC and some other video or picture players. An mjpeg does not understand time, so it will play the picture as quick as it can, and you have have to enter new information about the time between frames to get it to play as you want.

VLC seems to have controls there to convert the file to various formats like h264, wmv, etc. but I could not get that to work.

If anyone has better ways to capture the live stream, or capture and covert it, please let us know in the comments.

I have not really studied how the streaming interacts with the recording. But 3 fps streaming seems to work fine with 8 fps svga recording. More work to be done there. I reduced the http task priorty to below the picture-taking and avi-writing tasks, so the the streaming should slow down before the recording. It seems the esp32 http server can only handle one client at a time, so you cannot stream to one browser and check the status on another browser.

Another small feature is that you can now tell the recorder to /stop, and then /start with no parameters, and it will restart according to the original start parameters. Not only the framesize and interval, but if you set it to record 100 videos, and it has 5 left, after a /stop and /start it will restart at 100 videos.

Also if you have some parameters in EPROM, and your are doing a new compile with changes and you do not want to use those EPROM parameters, there is a setting called MagicNumber in the settings.h. Just change the MagicNumber, and the program will skip the EPROM settings and write your new settings from settings.h

I changed to default startup settings to VGA 10 frames per second, play at realtime, with no PIR or BOT.

Update Jul 15, 2020 Version 89 - more new stuff

The serial debug monitor shows you your ip address, and the web page uses the ip, rather than hoping that you can resolve mDNS everytime.

You just need the files from the /v89 folder. Edit the settings.h file for your wifi and startup configuration.

Update Jun 30, 2020 Version 86 - some new features

Software

Here is the "/" status page

And the /stop page to restart with new parameters

And what it looks like on your phone Telegram App

Update Feb 29, 2020 Sample Hardware for Microwave Camera

This is a bit of hardware to set up a camera recording to SD Card whenever something moves, as seen through a microwave device, and adds a led so you can see when the camera sees you!

Update Feb 25, 2020 Sample Hardware for PIR Camera

This is a bit of hardware to set up a camera recording to SD Card whenever something moves.

(my microUSB adapter is different from the one in the library)

Update Feb 26, 2020 TimeLapseAvi60x.ino

New version # 60

Also, someone did an instructables.com explanation and video about the Sep 15, 2019 version, which is not bad.
I am refered to as "The Team" :-)

https://www.instructables.com/id/Video-Capture-Using-the-ESP32-CAM-Board/

Other general advice about the ESP32-CAM.

Update Feb 18, 2020

It is a similar program, but makes a ".mjpeg" file rather than an ".avi" file.

It will also give you the live-stream through the camera to your browser, it will play the videos for you through the browser, and it will record based on a PIR or other sensor that grounds a pin.

And it solves the "Blinding Disk-Active Light" without any soldering or tape.

Reference by amirjak over in the "Issues" section.

I will be borrowing a few of these good ideas in days to come!

Update Oct 15, 2019

Update Sep 15, 2019 TimeLapseAvi39x.ino

"work-in-progress" I'm publishing this as a few people have been asking or working on this.

Original July 2019 Intro

Acknowlegements:

  1. https://robotzero.one/time-lapse-esp32-cameras/ Timelapse programs for ESP32-CAM version that sends snapshots of screen.
  2. https://github.com/nailbuster/esp8266FTPServer ftp server (slightly modifed to get the directory function working)
  3. https://github.com/ArduCAM/Arduino/tree/master/ArduCAM/examples/mini ArduCAM Mini demo (C)2017 LeeWeb: http://www.ArduCAM.com I copied the structure of the avi file, some calculations.

    The is Arduino code, with standard setup for ESP32-CAM

    • Board ESP32 Wrover Module
    • Partition Scheme Huge APP (3MB No OTA)

    This program records an AVI video on the SD Card of an ESP32-CAM.

    It will record realtime video at limited framerates, or timelapses with the full resolution of the ESP32-CAM. It is controlled by a web page it serves to stop and start recordings with many parameters, and look through the viewfinder.

    You can control framesize (UXGA, VGA, ...), quality, length, and fps to record, and fps to playback later, etc.

    There is also an ftp server to download the recordings to a PC.

    Instructions:

    The program uses a fixed IP of 192.168.1.222, so you can browse to it from your phone or computer.

    http://192.168.1.222/ -- this gives you the status of the recording in progress and lets you look through the viewfinder

    http://192.168.1.222/stop -- this stops the recording in progress and displays some sample commands to start new recordings

    ftp://192.168.1.222/ -- gives you the ftp server

    The ftp for esp32 seems to not be a full ftp. The Chrome Browser and the Windows command line ftp's did not work with this, but the Raspbarian command line ftp works fine, and an old Windows ftp I have called CoffeeCup Free FTP also works, which is what I have been using. You can download at about 450 KB/s -- which is better than having to retreive the SD chip if you camera is up in a tree!

http://192.168.1.222/start?framesize=VGA&length=1800&interval=250&quality=10&repeat=100&speed=1&gray=0
-- this is a sample to start a new recording

These factors have to be within the limit of the SD chip to receive the data. For example, using a LEXAR 300x 32GB microSDHC UHS-I, the following works for me:

If you increase fps, you might have to reduce quality or framesize to keep it from dropping frames as it writes all the data to the SD chip.

Also, other SD chips will be faster or slower. I was using a SanDisk 16GB microSDHC "Up to 653X" - which was slower and more unpredictable than the LEXAR ???

Search for "zzz" to find places to modify the code for:

  1. Your wifi name and password
  2. Your preferred ip address (with default gateway, etc)
  3. Your Timezone for use in filenames
  4. Defaults for framesize, quality, ... and if the recording should start on reboot of the ESP32 without receiving a command

Sample videos produced by the program in the /sample-output folder -- it is not GoPro quality, but then GoPro's don't cost $10.

While not necessay, following is how I dealt with the "Flash" led on the front of the ESP32-CAM chip.

Picture below shows my solution to the "Flash" led, aka "the Blinding Disk-Active light". The led turns on whenever you are are writing data to the SD chip, which is normally after you have taken the picture, so you don't need the flash on any more!

Quick de-solder of the collector on the top of the J3Y transistor just above the led, then put in some tape to keep it clear -- you can solder it back later if you want to use it.