Snapshot of Camera - empty JPG file

I have tried following a few guides with regards to taking a snapshot of my cameras, but I have been unsucessful thus far.

In my configuration.yaml I have:

camera:
- platform: ffmpeg
  input: rtsp://192.168.0.104/user=admin_password=******_channel=1_stream=0.sdp
  name: BackDoorCamera

- platform: ffmpeg
  input: rtsp://192.168.0.102/user=admin_password=******_channel=1_stream=0.sdp
  name: FrontDoorCamera

I can use the above RTSP URL in VLC and I am able to view a live camera feed.

In my automations.yaml I have:

- id: '1542837260543'
  alias: Camera
  trigger:
  - entity_id: binary_sensor.0x00158d000238c7ca
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      entity_id: camera.BackDoorCamera
      filename: /config/www/snapshot.jpg
    service: camera.snapshot

The above scripts creates a ā€œsnapshot.jpgā€ in the directory, but it is a 0kb empty file.

Any ideas as to what I am doing wrong please?

I also have motionEye installed and I am able to view the cameras through this add on.

You might be better off using a script and calling the download component. This is my example for a Foscam camera.

driveway_motion:
  alias: Driveway Motion
  sequence:
    - service: downloader.download_file
      data_template:
        url: "http://YOUR-IP-ADDRESS:PORT/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=USERNAME&pwd=PASSWORD"
        filename: "front_door.jpg"
        overwrite: true

Thanks for your reply. Excuse my ignorance being somewhat new to Hass.io.

Your above script, is that from your automations.yaml file?

Not a worry, script.yaml file, then you call the script in your automation. In my example, you would call script.driveway_motion

I tried your script this morning, but unfortunately I got an error:

Invalid service data for downloader.download_file: invalid url for dictionary value @ data['url'].

I think I understand why it is returning this error. Your URL begins with ā€œhttp://ā€ whereas mine begins with ā€œrtsp://ā€. I donā€™t think downloader can cope with rtsp. :frowning:

Full script from scripts.yaml.

  alias: BackDoorCamera
  sequence:
    - service: downloader.download_file
      data_template:
        url: "rtsp://192.168.0.104/user=admin_password=*****_channel=1_stream=0.sdp"
        filename: "front_door.jpg"
        overwrite: true

have you find the solution for this? i m having same issues.
I m using onvif platform for my camera. when i call the camera.snapshot, i m getting zero size jpg file. No idea what i m doing wrong. i can view the camera through live stream though

Hi there,

I ended up going down the video route and I used the following shell script:

#!/bin/bash
date

folder=/config/temp/garden_camera
id=$(date +ā€œ%y-%m-%d_%H-%M-%Sā€)garden_camera
rtsp_url=ā€œrtsp://192.168.0.104/user=admin_password=tlJwpbo6_channel=1_stream=0.sdpā€
frames=300
fps=5

mkdir $folder
ffmpeg -rtsp_transport tcp -i $rtsp_url -r $fps -frames:v $frames -vcodec copy $folder/$id.mp4
ls -lh $folder/$id.mp4 $folder/garden_camera.mp4
cp $folder/$id.mp4 $folder/garden_camera.mp4
ls -lh $folder/$id.mp4 $folder/garden_camera.mp4
find $folder -type f -name ā€˜*.mp4ā€™ -mtime +30 -exec rm {} ;

The error messages in the log file proved vital for helping me trouble shoot and of course a bit of trial and error.

Any one worked this out yet. Getting empty jpg file.

No! i have the same issue.

Has anyone come up with a solution to this issue yet? Iā€™m in a similar boat, however using the generic camera. All jpg created are empty and 4 bytes.

I believe this is a bug in the snapshot function of the camera component; I am seeing the same behavior when attempting to snapshot a camera into a file and also use that file as an input to another camera. FWIW

- id: motion_end_snapshot_fireplace
  alias: motion_end_snapshot_fireplace
  initial_state: on
  trigger:
    platform: state
    entity_id: binary_sensor.motion_end_fireplace
  condition:
    condition: template
    value_template: >-
      {{ is_state('binary_sensor.motion_end_fireplace','on') }}
  action:
    - service: camera.snapshot
      data_template:
        filename: >-
          {{ '/config/www/images/motion_end-fireplace.jpg' }}
        entity_id: >-
          {{ 'camera.motion_end_fireplace' }}

Similarly, I have a camera defined to use the contents of that file:

I am using snapshots, for both notifications and to feed another camera with the still images without issue. What is your config? You cannot view the images it saves? Or is it just an issue when using the secondary ā€œcameraā€ ?

Hi,

Iā€™m having same issue with zero byte snapshot. Iā€™m using Wyze cam2 and can stream on Lovelace front end. Would you be able to share your configuration ?

I just got something similar working for my setup with Node-Red, if anyone is interested (sorry, I know Node-Red wasnā€™t listed here, but when trying to get mine to work, I came across this thread and figured it might help someone else).

Mine is set up to communicate to a Wyze Cam [with Dafang-Hacks firmware] camera thatā€™s connected to MotionEye, so itā€™s not quite the same, but hopefully the solution is universal. At the very least, maybe itā€™s a starting point for someone elses project.

I tried to break this out to be as basic as possible but have everything needed (without my real triggers and other stuff on what happens after the pic is saved). The change node isnā€™t strictly needed, but I have a pretty big flow for mine and the change nodes made it really easy to re-use everything past it (useful if youā€™re doing the same thing for multiple cameras).

Hereā€™s the code for it:

[{"id":"2fab1eb1.284322","type":"http request","z":"4ed8d085.a0498","name":"GetPic","method":"GET","ret":"bin","paytoqs":false,"url":"","tls":"","persist":true,"proxy":"","authType":"","x":610,"y":280,"wires":[["ffb676bb.ab5d4"]]},{"id":"ffb676bb.ab5d4","type":"file","z":"4ed8d085.a0498","name":"SavePic","filename":"","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"none","x":780,"y":280,"wires":[[]]},{"id":"799dfda8.8afa34","type":"inject","z":"4ed8d085.a0498","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":280,"wires":[["18aaa26a.270976"]]},{"id":"18aaa26a.270976","type":"change","z":"4ed8d085.a0498","name":"Outside Patio","rules":[{"t":"set","p":"url","pt":"msg","to":"http://10.1.10.143/picture/2/current/","tot":"str"},{"t":"set","p":"filename","pt":"msg","to":"/share/OutsidePatio01.jpg","tot":"str"},{"t":"set","p":"temppayload","pt":"msg","to":"{ \"photo\":\"/share/OutsidePatio01.jpg\" }","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":280,"wires":[["2fab1eb1.284322"]]}]

Hereā€™s the visual representation:

1 Like

Also experiencing this issue with Nest cams. However, it seems to be sporadic. Sometimes it saves as zero kb, and sometimes it works. Might be time for an official bug report

1 Like

Same issue with sonoff camera.

And nobody knows how it can be fixed?

Thank you very much for your code! Iā€™ve been trying to accomplish the same thing as your code, but couldnā€™t get it work.

Very much appreciated!

Hey hey! Thatā€™s awesome! Glad I could be of help :slight_smile:

I was having this issue with a TAPO camera and came across this discussion. The sollution I found was to disable ā€œpreload streamā€ in HA, which keeps the feed open.

It appears some cameras only allow access to 1 external steam at a time and if HA is preloading 1, it means there isnā€™t a stream for camera.snapshot to use.

1 Like