How to set up a broadcast to the site from any CCTV camera

In early 2016, the service for the organization of broadcasts "Line" has undergone an unexpected test of strength. And all thanks to the events in the safari park, where the tiger and the goat lived in the same aviary. On December 31, 2015, the start of the live broadcast, which was organized with the help of our service, was announced on national television. Almost immediately after that, both the park site and our servers could not bear the load.



Within a couple of hours, the broadcast was restored, and the required capacity was added for more than 2,500,000 connections to IP cameras. Over the next week, servers in the Netherlands and the USA were added to the service, and a broadcast protection function was developed. In general, we did everything to ensure that our service could withstand any amount of people who want to watch the popular broadcast. In this particular example, the audience amounted to more than 10 million people.







Since then, the popularity of this service is only growing. Not only is it an excellent marketing tool that can be used absolutely in any business, it also brings nice bonuses in the form of improving the website's behavioral characteristics and increasing the credibility of the company, product or service.



In addition to Amur and Timur, there are many interesting examples in our practice. This is a network of flower shops, and a hospital in the clinic for pets, and sports events. In general, for business it is just a storehouse of ideas that we have reviewed in detail and with examples in this article .



From idea to implementation. How to organize everything as profitably as possible



Out-of-the-box camera streams are not intended to be broadcast on the site, therefore it is better to use video surveillance software. For those who have previously installed such a system, the extra costs will be at a minimum or not at all.



The rest can use the free demo version of the program for video surveillance "Line" for Linux . For broadcasting you only need a camera, from which we will take the stream and video server on Linux.



Moreover, the physical server is not an obligatory element. You can install the "Line" on the VPS. Choose a suitable virtual server will help a lot of reviews on Geektimes and Habrahabr, and in other sources.



Setting up the broadcast is possible using the client "Line" for Windows. Even in the demo version of the software, we laid a lot of useful chips, including the possibility of notifying when the signal from the camera was lost.



Placing broadcast on the site



After installing and testing all system components, you can post a broadcast on your site. You can create your own player design using the features of html5 video + css.



The Line Video System API allows you to get both the current frame and the H.264 stream (hls, flv).



But the perfect solution for all platforms does not exist. So, Internet Explorer can only play flv, Chrome recently actively blocks flash, hls.js does not work in iOS.



You can solve this by writing a handler in JavaScript or PHP, or use our ready-made solution - a.devline.ru/html5 .







Safety first



Consider a situation in which your idea of ​​a broadcast "shot", and now thousands of people from all over the world come to your site every hour. Some of them are not at all with good intentions, so you need to protect yourself from the hotlink, hide the authorization data and the IP address of the server, set up caching, and so on.



Here nginx comes to the rescue, we register a couple of lines in the config, and the server will give access only by the following link:



http://demo.devline.ru:3333/O0deKdmC0j2xLqRqM490Mw/1504967831/streaming/0/sub.m3u8 location / { rewrite /([a-zA-Z0-9_\-]*)/([0-9]*)/([a-zA-Z0-9_\-]*)/([0-9]*)/(.*)\.(.*)$ /$3/$4/$5.$6?secl=$1&sect=$2&secq=$4&secm=$3; secure_link $arg_secl,$arg_sect; secure_link_md5 devline$arg_secq$arg_sect$remote_addr; if ($secure_link = "") { return 403; } if ($secure_link = "0") { return 404; } if ($arg_secm = "image") {rewrite /([a-zA-Z0-9_\-]*)/([0-9]*)/(.*)\.(.*)$ /cameras/$2/$1 break;} rewrite /([a-zA-Z0-9_\-]*)/([0-9]*)/(.*)\.(.*)$ /cameras/$2/$1/$3.$4 break; proxy_pass http://127.0.0.1:9786; proxy_set_header Authorization "Basic YWRtaW46"; }     PHP: $camid = "0"; $secret = 'devline'; $time_expires = time() + 90800; //life 24 hours $key = str_replace("=", "", strtr(base64_encode(md5($secret.$camid.$time_expires.getenv("REMOTE_ADDR"), TRUE)), "+/", "-_")); echo "/$key/$time_expires/streaming/$camid/sub.m3u8"; ?>
      
      





We did everything for you



All of the above, you can not do it yourself, but simply use our ready-made solution - rtsp.me. For the service to work, it is not necessary to be a user of the Line software; it is enough to have an IP camera or DVR that supports RTSP streams. Equipment must be with a static IP address and forwarded ports.







You get a secure broadcast with sound support, the ability to switch between the first and second stream. Visitors to the site will not see the real login and password from your video server; the repeater will duplicate the video if there are more than one viewers.



And the presence of a small logo at the bottom of the player allows you to provide services for free. The logo can be removed by selecting one of the paid rates .



Also, service users can use Timelapse function - video from a series of frames from your video surveillance camera. Ten days with a loop recording, each frame is taken every ten minutes. The file is created once every 24 hours, the output video bitrate is 2 Mb / s. There is a paid version with an unlimited archive depth in the paid period, as well as with individual settings for the frame creation frequency, recording creation time, video bitrate.



What type of broadcasting organization would you choose? Maybe you already have a broadcast on the site? What is it and how much does it cost you?



All Articles