nginx.conf.template 4.72 KB
Newer Older
root's avatar
subdirs  
root committed
1 2 3 4 5 6 7 8 9 10 11 12 13
daemon off;

error_log /dev/stdout info;

events {
    worker_connections 1024;
}

rtmp {
    server {
        listen 1935;
        chunk_size 4000;

dreamer's avatar
dreamer committed
14 15 16
        # deny access from router303
        deny 10.205.12.2;

dreamer's avatar
dreamer committed
17
        application streaminput {
dreamer's avatar
dreamer committed
18 19
            # allow access from router303
            allow 10.205.12.2;
dreamer's avatar
dreamer committed
20 21 22
            live on;
        }

root's avatar
subdirs  
root committed
23 24 25
        application stream {
            live on;

dreamer's avatar
dreamer committed
26
            #relays the incoming video to low quality streams on this server, audio-only version and to a different server
root's avatar
subdirs  
root committed
27
            exec ffmpeg -i rtmp://localhost:1935/stream/$name
dreamer's avatar
dreamer committed
28 29
                -c:a copy     -c:v copy                                                      -f flv rtmp://localhost/hls/$name_hi;
            exec ffmpeg -i rtmp://localhost:1935/stream/$name -max_muxing_queue_size 1024
dreamer's avatar
dreamer committed
30
                -c:a copy     -c:v libx264 -b:v 500K  -preset superfast -profile:v baseline  -f flv rtmp://localhost/hls/$name_low
dreamer's avatar
dreamer committed
31
                2>/mnt/radio/logs/ffmpeg-$name_low.log;
dreamer's avatar
dreamer committed
32

dreamer's avatar
dreamer committed
33
            exec ffmpeg -i rtmp://localhost:1935/stream/$name
dreamer's avatar
dreamer committed
34
                -c:a copy     -vn                                                            -f flv rtmp://localhost/hls/$name_audio;
dreamer's avatar
dreamer committed
35

dreamer's avatar
dreamer committed
36
            exec ffmpeg -i rtmp://localhost:1935/stream/$name
dreamer's avatar
dreamer committed
37
                -c:v copy     -c:a copy                                                      -f flv "rtmp://IFM_SERVER/show/$name";
dreamer's avatar
dreamer committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

            recorder video {
                record all;
                record_path /mnt/radio/recordings/rtmprec/streams;
                record_suffix _video.flv;

                record_unique on;
            }
            recorder audio {
                record audio;
                record_path /mnt/radio/recordings/rtmprec/streams;
                record_suffix _audio.flv;
                record_unique on;
                exec_record_done ffmpeg -i $path -metadata title="$basename" year="2020" -c:a libmp3lame /mnt/radio/recordings/rtmprec/streams/$basename.mp3;

            }
root's avatar
subdirs  
root committed
54 55 56

        }

dreamer's avatar
dreamer committed
57 58 59 60 61 62 63 64 65 66 67
        # to send video to be recorded on server (not played live)
        application input {
            live on;
        #records audio + video
            recorder video {
                record all;
                record_path /mnt/radio/recordings/rtmprec/inputrec;
                record_suffix _video.flv;

                record_unique on;
            }
root's avatar
subdirs  
root committed
68
        #records audio
dreamer's avatar
dreamer committed
69 70 71 72 73 74 75 76 77 78
            recorder audio {
                record audio;
                record_path /mnt/radio/recordings/rtmprec/inputrec;
                record_suffix _audio.flv;
                record_unique on;
            # convert to mp3
                exec_record_done ffmpeg -i $path -metadata title="$basename" year="2020" -c:a libmp3lame /mnt/radio/recordings/rtmprec/inputrec/$basename.mp3;

            }
        }
root's avatar
subdirs  
root committed
79 80 81 82 83

        application hls {
            live on;
            hls on;
            hls_fragment_naming system;
84 85
            hls_fragment 3;
            hls_playlist_length 60;
root's avatar
subdirs  
root committed
86 87 88
            hls_path /opt/data/hls;
            hls_nested on;

dreamer's avatar
dreamer committed
89
            hls_variant _hi      BANDWIDTH=640000;
dreamer's avatar
dreamer committed
90
            hls_variant _low     BANDWIDTH=160000;
dreamer's avatar
dreamer committed
91
            hls_variant _audio   BANDWIDTH=500;
root's avatar
subdirs  
root committed
92 93 94 95 96 97 98 99 100 101
        }
    }
}




http {
    access_log /dev/stdout combined;

dreamer's avatar
style  
dreamer committed
102
    map $request_uri $cache_expires {
dreamer's avatar
style  
dreamer committed
103 104 105
        default 59;
        ~*(.+\.ts)$  3600;
        ~*(.+\.m3u8)$  10;
dreamer's avatar
style  
dreamer committed
106
    }
root's avatar
root committed
107 108 109 110 111 112 113

    map $request_uri $cache_control {
        default "public , s-maxage=59, max-age=59";
        ~*(.+\.ts)$  "immutable , s-maxage=3600, max-age=3600";
        ~*(.+\.m3u8)$  "public, s-maxage=10, max-age=10";
    }

root's avatar
subdirs  
root committed
114 115
    server {
        listen      80;
dreamer's avatar
dreamer committed
116 117 118 119 120 121
        location /hls {
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root /opt/data;
dreamer's avatar
style  
dreamer committed
122

dreamer's avatar
dreamer committed
123
            add_header Cache-Control $cache_control;
root's avatar
root committed
124 125 126 127
            add_header Expires $cache_expires;
            add_header X-Cache-Control $cache_control;
            add_header X-Expires $cache_expires;

dreamer's avatar
dreamer committed
128 129 130
            add_header Access-Control-Allow-Origin *;
        }

root's avatar
subdirs  
root committed
131
        location /live {
dreamer's avatar
style  
dreamer committed
132 133 134 135 136 137 138 139 140 141 142
            alias /opt/data/hls;
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            add_header Cache-Control $cache_control;
            add_header Expires $cache_expires;
            add_header X-Cache-Control $cache_control;
            add_header X-Expires $cache_expires;

            add_header Access-Control-Allow-Origin *;
root's avatar
subdirs  
root committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
        }

        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet static/stat.xsl;
        }

        location /static {
            alias /www/static;
        }

        location = /crossdomain.xml {
            root /www/static;
            default_type text/xml;
            expires 24h;
        }
    }
}