...
Se placer en tant que root (sudo -s)
Bloc de code |
---|
$> vim /etc/apt/sources.list |
...
Puis faire une mise à jour :
Bloc de code |
---|
$> apt update |
...
Ensuite, il faut installer le module nginx-rtmp :
Bloc de code |
---|
$> apt-get install libnginx-mod-rtmp |
...
Pour le multibitrate, il faut installer ffmpeg qui encode en temps réel le flux vidéo :
Bloc de code |
---|
$> aptitude install ffmpeg |
...
Bloc de code |
---|
language | text |
---|
title | Fichier /etc/nginx/snippets/rtmp.conf |
---|
|
rtmp {
server {
listen 1935; # port rtmp par defaut
chunk_size 4000; # taille des paquets transmis/découpé
application live { # nom de l'application (on peut mettre toto etc.
live on;
#meta copy;
#record off;
# publish only from localhost
allow publish 127.0.0.1; # seulement publier en local
allow publish all; #tout le monde peut publier
allow play all; # certaine adresse IP on le droit de lire
deny publish all; # mettre un deny à la fin pour securiser
exec ffmpeg -i rtmp://localhost/$app/$name
-c:v libx264 -preset ultrafast -b:v 512k -tune zerolatency -maxrate 512k -bufsize 1024k -vf "scale=480:-2,format=yuv420p" -g 60 -c:a aac -b:a 96k -ar 44100 -f flv rtmp://localhost/show/$name_low
-c:v libx264 -preset ultrafast -b:v 1.5M -tune zerolatency -maxrate 1.5M -bufsize 3M -vf "scale=1280:-2,format=yuv420p" -g 60 -c:a aac -b:a 128k -ar 44100 -f flv rtmp://localhost/show/$name_high
>/tmp/ffmpeg.log 2>&1 ;
exec_publish curl --request PATCH "https://pod.univ.fr/rest/broadcasters/$name/" --header "Content-Type: application/json" --header "Accept: application/json" --user CHANGE_USERNAME:CHANGE-THIS-STATUS-PASSWORD --data "{\"status\":true}";
exec_publish_done curl --request PATCH "https://pod.univ.fr/rest/broadcasters/$name/" --header "Content-Type: application/json" --header "Accept: application/json" --user CHANGE_USERNAME:CHANGE-THIS-STATUS-PASSWORD --data "{\"status\":false}";
}
# This application is for splitting the stream into HLS fragments
application show {
live on; # Allows live input from above
meta copy;
record off;
hls on; # activation du hls
hls_path /dev/shm/hls; #chemin des fragment ts mettre dans /dev/shm pour eviter de faire trop travailler le disque
hls_nested on; # cree un sous repertoire par stream envoye
hls_fragment 2s; #taille des fragments
hls_max_fragment 3s;
hls_playlist_length 10s;
# Instruct clients to adjust resolution according to bandwidth
hls_variant _low BANDWIDTH=512000; # Low/Mid bitrate, about sub-SD resolution
hls_variant _highthigh BANDWIDTH=1500000; # Source bitrate, source resolution
}
}
} |
...
Nous venons donc de créer un flux diffusé en direct accessible en HTML5, multibitrate et adaptatif, voici ce que contient le fichier nico.m3u8 :
Bloc de code |
---|
|
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=320000
nico_low/index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=640000
nico_high/index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1200000
nico_src/index.m3u8 |
...