The easiest (for Linux knowledgeable) and cheapest way to place an IP camera on a site for a small audience

What is the main problem with modern low-cost IP cameras? You can't just add them to your site! They render videos in a completely different format than browsers understand. Yes, of course, you can go directly to the camera (and often only with IE), and many models have a "cloud". But the problem remains - I can't just take and place a camera on a site, like a simple picture!





I reviewed many solutions for organizing broadcasts from IP cameras from different vendors, including OpenSource solutions. Most have one drawback, which is very critical for me: the system constantly captures the stream from the camera, even if there are no spectators.





In my case, it was necessary to display a picture on the site from remote cameras connected via a 4G channel in a remote area. Upload speed did not rise above 10 Mbps at the best of times, but it was usually 2-3 Mbps. Although the traffic is unlimited, the provider unofficially warned that the consumption of more than 200 GB of traffic will certainly have a negative impact, such is the conditional "unlimited". I suppose they will simply "cut" the speed.





Some of the solutions found on GitHub were practically suitable, but did not have good documentation or seemed just complicated and cumbersome.





And I needed an online broadcasting system with the following properties:





  1. does not consume traffic in the absence of viewers;





  2. average daily simultaneous number of spectators - 1-3 people;





  3. support, if not all, then most of the popular Internet browsers, including mobile ones;





  4. as simple and straightforward as possible;





  5. inexpensive;





  6. preferably OpenSource.





Having rich experience with the FFMpeg program, I decided to try to implement all this functionality on my own. In the end, what is wrong with a "bicycle" made with your own hands, if you have the desire and time?





« , iVideon?» . , , , . , , ( ). , ( , ). , , . , «iVideon-» .





, , , Google Chrome Mozilla Firefox, H.264- . « » FFMpeg :





-movflags +frag_keyframe+separate_moof+omit_tfhd_offset+empty_moov







FFMpeg, MP4- moov moof .





:





«-c copy



» ;





«-an



» — (- , , );





«-t



» ( , );





«-rtsp_transport tcp



» — , RTP-, NAT ( );





«-probesize 32



» — ;





«-stimeout 5000000



» — - (5 ).





, PHP? . :





header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");







header("Cache-Control: post-check=0, pre-check=0", false);







header("Pragma: no-cache");







header('Accept-Ranges:bytes');







header('Connection:keep-alive');







header('Content-type: video/mp4');







PHP FFMpeg :





passthru("ffmpeg < > -f mp4 pipe:");







, , Safari Mac iOS. , MP4 , — . , «» Google Chrome, .





, — MJPEG , , MP4, — ? — , , , … , , . , .





, . , :





  1. : OGV WEBM;





  2. ();





  3. , , (, ), , ;





  4. - Mac. - — , . , «».  Safari — .





, , — . :





  1. , , Debian, Apache+PHP7 FFMpeg;





  2. SSL- ;





  3. www ;





  4. camera.php (; ) $key, $redirectToIfBackground , ;





  5. camera.php : camera.php?a=<rtsp- base64>&b=<>&c=<rtsp- base64>. «c» , .





, 5 . , base64 , http://base64.ru/, RTSP-.





, . MODX Revolution, , . CMS. $key $camera_server_url ( — , , ).





, :





{camera**RTSP-*RTSP- }







RTSP- . , . RTSP- , Onvif Device Manager. , « ».





. , , , . , «» camera.php, RTSP-, ( RTSP-), $key. , RTSP. «» . , . , … - «», .





By the way, personally, all my cameras are connected via VPN (I love Wireguard) into one network, all links I register with "gray IP". Convenient, safe, happy.





My code is published under the MIT license.





The project uses the ifvisible.js library developed by Serkan Yerşen, licensed by MIT.





Download, 14 kB





Mirror





Github








All Articles