📜 ⬆️ ⬇️

Video from a surveillance camera on the site for free and without SMS

There is a need to show video from the camera on the site online. There were several options (I will add options from comments, if there are any):


This option will be considered below. Since " flash died " or " flash is about to die, " the option of placing a flash player on the site was not considered. The thorny way of finding solutions on the Internet did not lead to a ready-made solution. I had to invent a bicycle.

More inventions under the cut.

Description of the bike received in more detail:



More about settings


On each stream from the camera, you need to run ffmpeg to convert rtsp to files that hls will understand.
')

ffmpeg and stream with sound


/usr/bin/ffmpeg \ -i rtsp://<     ONVIF Device Manager> \ -ar 44100 \ -acodec aac -ac 1 -strict -2 -crf 18 \ -c:v copy -preset ultrafast \ -flags -global_header \ -fflags flush_packets -tune zerolatency \ -hls_time 1 -hls_list_size 3 -hls_wrap 4 -hls_flags delete_segments -start_number 0 \ /tmp/www/index1.m3u8 
ffmpeg at start writes 25 fps with FullHD
 Guessed Channel Layout for Input Stream #0.1 : mono Input #0, rtsp, from 'rtsp://192.168.XX:554/user=admin_password=tlJwpbo6_channel=1_stream=0.sdp?': Metadata: title : RTSP Session Duration: N/A, start: 0.000000, bitrate: N/A Stream #0:0: Video: h264 (Baseline), yuv420p, 1920x1080, 25 fps, 9 tbr, 90k tbn, 50 tbc Stream #0:1: Audio: pcm_alaw, 8000 Hz, 1 channels, s16, 64 kb/s Output #0, hls, to '/tmp/www/index1.m3u8': Metadata: title : RTSP Session encoder : Lavf56.25.101 Stream #0:0: Video: h264, yuv420p, 1920x1080, q=2-31, 25 fps, 9 tbr, 90k tbn, 25 tbc Stream #0:1: Audio: aac, 44100 Hz, mono, fltp, 128 kb/s Metadata: encoder : Lavc56.26.100 aac Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (pcm_alaw (native) -> aac (native)) 
The video is simply copied, the audio had to be recoded otherwise silence.
Noname camera.

How does it work:


We take a stream, without transcoding we create files and a list for playback in the folder / tmp / www / .

nginx


We shorten the standard for the debian package file default to, for example, this:

/ etc / nginx / sites-enabled / default
 server { listen 80 default_server; listen [::]:80 default_server; access_log off; error_log /dev/null; root /tmp/www; index index.html; server_name _; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } } 

Sample video page:

/tmp/www/index.html
 <!DOCTYPE html> <html> <head> <title></title> </head> <body> <script src="https://cdn.jsdelivr.net/hls.js/latest/hls.min.js"></script> <video id="video"></video> <script> if(Hls.isSupported()) { var video = document.getElementById('video'); var hls = new Hls(); hls.loadSource('/index1.m3u8'); hls.attachMedia(video); hls.on(Hls.Events.MANIFEST_PARSED,function() { video.play(); }); } </script> 

The script should be placed locally, it has no external dependencies. Read more about hls settings .

How does it work:


hls connects to the page and plays files from the index1.m3u8 list. List and files are updated ffmpeg.

What happened:



References:


» Hls implementation
» Work demo hls
» Ffmpeg
» Nginx
» Updated and expanded text of the article on my blog

Source: https://habr.com/ru/post/401107/


All Articles