Not working to do snapshot or recording using ESP32 CAM

Hello All. I am here to ask you the function for snapshot or recording using the ESPcam.

I bought the ESpcam mentioned in the link below.

And I think that it is gorgeous to use the camera with a very low price. But I got to know that this Camera dosenot support the snapshot or recording function.

i got the error mesage like below when i tried to do it by following the instruction from the official homeassistant.io site. ( https://www.home-assistant.io/components/stream )

–> Error Message: camera.espcam does not support record service

The reason why i bought this is for the Surveilance by automation and I need to record or get a snapshot to send it to me by telegram or any other ones.

Therefore, Is there anyone who has a solution about this?

THank you in advance.

I had the same concern and wrote a script to make recordings using ffmpeg.
Running the following in a shell session will make a 1 minute recording:

  ffmpeg -i http://ip_of_ha_instance:8123/api/camera_proxy_stream/camera.my_camera?token=YOUR_CAM_TOKEN -t 1 -vcodec copy  /home/videos/recording.mp4

Possibly, you could integrate this with a python script in HA (I am not using the HA frontend and I use Appdaemon for automations). Regarding snapshots, this works fine for me using the built-in snapshot service so you might be doing something wrong when calling the service.

4 Likes

Thank you for your kind explanation. I will try this. Thank you.

Unfortunately, The token is changed from time to time. Therefore, I couldnot input the correct token in the script you mentioned above. How can i input the fixed token?

In addition, I also got this error message, when I input the script you mentioned above.

–> http://192.168.0.xx:8123/api/camera_proxy_stream/camera.my_camera?token=xxxxxxxxxxxxxxxxxxxxxxxxxx invalid data found when processing input

Can you please let us have your additional advice? Thank you in advance.

1 Like

Did you replace camera.my_camera with the actual name of your camera entity? I am travelling today but I can upload my full python script later that also handles the token that changes every 5 minutes.

sure. I put my own camera name and sorry to make you confused.

It seems that the changed Token is one of the rootcause for no working of the recording. As i checked the token and inputted the your command included with token ASAP before change or I also inputted all command I can do ASAP. But it showed some error message i mentioned above.

Therefore, I think that there is another reason that the recording is not working. But I will try anything i can.

Thank you for your kindness and sorry to disturb your trip. Please let me have your python script later, if available. I appreciate it.

@tjntomas i was wondering if you can post your python script on the forum im also wondering how you did this. :slight_smile:

Sure, I 'll take some time to post the script shortly.

You can get the current access token or most of the required url using templates… assuming the camera’s entity id is camera.esp32_camera

This works for other cameras too; not just esp32 cams :slight_smile:

access token only:

{{ state_attr('camera.esp32_camera','access_token') }}

most of the URL for a single image:

{{ state_attr('camera.esp32_camera','entity_picture') }}

Single image:

https://YOUR_DDNS_URL{{ state_attr('camera.esp32_camera','entity_picture') }}

Video stream:

https://YOUR_DDNS_URL/api/camera_proxy_stream/camera.esp32_camera?token={{ state_attr('camera.esp32_camera','access_token') }}
5 Likes

Thank you for your kind explanation. I can get the snap shot based on your information, But i am still eager to get the solution for recording as well. Thank you.

hello,

i have try your solution but i get an error :

': File exists
/config/shell_scripts/cuisine_camera_shell_script.sh: line 8: syntax error near unexpected token `('

my shell file is :

#!/bin/bash
date

folder=/config/www/cam_record
id=$(date +"%y-%m-%d_%H-%M-%S")cuisine_camera

mkdir $folder
ffmpeg -i https://192.168.1.50:8123/api/camera_proxy_stream/camera.cuisine?token={{ state_attr("camera.cuisine","access_token") }} -t 1 -vcodec copy $folder/$id.mp4
ls -lh $folder/$id.mp4 $folder/cuisine_camera.mp4
cp $folder/$id.mp4 $folder/cuisine_camera.mp4
ls -lh $folder/$id.mp4 $folder/cuisine_camera.mp4
find $folder -type f -name ‘*.mp4’ -mtime +30 -exec rm {} ;

i am a noob…is someone can help please?

Your script is trying to make a directory that already exists.

hello @nickrout,

thanks for your help, i have solved it 20 minutes ago : https://community.home-assistant.io/t/record-video-from-esp32-cam-config-with-esphome-in-hassio-works-great/153354/16

very happy to record a stream from an esp32cam lol

1 Like

I am getting this same error. The token and camera name is correct. But was there a solution to overcome this error?

–> http://192.168.0.xx:8123/api/camera_proxy_stream/camera.my_camera?token=xxxxxxxxxxxxxxxxxxxxxxxxxx 2 invalid data found when processing input
1 Like

Read the post above yours.

1 Like