summaryrefslogtreecommitdiff
path: root/pod/nginx/ngx_http_hls_module.pod
blob: 8f3195aad1d7f9415cc3c3a368aa734043dc395f (plain)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
=encoding utf-8

=head1 NAME

ngx_http_hls_module - Module ngx_http_hls_module




=head1



The C<ngx_http_hls_module> module provides HTTP Live Streaming
(HLS) server-side support for MP4 and MOV media files.
Such files typically have the F<.mp4>, F<.m4v>,
F<.m4a>, F<.mov>, or F<.qt> filename extensions.
The module supports H.264 video codec, AAC and MP3 audio codecs.





For each media file, two URIs are supported:

=over




=item *

A playlist URI with the “C<.m3u8>” filename extension.
The URI can accept optional arguments:

=over




=item *

“C<start>” and “C<end>”
define playlist boundaries in seconds (1.9.0).



=item *

“C<offset>” shifts an initial playback position
to the time offset in seconds (1.9.0).
A positive value sets a time offset from the beginning of the playlist.
A negative value sets a time offset
from the end of the last fragment in the playlist.



=item *

“C<len>” defines the fragment length in seconds.


=back






=item *

A fragment URI with the “C<.ts>” filename extension.
The URI can accept optional arguments:

=over




=item *

“C<start>” and “C<end>”
define fragment boundaries in seconds.



=back





=back








B<NOTE>

This module is available as part of our
commercial subscription.





=head1 Example Configuration




    
    location / {
        hls;
        hls_fragment            5s;
        hls_buffers             10 10m;
        hls_mp4_buffer_size     1m;
        hls_mp4_max_buffer_size 5m;
        root /var/video/;
    }


With this configuration, the following URIs are supported for
the “F<E<sol>varE<sol>videoE<sol>test.mp4>” file:

    
    http://hls.example.com/test.mp4.m3u8?offset=1.000&start=1.000&end=2.200
    http://hls.example.com/test.mp4.m3u8?len=8.000
    http://hls.example.com/test.mp4.ts?start=1.000&end=2.200






=head1 Directives

=head2 hls




B<context:> I<location>





Turns on HLS streaming in the surrounding location.







=head2 hls_buffers


B<syntax:> hls_buffers I<I<C<number>> I<C<size>>>


B<default:> I<8 2m>


B<context:> I<http>


B<context:> I<server>


B<context:> I<location>





Sets the maximum I<C<number>> and I<C<size>> of buffers
that are used for reading and writing data frames.







=head2 hls_forward_args


B<syntax:> hls_forward_args I<C<on> E<verbar> C<off>>


B<default:> I<off>


B<context:> I<http>


B<context:> I<server>


B<context:> I<location>



This directive appeared in version 1.5.12.





Adds arguments from a playlist request to URIs of fragments.
This may be useful for performing client authorization at the moment of
requesting a fragment, or when protecting an HLS stream with the
L<ngx_http_secure_link_module|ngx_http_secure_link_module>
module.





For example, if a client requests a playlist
C<http:E<sol>E<sol>example.comE<sol>hlsE<sol>test.mp4.m3u8?a=1E<amp>b=2>,
the arguments C<a=1> and C<b=2>
will be added to URIs of fragments after the arguments
C<start> and C<end>:

    
    #EXTM3U
    #EXT-X-VERSION:3
    #EXT-X-TARGETDURATION:15
    #EXT-X-PLAYLIST-TYPE:VOD
    
    #EXTINF:9.333,
    test.mp4.ts?start=0.000&end=9.333&a=1&b=2
    #EXTINF:7.167,
    test.mp4.ts?start=9.333&end=16.500&a=1&b=2
    #EXTINF:5.416,
    test.mp4.ts?start=16.500&end=21.916&a=1&b=2
    #EXTINF:5.500,
    test.mp4.ts?start=21.916&end=27.416&a=1&b=2
    #EXTINF:15.167,
    test.mp4.ts?start=27.416&end=42.583&a=1&b=2
    #EXTINF:9.626,
    test.mp4.ts?start=42.583&end=52.209&a=1&b=2
    
    #EXT-X-ENDLIST







If an HLS stream is protected with the
L<ngx_http_secure_link_module|ngx_http_secure_link_module>
module, C<$uri> should not be used in the
L<ngx_http_secure_link_module>
expression because this will cause errors when requesting the fragments.
L<Base URI|ngx_http_map_module> should be used
instead of C<$uri>
(C<$hls_uri> in the example):

    
    http {
        ...
    
        map $uri $hls_uri {
            ~^(?<base_uri>.*).m3u8$ $base_uri;
            ~^(?<base_uri>.*).ts$   $base_uri;
            default                 $uri;
        }
    
        server {
            ...
    
            location /hls/ {
                hls;
                hls_forward_args on;
    
                alias /var/videos/;
    
                secure_link $arg_md5,$arg_expires;
                secure_link_md5 "$secure_link_expires$hls_uri$remote_addr secret";
    
                if ($secure_link = "") {
                    return 403;
                }
    
                if ($secure_link = "0") {
                    return 410;
                }
            }
        }
    }









=head2 hls_fragment


B<syntax:> hls_fragment I<I<C<time>>>


B<default:> I<5s>


B<context:> I<http>


B<context:> I<server>


B<context:> I<location>





Defines the default fragment length for playlist URIs requested without the
“C<len>” argument.







=head2 hls_mp4_buffer_size


B<syntax:> hls_mp4_buffer_size I<I<C<size>>>


B<default:> I<512k>


B<context:> I<http>


B<context:> I<server>


B<context:> I<location>





Sets the initial I<C<size>> of the buffer used for
processing MP4 and MOV files.







=head2 hls_mp4_max_buffer_size


B<syntax:> hls_mp4_max_buffer_size I<I<C<size>>>


B<default:> I<10m>


B<context:> I<http>


B<context:> I<server>


B<context:> I<location>





During metadata processing, a larger buffer may become necessary.
Its size cannot exceed the specified I<C<size>>,
or else nginx will return the server error
C<500> (C<Internal Server Error>),
and log the following message:

    
    "/some/movie/file.mp4" mp4 moov atom is too large:
    12583268, you may want to increase hls_mp4_max_buffer_size