summaryrefslogtreecommitdiff
path: root/templates/default/kubernetes/nginx-streamer-cm.yml.j2
blob: 72cc461efec718634a3218b898cfa5edeb194f89 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
apiVersion: v1
kind: ConfigMap
metadata:
  namespace: {{ deploy.namespace }}
  name: nginx-streamer-{{ deploy.worker.name }}
  labels:
    app: nginx
    type: streamer
    worker: {{ deploy.worker.name }}
data:
  nginx.conf: |
    worker_processes 4;
    pid /srv/nginx.pid;
    error_log /dev/stderr notice;

    load_module modules/ngx_rtmp_module.so;

    events {
      worker_connections 768;
      # multi_accept on;
    }

    http {
      sendfile on;
      tcp_nopush on;
      tcp_nodelay on;
      keepalive_timeout 65;
      types_hash_max_size 2048;

      server_names_hash_bucket_size 64;

      include /etc/nginx/mime.types;
      default_type application/octet-stream;

      access_log /dev/null;

      server {
        listen {{ desc.streams[deploy.worker.flags.stream].port }} default_server;
        listen [::]:{{ desc.streams[deploy.worker.flags.stream].port }} default_server;
        server_name _;

        root /srv/www;

        location / {
          types {
            application/vnd.apple.mpegurl m3u8;
          }
          expires -1s;
          add_header Cache-Control "no-store,must-revalidate,max-age=0";
        }
      }
    }

    rtmp {
      access_log /dev/null;

      server {
        listen localhost:1935;

        application hls {
          live on;

          hls on;
          hls_path /srv/www/hls;
          hls_fragment 3;
          hls_playlist_length 12;
          hls_nested on;
          hls_cleanup on;
          hls_fragment_naming timestamp;
          hls_fragment_slicing aligned;
          hls_type live;
          hls_base_url http://{{ deploy.worker.flags['stream-hostname'] }}:{{ desc.streams[deploy.worker.flags.stream].port }}/hls/;

%% for mux in desc.streams[deploy.worker.flags.stream]['nginx-muxes']
%%   for profile in desc.muxes[mux].formats.flash
%%     set abitrate = desc.globals.profiles[profile].audio
%%     set vbitrate = desc.globals.bitrates[desc.globals.formats.flash.video][desc.globals.profiles[profile].video]
          hls_variant -{{ profile }} BANDWIDTH={{ (abitrate + vbitrate) * 1000 }};
%%   endfor
%% endfor
        }

        application dash {
          live on;

          dash on;
          dash_path /srv/www/dash;
          dash_fragment 3;
          dash_playlist_length 12;
          dash_nested on;
          dash_cleanup on;
        }

        respawn on;
%% for mux in desc.streams[deploy.worker.flags.stream]['nginx-muxes']
%%   for profile in desc.muxes[mux].formats.flash
        exec_static ffmpeg -i http://flumotion-worker-{{ deploy.worker.name }}:{{ desc.streams[deploy.worker.flags.stream].port }}/{{ mux }}-flash-{{ profile }}.flv
              -acodec copy -vcodec copy -vbsf h264_mp4toannexb -f flv rtmp://localhost/hls/{{ mux }}-{{ profile }}
              -acodec copy -vcodec copy -vbsf h264_mp4toannexb -f flv rtmp://localhost/dash/{{ mux }}-{{ profile }};
%%   endfor
%% endfor
      }
    }