Ceci est une ancienne révision du document !
Sources :
On commence par installer go :
apt-get install go
Puis par télécharger le code source :
git clone https://github.com/deepch/RTSPtoWeb
On se rend dans le répertoire et on teste le lancement :
cd RTSPtoWeb/
GO111MODULE=on go run *.go
On configure le serveur :
sudo nano config.json
Par exemple :
{ "server": { "debug": true, "log_level": "info", "http_debug": false, "http_demo": true, "http_dir": "web", "http_login": "$TONLOGIN", "http_password": "$TONPASS", "http_port": ":8083", "https": true, "https_auto_tls": false, "https_auto_tls_name": "", "https_cert": "/etc/letsencrypt/live/$TONDNS/cert.pem", "https_key": "/etc/letsencrypt/live/$TONDNS/privkey.pem", "https_port": ":8084", "ice_servers": ["stun:stun.l.google.com:19302"], "log_level": "debug", "rtsp_port": ":5541", "token": { "backend": "http://127.0.0.1/test.php" }, "defaults": { "audio": true } }, "streams": { "Couvoir": { "name": "Couvoir", "channels": { "0": { "url": "rtsp://$TONLOGIN:$TONPASS@$TONIP:554/Streaming/Channels/102", "debug": false, "on_demand": true, "audio": true, "status": 0 } } }, "Pondoir": { "name": "Pondoir", "channels": { "0": { "name": "ch1", "url": "rtsp://$TONIP:554/11", "debug": false, "on_demand": true, "audio": true, "status": 0 } } } }, "channel_defaults": { "on_demand": true } }
On teste si tout fonctionne :
GO111MODULE=on go run *.go
Et lancer un navigateur et se rendre sur
https://$TONDNS:8084
Si tout fonctionne, on peut lancer le build de l'application :
sudo GO111MODULE=on go build -o /$TONPATH/RTSPtoWeb/RTSPtoWeb.bin
Puis créer le service RTSP :
sudo nano /etc/systemd/system/rtsp.service
[Unit] Description=Service RTSPtoWebRTC [Service] Type=simple Restart=always ExecStart= /$TONPATH/RTSPtoWeb/RTSPtoWeb.bin WorkingDirectory=/$TONPATH/RTSPtoWeb [Install] WantedBy=multi-user.target
On recharge les services, on lance le service RTSP et on vérifie son status :
sudo systemctl daemon-reload sudo systemctl start rtsp.service sudo systemctl status rtsp.service
Une fois que c'est testé via le navigateur, on l'ajoute au lancement lors du boot :
sudo systemctl enable rtsp.service
Exemple :
https://$TONDNS:8084
<!-- CSS --> <link href="https://vjs.zencdn.net/7.2.3/video-js.css" rel="stylesheet"> <!-- HTML --> <video id='hls-example' class="video-js vjs-default-skin" width="800" height="600" controls> <!-- <source type="application/x-mpegURL" src="https://pisto.fr.nf:8084/stream/Couvoir/channel/0/hls/live/index.m3u8"> --> <source type="application/x-mpegURL" src="https://pisto.fr.nf:8084/stream/Pondoir/channel/0/hls/live/index.m3u8"> </video> <!-- JS code --> <!-- If you'd like to support IE8 (for Video.js versions prior to v7) --> <script src="https://vjs.zencdn.net/ie8/ie8-version/videojs-ie8.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-hls/5.14.1/videojs-contrib-hls.js"></script> <script src="https://vjs.zencdn.net/7.2.3/video.js"></script> <script> var player = videojs('hls-example'); player.play(); </script>
Source : https://stackoverflow.com/questions/19782389/playing-m3u8-files-with-html-video-tag https://videojs.com/getting-started/#videojs-cdn https://github.com/videojs/http-streaming?tab=readme-ov-file#initialization https://unpkg.com/browse/@videojs/http-streaming@3.15.0/dist/videojs-http-streaming.min.js https://github.com/videojs/http-streaming?tab=readme-ov-file#installation
nano /$TONPATH/RTSPtoWeb/config.json
Ajouter dans les streams :
,"NomDeLaCam": { "name": "NomDeLaCam", "channels": { "0": { "name": "ch1", "url": "rtsp://IPDELACAM:554/11", "debug": false, "on_demand": true, "audio": true, "status": 0 } } }
Redémarrer le service rtsp :
sudo systemctl restart rtsp.service
Vérifier son statut :
sudo systemctl status rtsp.service
Si tout est OK, la nouvelle cam est disponible par le gestionnaire de RTSPtoWeb.
Pour l'ajouter dans une page Web, il faut utiliser videojs ( https://github.com/videojs/http-streaming?tab=readme-ov-file#initialization ).
GNU nano 7.2 /var/www/html/cam_poul/index.php <!doctype html> <html lang="fr"> <head> <meta charset="utf-8"> <title>Cam Poulailler</title> <link href="../css.css" rel="stylesheet"> <link href="css/video-js.css" rel="stylesheet" /> <!-- "core" version of Video.js --> <script src="js/video.min.js"></script> <script src="js/videojs-http-streaming.min.js"></script> </head> <body> <?php $TONDNS = "dokuwiki.fr.nf"; $cameras = [ 'Trappe', 'Pondoir', 'Couvoir', 'Cour', 'Cypres' ]; foreach ($cameras as $valeur) { ?><video-js id=<?php echo ("'".$valeur."'");?> width='540' height='360' class="vjs-default-skin" controls autoplay muted style="margin-bottom:10px;"> <source src=<?php echo ("'https://".$TONDNS.":8084/stream/".$valeur."/channel/0/hls/live/index.m3u8'");?> type="application/x-mpegURL"> </video-js> <script> var player = videojs(<?php echo ("'".$valeur."'");?>); player.play(); </script> <?php } ?> </body>