Official website

Monday, February 18, 2013

DVR system by using an IP camera

Most IP Cameras on the market, even the cheap ones, has a built-in alarm system that notifies via e-mail, upload image to ftp or send an http request when motion is detected (additional example). But what if we want to capture video instead?

In this example we're going to use the http notification feature that camera provides, to send a command to Jubito server.

Login to camera's interface, go to Alarm tab, check the motion detection and send alarm notification by http check box. Then enter the HTTP URL in a RESTful style like this...

http://<host>:<port>/<instruction>
e.g. http://192.168.1.92:5744/ip-cam


Now we have to create the instruction set ip-cam but first we need to make sure that camera's IP address is declared in the trusted zone.

UPDATE: Check this post to see how to add trusted clients by the UI, without editing the AppConfig.xml.

However, I leave the paragraph below as is, in case you want to edit the file and see things behind the scenes
.
Edit the AppConfig.xml file, jump to the system settings and add the IP address of the camera or any other device you might want to access Jubito, delimited by semicolon. Also make sure you have setup a TCP socket that accept data to a specified port (5744 by default) by filling the localHost (Jubito server address) and localPort tags as well. Then save and close file.

<!-- SYSTEM SETTINGS -->
  <System>
    <Alerts>
      <MailHeaders>
        <MailFrom>noreply@xxx.net</MailFrom>
        <MailTo>xxx@gmail.com</MailTo>
        <MailSubject>Alert from Jubito</MailSubject>
      </MailHeaders>
    </Alerts>
    <Comm>
      <!-- Addresses that allowed to post notifications to socket specified -->
      <Trusted>192.168.1.10; 192.168.1.11</Trusted>
      <!-- Socket for accepting network messages via telnet, ip cameras etc -->
      <localHost>192.168.1.92</localHost>
      <localPort>5744</localPort>
      <!-- Web Server -->
      <Hostname>xxx.dyndns.org</Hostname>
      <httpPort>8080</httpPort>
      <!-- Microcontroller -->
      <ComPort>/dev/ttyACM0</ComPort>
      <BaudRate>9600</BaudRate>
    </Comm>
    <Others>
      <YahooForecastFeed>http://weather.yahooapis.com/forecastrss?p=GRXX0004&amp;u=c</YahooForecastFeed>
    </Others>
  </System>

Once you set it up you should enable the socket.


Let's assemble our ip-cam instruction set. Go to Control Panel/Instruction Sets/Add New Instruction Set. Under name enter the ip-cam. The Action part is a little bit tricky because the camera will always send notification when motion is detected but in our case we need to record a video only when we're out. Here comes the evaluation function that will check our status. The action will look like this...

{ evalBool("%whereami%" == "absent"); rec sendmemail; ; }

Read more on Evaluation

The above action evaluates over the %whereami% function and trigger rec and sendmemail instruction sets when condition is true.


What remains is the rec and sendmemail implementations. The rec will be a trigger of our recording software, in this case ffmpeg. Go back and Add New Launcher. Type rec as a name and set the action...

Using ffmpeg

./'ffmpeg' '-t 00:00:20 -i "http://<cam ip>:<port>/videostream.asf?user=admin&pwd=xxx" "/home/%user%/Videos/IP-Cam/cam-%calendarday%-%calendarmonth%-%calendaryear%_%hour%-%minute%.asf"'

Using vlc (there aren't ffmpeg packages for Raspberry Pi and Banana Pi and need to be compiled from source. Instead you can use vlc)

./'cvlc' 'http://<cam ip>:<port>/videostream.asf?user=admin&pwd=xxx --run-time=20 :demux=dump :demuxdump-file=/home/%user%/Videos/IP-Cam/cam-%calendarday%-%calendarmonth%-%calendaryear%_%hour%-%minute%.asf vlc://quit'


Dot-slash (./) that precedes, is required when we call a third party program.

Finally, we make the sendmemail launcher the same way. Add New Launcher, enter sendmemail as a name and judo mail send <from> <to> `<subject>` `<body>` as action which is the API for sending e-mails. APIs does not require the dot-slash (./) indicator. Learn more about at instruction set anatomy.


Example action
:
judo mail send xxx@gmail.com xxx@gmail.com `Security Breach` `Security Breach @ %date% - %time24%`


That's it, we have successfully created our DVR system!
For dropbox synchronization follow this post.

1 comment:

  1. Its very informative blog! Thanks for sharing it. These tips are really going to help me.

    ReplyDelete

Note: Only a member of this blog may post a comment.