Script to get JPEG snapshot from RTSP-stream (ffmpeg)
Moderator: leecollings
-
- Posts: 30
- Joined: Sunday 31 May 2015 11:04
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: The Netherlands, Veenendaal
- Contact:
Re: [Bash] Script to get JPEG snapshot from RTSP-stream (ffm
I use the script on my Raspberry and it's working. The only thing is when I execute the script from the CLI the *.jpg will we stored under the "Pi" account.
If I do it from Domoticz, with a virtual switch, it will be stored under the user root.
How can I change this. (Sorry, new to linux)
Another question: how can I email this *.jpg to my email address within Domoticz
I had a IP cam which I could add to a switch and in Domoticz the jpg will be send automagicly. But now I use this script and I love to have the picture in my email box.
If I do it from Domoticz, with a virtual switch, it will be stored under the user root.
How can I change this. (Sorry, new to linux)
Another question: how can I email this *.jpg to my email address within Domoticz
I had a IP cam which I could add to a switch and in Domoticz the jpg will be send automagicly. But now I use this script and I love to have the picture in my email box.
-
- Posts: 890
- Joined: Tuesday 30 September 2014 8:49
- Target OS: Linux
- Domoticz version: beta
- Location: The Netherlands
- Contact:
Re: [Bash] Script to get JPEG snapshot from RTSP-stream (ffm
Like i said you can change the path where the image will be stored. Store at some place like /home/pi/doorbellcam.
And to get it delivered to your mail: you have to find out yourself. I drop the image on Dropbox and get a link to it, through a Pushover message. See the scripts i posted earlier in this topic.
But it can also be dumped onto a FTP-server, like 'mvveelen' has posted.
And to get it delivered to your mail: you have to find out yourself. I drop the image on Dropbox and get a link to it, through a Pushover message. See the scripts i posted earlier in this topic.
But it can also be dumped onto a FTP-server, like 'mvveelen' has posted.
I am not active on this forum anymore.
-
- Posts: 30
- Joined: Sunday 31 May 2015 11:04
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: The Netherlands, Veenendaal
- Contact:
Re: [Bash] Script to get JPEG snapshot from RTSP-stream (ffm
I have edited the script to send the snapshot. It seems to work, but only my e-mail server links the attachment as spam.
When I find the root cause I'll post it in this topic
Code: Select all
#!/bin/sh
IP="[IP address]" # IP address Camera
#Ping IP-address of camera to see if it's online, otherwise we don't have to grab a snapshot
if ping -c 1 $IP > /dev/null ; then
#Grab snapshot from RTSP-stream
/usr/bin/ffmpeg -rtsp_transport tcp -i 'rtsp://'$IP'/user=admin&password=&channel=1&stream=0.sdp' -f image2 -vframes 1 -pix_fmt yuvj420p /home/pi/doorbell/snapshot.jpeg
fi
sudo curl --url "smtp://[IP address of SMTP server]:25" --mail-from "[email protected]" --mail-rcpt "[email protected]" --upload-file "/home/pi/doorbell/snapshot.jpeg"
Last edited by marigo on Friday 11 September 2015 9:58, edited 2 times in total.
-
- Posts: 890
- Joined: Tuesday 30 September 2014 8:49
- Target OS: Linux
- Domoticz version: beta
- Location: The Netherlands
- Contact:
Re: [Bash] Script to get JPEG snapshot from RTSP-stream (ffm
Nice, please post your result here. You'll get it working, just spend some time on it
I am not active on this forum anymore.
-
- Posts: 30
- Joined: Sunday 31 May 2015 11:04
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: The Netherlands, Veenendaal
- Contact:
Re: [Bash] Script to get JPEG snapshot from RTSP-stream (ffm
The "curl" wasn't able to send the *.jpeg which have something to do with "Mime" settings.
I have installed "ssmtp" on the Pi to get the job done. I've used this setup:
https://rpi.tnet.com/project/faqs/smtp
I used my gmail credentials just like the setup in the url.
In the script I added the following line:
So the whole script is:
Thanks goes to Thinkpad for pushing me in the right direction.
I have installed "ssmtp" on the Pi to get the job done. I've used this setup:
https://rpi.tnet.com/project/faqs/smtp
I used my gmail credentials just like the setup in the url.
In the script I added the following line:
Code: Select all
mpack -s "Doorbell" /home/pi/doorbell/snapshot.jpeg [email protected] [email protected]
Code: Select all
#!/bin/sh
IP="[ip address]" # IP address Camera
#Ping IP-address of camera to see if it's online, otherwise we don't have to grab a snapshot
if ping -c 1 $IP > /dev/null ; then
#Grab snapshot from RTSP-stream
/usr/bin/ffmpeg -rtsp_transport tcp -i 'rtsp://'$IP'/user=admin&password=&channel=1&stream=0.sdp' -f image2 -vframes 1 -pix_fmt yuvj420p /home/pi/doorbell/snapshot.jpeg
fi
mpack -s "Doorbell" /home/pi/doorbell/snapshot.jpeg [email protected] [email protected]
-
- Posts: 890
- Joined: Tuesday 30 September 2014 8:49
- Target OS: Linux
- Domoticz version: beta
- Location: The Netherlands
- Contact:
Re: [Bash] Script to get JPEG snapshot from RTSP-stream (ffm
Always nice to see the variations that people have on different scripts. Good to hear you got it working.
Maybe this can also be useful: http://domoticz.com/forum/viewtopic.php ... 451#p50451 so you won't get spammed with a lot of mails when someone is pressing your doorbell very often.
Maybe this can also be useful: http://domoticz.com/forum/viewtopic.php ... 451#p50451 so you won't get spammed with a lot of mails when someone is pressing your doorbell very often.
I am not active on this forum anymore.
-
- Posts: 890
- Joined: Tuesday 30 September 2014 8:49
- Target OS: Linux
- Domoticz version: beta
- Location: The Netherlands
- Contact:
Re: [Bash] Script to get JPEG snapshot from RTSP-stream (ffm
I updated my NAS to DSM 5.2 yesterday (still had 5.1 running) and today i noticed i didn't get a snapshot.
When i ran the script by hand, i got the dreaded 'rtsp://192.168.4.20/user=admin&password=&channel=1&stream=1.sdp: Input/output error'. The 'MediaServer' package i was using (/volume1/@appstore/MediaServer/bin/ffmpeg) was also upgraded it seemed. It was back on v1.0 of ffmpeg it said.
I uninstalled it and installed the 'Audio Station' package, and now it works back again It says it is version 2.02 of ffmpeg.
volume1/@appstore/AudioStation/bin/ffmpeg
When i ran the script by hand, i got the dreaded 'rtsp://192.168.4.20/user=admin&password=&channel=1&stream=1.sdp: Input/output error'. The 'MediaServer' package i was using (/volume1/@appstore/MediaServer/bin/ffmpeg) was also upgraded it seemed. It was back on v1.0 of ffmpeg it said.
I uninstalled it and installed the 'Audio Station' package, and now it works back again It says it is version 2.02 of ffmpeg.
volume1/@appstore/AudioStation/bin/ffmpeg
I am not active on this forum anymore.
-
- Posts: 890
- Joined: Tuesday 30 September 2014 8:49
- Target OS: Linux
- Domoticz version: beta
- Location: The Netherlands
- Contact:
Re: [Bash] Script to get JPEG snapshot from RTSP-stream (ffm
Migrated Domoticz to a Ubuntu VM on ESXi, not running on my NAS anymore (which results in the HDD's of the NAS spinning down )
I changed the doorbell notification script, it now sends me a pushnotification (Pushover) with only text. The image is send through mail to my Gmail address (sent by myself).
I also changed from 'ffmpeg' to 'avconv' as it seems ffmpeg has become deprecated as of Ubuntu 14.04
To be able to send mail from the system through Gmail, i used this tutorial: http://www.renedohmen.nl/blog/2014/12/s ... on-ubuntu/
Backup of page if website ever goes down:
I changed the doorbell notification script, it now sends me a pushnotification (Pushover) with only text. The image is send through mail to my Gmail address (sent by myself).
Code: Select all
#!/bin/sh
today=`/bin/date '+%d-%m-%Y__%H-%M-%S'`; #Used to generate filename
datesubject=`/bin/date '+%d-%m-%Y om %T'`; #Used to generate timestamp in mailbody
IP="192.168.4.20" # IP address Camera
#Ping IP-address of camera to see if it's online, otherwise we don't have to grab a snapshot
if ping -c 1 $IP > /dev/null ; then
#Grab snapshot from RTSP-stream
/usr/bin/avconv -rtsp_transport tcp -i 'rtsp://'$IP'/user=admin&password=&channel=1&stream=0.sdp' -f image2 -vframes 1 -pix_fmt yuvj420p /home/domoticz/deurbelsnapshots/$today.jpeg
#Send pushnotification with URL to snapshot
sh /home/domoticz/domoticz/scripts/bash/deurbel/pushover.sh -u USERTOKEN -a APPLICATIONTOKEN -q "Deurbel galerij" -m "Er is aangebeld op de galerij. Zie bijlage in Gmail voor foto."
echo "Er is op" $datesubject "aangebeld, zie de bijlage voor de foto." | mail -s "Deurbelfoto" -r "YOUR NAME<[email protected]>" -aFrom:[email protected] -A /home/domoticz/deurbelsnapshots/$today.jpeg [email protected]
#Delete previous taken snapshots older than 7 days
find /home/domoticz/deurbelsnapshots/ -name '*.jpeg' -mtime +7 -delete
else
sh /home/domoticz/domoticz/scripts/bash/deurbel/pushover.sh -u USERTOKEN -a APPLICATIONTOKEN -q "Deurbel galerij" -m "Net aangebeld, plaatje niet beschikbaar omdat cam offline is"
fi
To be able to send mail from the system through Gmail, i used this tutorial: http://www.renedohmen.nl/blog/2014/12/s ... on-ubuntu/
Backup of page if website ever goes down:
- Spoiler: show
I am not active on this forum anymore.
-
- Posts: 10
- Joined: Monday 09 November 2015 19:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: [Bash] Script to get JPEG snapshot from RTSP-stream (ffm
Hi,
I have also a camera with only rtsp stream ( srcicam sp008) and i am newbie .
I use a Rpi 2 with domoticz
So i have some questions :
In which directory i have to save this script ?
How run it after each reboot ?
With this script is it possible to add camera in domoticz as a camera full compatible domoticz ? if yes what will be the parameter, Ip, port, url image,... to configure it?
Thanks in advance for your help
I have also a camera with only rtsp stream ( srcicam sp008) and i am newbie .
I use a Rpi 2 with domoticz
So i have some questions :
In which directory i have to save this script ?
How run it after each reboot ?
With this script is it possible to add camera in domoticz as a camera full compatible domoticz ? if yes what will be the parameter, Ip, port, url image,... to configure it?
Thanks in advance for your help
-
- Posts: 890
- Joined: Tuesday 30 September 2014 8:49
- Target OS: Linux
- Domoticz version: beta
- Location: The Netherlands
- Contact:
Re: [Bash] Script to get JPEG snapshot from RTSP-stream (ffm
Just put the script in a folder like /home/pi/ and call it doorbell.sh or so. You link the script to a switch that is activated when someone presses your doorbell.
The script will work outside Domoticz, you cannot get your cam working in Domoticz. If you want that: buy a different camera that is supported.
The script will work outside Domoticz, you cannot get your cam working in Domoticz. If you want that: buy a different camera that is supported.
I am not active on this forum anymore.
-
- Posts: 10
- Joined: Monday 09 November 2015 19:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: [Bash] Script to get JPEG snapshot from RTSP-stream (ffm
Thank for your quick and clear answer.
It is the bad news no compatibility to view it in domoticz.
It is the bad news no compatibility to view it in domoticz.
-
- Posts: 39
- Joined: Monday 19 January 2015 14:35
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: The Netherlands
- Contact:
Re: [Bash] Script to get JPEG snapshot from RTSP-stream (ffmpeg)
I bought an Escam QD300 Wifi and want to use it to send a snapshot when someone presses the doorbel. I noticed that on some pages in the webgui for this cam a current snapshot appeared. So I used Fiddler to see what happens when I go to that page.
I discovered that the webgui uses a special command to retrieve the snapshot:
http://1.2.3.4/web/cgi-bin/hi3510/param.cgi?cmd=snap
The output of this command is a string in this format:
var path="/tmpfs/snap_tmpfs/20160227/IMG001/IMG_chn0_TIMER_MNG_20160227114416_008.jpg"
If you create the following URL you can get the picture in maximum resolution:
http://1.2.3.4/tmpfs/snap_tmpfs/2016022 ... 16_008.jpg
I'm interested in the fact if the snapshot option is also available in other cams. Like I said, I used fiddler to discover this.
Also, this URL does not need any username and password So it's a security issue as well...
I created a quick and dirty python script that I can execute when the doorbell is pressed. Here is the script for others to use. Quick and very dirty.
I discovered that the webgui uses a special command to retrieve the snapshot:
http://1.2.3.4/web/cgi-bin/hi3510/param.cgi?cmd=snap
The output of this command is a string in this format:
var path="/tmpfs/snap_tmpfs/20160227/IMG001/IMG_chn0_TIMER_MNG_20160227114416_008.jpg"
If you create the following URL you can get the picture in maximum resolution:
http://1.2.3.4/tmpfs/snap_tmpfs/2016022 ... 16_008.jpg
I'm interested in the fact if the snapshot option is also available in other cams. Like I said, I used fiddler to discover this.
Also, this URL does not need any username and password So it's a security issue as well...
I created a quick and dirty python script that I can execute when the doorbell is pressed. Here is the script for others to use. Quick and very dirty.
Code: Select all
#!/usr/bin/python
import smtplib
import sys, json, urllib, urllib2
from cookielib import CookieJar
import base64
sender = '[email protected]'
receivers = ['[email protected]']
cj = CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
response = opener.open("http://1.2.3.4/web/cgi-bin/hi3510/param.cgi?cmd=snap")
content = response.read()
imgpath=content.split("=")[1]
imgPath = imgpath[1:-3]
imgUrl="http://1.2.3.4" + imgPath
#print imgUrl
imgData = urllib2.urlopen(imgUrl).read()
#output = open("/home/pi/test.jpg",'wb')
#output.write(imgData)
#output.close()
encodedcontent = base64.b64encode(imgData)
#Compose mail
marker = "AUNIQUEMARKER"
body ="""
Er is aangebeld.
"""
# Define the main headers.
part1 = """From: Cam <[email protected]>
To: User Name <[email protected]>
Subject: Sending Attachement
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=%s
--%s
""" % (marker, marker)
# Define the message action
part2 = """Content-Type: text/plain
Content-Transfer-Encoding:8bit
%s
--%s
""" % (body,marker)
# Define the attachment section
part3 = """Content-Type: multipart/mixed; name=\"%s\"
Content-Transfer-Encoding:base64
Content-Disposition: attachment; filename=%s
%s
--%s--
""" %("snapshot.jpg", "snapshot.jpg", encodedcontent, marker)
message = part1 + part2 + part3
try:
smtpObj = smtplib.SMTP('smtp.yourprovider.something')
smtpObj.sendmail(sender, reciever, message)
print "Successfully sent email"
except Exception:
print "Error: unable to send email"
Raspberry 3
Aeon Labs Z-Wave Stick Series 2 - RFLink USB Gateway
Z-Wave switches
433 MHz Temperature + Humidity sensors
Philips Hue Lights
Mi-Light WiFi Bridge + RGBW Controllers
Aeon Labs Z-Wave Stick Series 2 - RFLink USB Gateway
Z-Wave switches
433 MHz Temperature + Humidity sensors
Philips Hue Lights
Mi-Light WiFi Bridge + RGBW Controllers
-
- Posts: 135
- Joined: Monday 27 January 2014 14:12
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Netherlands
- Contact:
Re: [Bash] Script to get JPEG snapshot from RTSP (EScam QD50
Hi matthijs,matthijs wrote:It is working. I have almost the same code and copied your previous taken snapshots part. I also make a copy of the last snapshot and named it snapshot.jpg so I can use it to send a notification to Telegram (It is workaround I think, but I couldn't get it working otherwise). The only problem I have is my front door. We have a gallery with other houses so I can't put my camera there (for now).
Slightly offtopic but the Xiaomi had another problem. Newer firmware versions of the Xiaomi ants camera are lacking a rtsp stream, because it is protected with a username and password which Xiaomi doesn't reveal. so I had to downgrade the camera to get the stream working. I indeed used that website for the correct stream and it is working.
I have bought a Xiaomi Ants camera. Could you share your script how you got it setup up with this camera and Telegram?
Raspberry Pi Type B
Raspberry Pi Type B2
RFXCOMtrx433e
Raspberry Pi Type B2
RFXCOMtrx433e
-
- Posts: 17
- Joined: Friday 29 May 2015 12:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: The Netherlands
- Contact:
Re: [Bash] Script to get JPEG snapshot from RTSP (EScam QD50
Heisenberg wrote:
Hi matthijs,
I have bought a Xiaomi Ants camera. Could you share your script how you got it setup up with this camera and Telegram?
Code: Select all
#!/bin/sh
export DATETIME=`date +%Y%m%d%H%M%S`
ffmpeg -i rtsp://CAMERAIP/ch0_0.h264 -vframes 1 -r 1 -s 1920x1080 /home/pi/domoticz/www/snapshots/$DATETIME.jpg
cp /home/pi/domoticz/www/snapshots/$DATETIME.jpg /home/pi/domoticz/www/snapshots/snapshot.jpg
curl -s -X POST "https://api.telegram.org/BOTNAME/sendPhoto" -F chat_id=ID -F photo="@/home/pi/domoticz/www/snapshots/snapshot.jpg"
-
- Posts: 2
- Joined: Thursday 16 June 2016 15:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.4834
- Location: Germany
- Contact:
Re: [Bash] Script to get JPEG snapshot from RTSP-stream (ffmpeg)
Hi matthijs,
I use also a Xiaomi Ants camera with the hack software (https://github.com/fritz-smh/yi-hack)
I am able to generate a snapshot of the rtsp stream with ffmpeg on my raspberry but how did you configure the camera in domoticz? I am not able to see the snapshot...
Thanks in advance
elpacito
I use also a Xiaomi Ants camera with the hack software (https://github.com/fritz-smh/yi-hack)
I am able to generate a snapshot of the rtsp stream with ffmpeg on my raspberry but how did you configure the camera in domoticz? I am not able to see the snapshot...
Thanks in advance
elpacito
-
- Posts: 135
- Joined: Monday 27 January 2014 14:12
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Netherlands
- Contact:
Re: [Bash] Script to get JPEG snapshot from RTSP-stream (ffmpeg)
elpacito wrote:Hi matthijs,
I use also a Xiaomi Ants camera with the hack software (https://github.com/fritz-smh/yi-hack)
I am able to generate a snapshot of the rtsp stream with ffmpeg on my raspberry but how did you configure the camera in domoticz? I am not able to see the snapshot...
Thanks in advance
elpacito
You could try this script below with xiaomi hack software:
1. Make sure you have avconv installed and a Telegram Bot
2. save the script in your script folder as doorbell.sh
3. assign doorbell.sh to your doorbell button in Domoticz (e.g. script:///home/pi/domoticz/scripts/doorbell.sh)
4. push the doorbell button to receive snapshot
Code: Select all
#!/bin/sh
export DATETIME=`date +%Y%m%d%H%M%S`
avconv -i rtsp://root:[email protected]:554/ch0_0.h264 -vframes 1 -r 1 -s 1920x1080 /home/pi/domoticz/www/snapshots/$DATETIME.jpg
cp /home/pi/domoticz/www/snapshots/$DATETIME.jpg /home/pi/domoticz/www/snapshots/snapshot.jpg
curl -s -X POST "https://api.telegram.org/bot123456789:ABCDEFGHIJKLMNOPetc/sendPhoto" -F chat_id=12345678 -F photo="@/home/pi/domoticz/www/snapshots/snapshot.jpg"
#Delete previous taken snapshots older than 7 days
find /home/pi/domoticz/www/snapshots/ -name '*.jpg' -mtime +7 -delete
Last edited by Heisenberg on Wednesday 22 June 2016 11:04, edited 1 time in total.
Raspberry Pi Type B
Raspberry Pi Type B2
RFXCOMtrx433e
Raspberry Pi Type B2
RFXCOMtrx433e
-
- Posts: 2
- Joined: Thursday 16 June 2016 15:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.4834
- Location: Germany
- Contact:
Re: [Bash] Script to get JPEG snapshot from RTSP-stream (ffmpeg)
Thanks for your answer
The snapshot is working, I create a bot and it is working fine!!! Thanks a lot!
The snapshot is working, I create a bot and it is working fine!!! Thanks a lot!
-
- Posts: 2
- Joined: Sunday 08 January 2017 11:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.5877
- Location: France
- Contact:
Re: [Bash] Script to get JPEG snapshot from RTSP-stream (ffmpeg)
Hello,
i try that on a escam qd 500, it's work. the ONVIF port is 8899.
http://www.openipcam.com/forum/index.ph ... 37#msg5125
i find this snapshot uri:
http://xxx.xxx.xxx.xxx/webcapture.jpg?c ... &channel=1
hope it's help
i try that on a escam qd 500, it's work. the ONVIF port is 8899.
http://www.openipcam.com/forum/index.ph ... 37#msg5125
i find this snapshot uri:
http://xxx.xxx.xxx.xxx/webcapture.jpg?c ... &channel=1
hope it's help
-
- Posts: 70
- Joined: Monday 06 February 2017 12:48
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V4.9700
- Location: Azores
- Contact:
Re: [Bash] Script to get JPEG snapshot from RTSP-stream (ffmpeg)
How can i execute that code on the openipcam forum? :/
I have a Escam QD300 but your url doesnt work for mine.
I have a Escam QD300 but your url doesnt work for mine.
-
- Posts: 1
- Joined: Saturday 15 April 2017 2:42
- Target OS: -
- Domoticz version:
- Contact:
Re: [Bash] Script to get JPEG snapshot from RTSP-stream (ffmpeg)
Please excuse the bumping of an old thread but I'm hoping someone may be able to assist.
I've got a Sricam sp009a camera that I can get a good feed displaying on VLC (on a PC) using rtsp://[IPaddress]:554/onvif1 and also surprisingly works on rtsp://[IPaddress]/onvif1 (without the explicit 554 port). However, when I try to save an image on the Raspberry Pi using ffmpeg or avconv using the examples in the scripts here I'm constantly getting "invalid data found when processing input".
Any suggestions on troubleshooting?
I've got a Sricam sp009a camera that I can get a good feed displaying on VLC (on a PC) using rtsp://[IPaddress]:554/onvif1 and also surprisingly works on rtsp://[IPaddress]/onvif1 (without the explicit 554 port). However, when I try to save an image on the Raspberry Pi using ffmpeg or avconv using the examples in the scripts here I'm constantly getting "invalid data found when processing input".
Any suggestions on troubleshooting?
Who is online
Users browsing this forum: No registered users and 0 guests