0Incorporare un flusso RTSP live in una pagina Web

I have recently been work­ing on my smarthome setup and one of the things I’ve been mean­ing to get set up is a tab­let with a touch-screen web inter­face to man­age my smart home. One of the first prob­lems I had to crack was how to stream my cctv feed to a web browser…

Il problema

My CCTV cam­era, come molti, fornisce solo un flusso RTSP. No mod­ern web browsers sup­port RTSP.

La ricerca e i requisiti

Google just isn’t what it used to be and it took sev­er­al days of search­ing to find an accept­able solu­tion that met all of my require­ments…

  • I wanted some­thing that would work entirely off­line without any third party serv­ers involved.
  • I wanted some­thing that was com­pletely leg­ally free, idealmente open source
  • I wanted some­thing that would­n’t transcode the video or audio as this would waste pro­cessing resources

La soluzione

Ho trovato un really use­ful guide which explained a way to do this with a bit of JavaS­cript and ffm­peg, both of which were read­ily avail­able for free.

To run ffm­peg I used the fol­low­ing com­mand, which I ran on win­dows as a ser­vice, cre­ated with nssm…
ffmpeg -i rtsp://your_rtsp_ip:port/path/to/file.stream -c:v copy -c:a copy -bufsize 1835k -pix_fmt yuv420p -flags -global_header -hls_time 10 -hls_list_size 6 -hls_wrap 10 -start_number 1 /var/www/html/video.m3u8

To embed the video I down­loaded the fol­low­ing css file and 2 file js

  • https://vjs.zencdn.net/7.2.3/video-js.css
  • https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-hls/5.14.1/videojs-contrib-hls.js
  • https://vjs.zencdn.net/7.2.3/video.js

Ho quindi usato il codice della guida (with mod­i­fied paths to loc­al files) per incorporare il video che ha funzionato immediatamente. ffm­peg is using around 0.2% cpu usage and a few mb of memory on the serv­er that hosts the web­site.

Un'ultima nota, incase it mat­ters — I used the win64 stat­ic build of ffm­peg 4.2.2

Cosa ne pensi? Mandaci un commento qui sotto! Se si desidera iscriversi si prega di utilizzare il link iscriviti sul menu in alto a destra. È inoltre possibile condividere con i tuoi amici usando i link sottostanti sociali. Saluti.

lascia un commento