Saturday 18 January 2020

Convert cheap security camera into nature camera

Live-streaming commercial IP cameras can be expensive.  I don't like expensive.

...there are cheap ones, but they're often hard-wired into the 'cloud', and stop you viewing the camera without an internet connection, often requiring more ££/$$ out of you to actually use the camera's full potential.  I'm also not a fan of streaming content 24/7 to an online faceless cloud only to have to download it back again to view it...  </end of rant>

Ryan Fitton's blog describes how a cheap IP security camera, the 'Neos SmartCam' can be simply modified to enable access its local video stream (called an rtsp stream).  We can then do some cool stuff with it to replicate and extend the limited cloud motion detection functionality.  The camera is available from Amazon here.
* 2021 update - it appears that the version available now has had a firmware update such that flashing it with the custom software may not be possible - you may still be able to pick up the original version off ebay *  Its a shame as my modified one has been happily livestreaming from a birdbox for the best part of a year now without issue




The good bits
  • Its a £25 wide angle wifi IP camera.  
  • You can view the livestream locally and remotely (remote needs internet at both sites)
  • It has night and day modes - night mode uses IR leds which are ok over a short distance.  
  • It does motion capture in the cloud
  • There's a smartphone/tablet app that lets you manually record clips live of ?unlimited length.

This is an example of a motion-captured clip on an unmodified camera (note its not waterproof!).

The bad bits
  • Motion capture relies on an active internet connection.
  • Motion capture videos are poorer resolution than manually captured ones.
  • Constant use of your internet connection.
  • Without more ££/$$ you only get 10 second clips that are limited to 10 min triggering interval.
  • The number of clips it saves is limited to maybe the last ?10.   
  • Neos expect a lot of personal info on initial configuration - I don't like that at all.
  • The local video stream, is NOT available.  I tried really hard!
  • 'Full' functionality is only available at extra subscription cost
Neos SmartCam.  They know where you live if you let them.

No Thanks.
So lets's fix it!!

Ryan's blog describes a method to make the video stream accessible locally in the form of an RTSP video stream.  To do this, you replace the camera's on-board software (the 'firmware').  This also removes the the motion capture functionality as this is done on Neos' cloud servers.  The method involves modifying the 'bootloader' to accept alternative firmware when turned on. To do this you need a blank micro SD card and some means to transfer custom firmware called 'DaFang hacks' to the unit.
DaFang hacks is custom firmware which you can flash to the camera via a MicroSD card. This give you benefits such as; no relying on the manufacturer’s cloud services, SSH and FTP services on the camera itself, and the best: RTSP stream support – this will allow you to integrate the camera into any DVR recording software, such as Shinobi, ZoneMinder or Synology’s Surveillance Station
My experience of modifying my Neos SmartCam was pretty simple.  The one difference to Ryan's account is that the 'ready' LED flash pattern on mine was different, showing a solid yellow LED signal. I also used an 8Gb micro SD card instead of a 16Gb one.  I also noticed that every time I used it on the stock firmware, the app kept telling me that it needed a firmware update.  DON'T DO THAT... I suspect that if you do it will remove the possibility of modifying the bootloader so that you can load custom firmware.  I cant prove that as I didn't try it, but its not worth the risk!

So now I have access to a local rtsp video feed from a cheap camera with day & night modes  plus all the camera configuration options 😊.

I modified the settings in the configuration browser as follows to get an acceptable framerate:
Video size: 960x540
Bitrate: 500
Framerate: 25 fps

