Video Streaming
By Maui Systems Ltd
Positec UK contacted us about the possibility of live streaming from the CCTV cameras they use. One location in particular was of interest to them as a trial - located on a shop near the Craignure ferry terminal on the island of Mull off the West coast of Scotland. The camera afforded good views of the state of the queue for the ferry and also whether the ferry was actually there or not. Something rather useful for the locals of an island.
The result
This is the live stream from the camera at the Craignure ferry terminal on Mull, Scotland. You can normally tell it’s a live stream as at many points of the day people and cars are moving. It’s also the West coast of Scotland, so there’s a fairly high chance of rain, which reflects the IR light in the dark. (Note it’s not always wet in Scotland, but there a saying that if it’s dry now, it might be just a gap betwwen showers).
Many CCTV cameras use a proprietary protocol to talk to their recorder, but some support the ‘RTSP’ prototol which is more of an open standard. The issue with ‘RTSP’ is that the player (your web browser) needs to connect directly to the video stream, which causes problems with many networks. Instead, we looked for a camera with ‘RTMP’ support which means the camera sends a stream to a server which can deal with the traffic load and process the feed accordingly.
RTSP and why you should avoid it for external access
Many cameras support RTSP and if you are just doing this within your own local network then it does provide a nice quick and easy solution. Think of using it for external access to your camera and you need to be very aware of four significant issues.
-
The camera needs to be accessible from the internet so you need to add firewall rules to your router. This is sometimes impossible and at best usually something you need to be technically proficient to do. It’s easy to expose your network inadvertently and render your firewall useless.
-
Your camera is then accessible to the internet - so any flaws with the camera firmware can be utilised by others. This may let them gain access to your network, or be used by miscreants to do nasty things to other networks, leaving a finger of blame pointing back to your network router.
-
The camera needs to be able to deal with all the simultaneous connections you might get. Camera firmware is usually built to a cost - designed to send a stream or two of information to a network video recorder. It’s not designed for 4 or 5 connections, let alone the 1000’s you might get if the camera is popular.
-
For every connection you need bandwidth. Run this from your home network broadband and every person viewing the camera feed consumes some of your upload bandwidth. Many broadband connections are asymetrical - favouring download speeds over upload, so you will notice things slow down the more people connect to the camera.
There are commercial solutions based around RTSP; where the provider gets you to allow them to connect their server to your camera and get the feed. They then deal with the load from viewers at their end. This still means making changes to your firewall and exposes your network to the provider you have chosen.
RTMP Streams
RTMP works the other way around; the camera is configured to send it’s stream to a pre-defined location. As the traffic is from a known device on the inside of your network, even if you do need firewall rules, they are all very well defined and limit the traffic to outbound only - so don’t expose your network to the world at large; not even the streaming server has access. The problem, is that it can usually only send it to one location; it doesn’t scale. So much for your web stream having thousands of viewers.
Streaming Servers
‘RTMP’ is the choice for safely sending the stream out of your network but it doesn’t scale. To overcome this limitation, you stream your content to a server specifically designed to accept the stream and then make it available to all of your viewers. This means you don’t have the security implications from RTSP and your broadband connection is only having to upload one copy of the stream, even if there are millions watching.
The next hurdle is that it’s not quite as easy as taking the RTMP stream and ‘making it available on a website’. Most browsers can’t process RTMP video natively, so the streaming server needs some software that will allow it to accept the RTMP feed and process it into something that can be ingested by your browser.
Commercial Options
There are commercial services that offer packages to do this for you; big players like You Tube will let you send them content and give you a web page where you can send your viewers - but it’ll not be part of your website and not be branded.
Running Your Own Service
There is software freely available for Linux that will take an RTMP stream and process it in to an ‘HLS’ stream that can be consumed by normal browsers. The main problem is that you need somewhere to run this software that has the bandwidth and processing power to do the job. Yes you can run it inside your own network, but then you have the some of the same issues as RTSP; firewall rules and viewers soaking up your upload bandwidth.
If you are lucky enough to have server capacity in a datacentre, then that’s where to put this; alternatively, find someone who will sell/rent you space. Amazon AWS, Azure, Digital Ocean etc etc
Maui Systems Streaming Service
As we do have our own servers running in a well connected data centre, we set up our own solution based on the well loved Nginx server and the Nginx RTMP Module.
There are many tutorials on the web to help set this up; we used a Debian based virtual machine and had it up and running very quickly. The harder part turned out to be getting the camera settings right and then finding a good player that would work across devices.