Some things that you can with do an rtsp video stream:

  1. Motion capture via open-source CCTV application MotionEye on a Raspberry Pi (I do this)
  2. Motion capture using commercial DVR recording stations (I don't do this)
  3. Motion capture using commercial CCTV applications on a PC e.g. iCatcher (I did this).
  4. Local viewing of your camera's video on a PC using VLC 

Local motion capture example using MotionEye
Motion capture done locally that does not rely on streaming to the cloud.  I currently use MotionEye launched from a Docker image on on a Raspberry Pi to motion capture video from this camera.  Its really simple to setup, I will likely do a future post more detail.


Review video stream in a web browser OR livestream to YouTube for free
I've previously done a post about an excellent application called Restreamer. This takes an rtsp stream and outputs it as something that can be easily incorporated into a web browser.  It also allows you to stream directly to YouTube and other streaming providers with minimal effort, see my previous post for more details on this specifically. 

At the moment I'm using Restreamer to generate a video stream from this modified neos camera that I can load it into into my 'Wildlife Camera dashboard', which is one way to get all my cameras onto one screen via a web browser.  This is also possible using MotionEye, however this app can handle either the rtsp feed or the 'web-friendly' one from Restreamer.

Have fun with timelapse 
Once you can access the local video stream this sort of thing becomes a possibility.. coming to a future blog post  😎



Conclusion
Without updating the firmware its pretty much useless for my needs.  The updated firmware opens up all sort of potential, I'm considering where to use it, in an inside situation, maybe a owl box?

Wednesday 1 January 2020

Restreamer: Live stream an IP camera the easy way

I recently added a wifi IP camera to add to my collection of home-brew wildlife monitoring kit, kindly supplied by Birdsy: https://www.birdsy.com/ .  The Birdsy camera livestreams to the 'cloud' where artificial intelligence (AI) software is used to classify the bird species.  Video clips are saved to your own secure section of the Birdsy website.

BUT I wanted to do more with the video without having to rely on an internet connection via the web site or smartphone app... so I needed access to the local video stream.  I came across a great application called 'Restreamer', which converts the rtsp stream that the camera produces into an internet browser-friendly video stream.    Restreamer is available in a simple to setup Docker image for the Raspberry Pi (or on Windows/Mac etc).  I recently wrote a how-to for Docker setup on the Raspberry Pi here.  In this case I would recommend using a version of the Pi with more oomph, eg the v3 or v4.

Restreamer user interface

Using Restreamer with the IP camera rtsp stream, I have been able to easily...

(1) Incorporate a website-friendly camera feed into my birdbox camera/weather 'dashboard' 
[  *Hint* - it's the top left camera feed  ]...


My 'Wildlife dashboard' incorporates Birdsy video stream via Restreamer, not the rtsp stream sent to the Birdsy servers and pulled back again via the Birdsy website (i'm not sure that's even possible) .

See this post that describes by Grafana wildlife dashboards in more detail.  By including the live, local camera video feed , I'm not reliant on pulling a live feed back off their website.  This does not interfere with normal operation of the Birdsy camera (or any other IP camera at that).  All the bird species AI goodness that Birdsy offers still requires the website login/app.    My dashboard is only available on my local network.

How does this work?... Restreamer converts the local rtsp video stream into a format that the Grafana dashboard can present in an html 'i-frame'. The output from Restreamer is for this Grafana panel is:

<iframe src="http://XXX.XXX.X.XX:9090/player.html" name="restreamer-player" width="704" height="500" scrolling="no" frameborder="0" webkitallowfullscreen="true" mozallowfullscreen="true" allowfullscreen="true"></iframe>

'http://XXX.XXX.X.XX' represents the IP address of the Raspberry pi running Restreamer.  Port 9090 is configured in the docker Restreamer container used to make the birdsy IP camera feed available.  You can spin up as many Restreamer Docker containers as you want, just assign a different port for each camera - instructions on the Restreamer website.

(2) Push the livestream elsewhere... e.g. Stream live to YouTube
A few years ago I live streamed a Robin nest to YouTube using using a program called ffmpeg.  It was a fiddle to setup and involved a long and convoluted command line to run it. If you want to watch four  hours of robin chicks check out this archived link: https://youtu.be/lMOGX1dMaO8


Anyway Restreamer makes to really simple to push the local rtsp stream direct to YouTube, Twitch, Facebook, Vimeo etc (I know what at least two of these are....).  The screenshot below is my Birdsy Camera feed pushed direct to YouTube, however any rtsp camera where you can access the local feed should work equally well.


(3) Push the camera feed into alternative, locally run motion capture software
[ Video clip motion-captured locally using free CCTV  application 'Zoneminder' .  Technically this used the rtsp feed direct from  the camera, and not via Restreamer]

This gif was generated from a Zoneminder-motion captured clip.  I don't recommend Zoneminder as it's user interface is clunky and I found retrieving captured video to be non-intuitive and fiddly. I only used it as there is a Docker container available for the raspberry pi.  Other motion capture software is available, i will do a future post on economical local motion capture options (i.e. not reliant on the cloud and an 'always on' internet connection).

Look a chap in the eye...

Restreamer brief overview
See https://datarhei.github.io/restreamer/

Restreamer takes a variety of video stream sources and converts it into a web browser-friendly format.  For my IP camera it was as simple as entering the IP camera's rtsp stream and pressing Start.

Stream locally and also to external services (Youtube etc) 
It can also take video from IP cameras, USB cameras, Raspbery PI cameras

For an IP camera, the format is:  rtsp://username:password@Camera'sIPaddress:port/streamLocation
The username and password can be found in your camera's literature (be sure to change it...)
I located the IP address and rtsp stream location of my Networked IP camera using a windows program called IPCManager, this gives access to loads of behind the scenes camera configuration options.

The instructions for adding a Restreamer container to Docker can be found here:
https://datarhei.github.io/restreamer/docs/installation-linux-arm.html
I'm running it on the fastest Raspberry Pi currently available (Pi 4) with 4Gb ram - as I dont want this to be a bottleneck.  There are Docker images available to run in Windows or Linux Docker installations too.

Next job is to look at options for local motion capture, probably starting with Docker applications on my trusty Raspberry Pi