Search code examples
nginxhttp-live-streaming

Nginx Plus not streaming HLS


I have installed Nginx Plus and configured HLS for streaming. While requesting the m3u8 file I'm getting the error:

2015/09/29 13:32:34 [error] 5814#5814: *1 open() "/usr/video/hls/CODECS="avc1.42e00a,mp4a.40.2"" failed (2: No such file or directory)

The m3u8 file has the following contents:

#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=545600,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2"
/usr/video/hls/myvideo_low.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1755600,RESOLUTION=640x360,CODECS="avc1.42e00a,mp4a.40.2"
/usr/video/hls/myvideo_high.m3u8

The Nginx configuration is:

location /hls {
      root   /usr/video;
      hls;
      hls_fragment            5s;
      hls_buffers             10 10m;
      hls_mp4_buffer_size     1m;
      hls_mp4_max_buffer_size 5m;
      types {
           application/vnd.apple.mpegurl m3u8;
           video/mp2t ts;
      }
      add_header 'Access-Control-Allow-Origin' '*';
      add_header 'Cache-Control' 'no-cache';
}

In the browser I am getting a warning: "No TS Fragments found".


Solution

  • In order to dynamically create the ts segments from a static file like an mp4 the filename and extension must be present in the m3u8 playlist filename:

    myvideo_high.mp4.m3u8 for myvideo_high.mp4

    For:

    myvideo_high.m3u8

    it assumes the segments already exist.


    The Serving Media with NGINX Plus whitepaper shows an example for a manually created m3u8 variant playlist which is incorrect due to page formatting (line wrapping):

    #EXTM3U
    #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=545600,RESOLUTION=416x234,
    CODECS="avc1.42e00a,mp4a.40.2"
    /hls/myvideo_low.mp4.m3u8
    #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1755600,RESOLUTION=640x360,
    CODECS="avc1.42e00a,mp4a.40.2"
    /hls/myvideo_high.mp4.m3u8
    

    THe #EXT-X-STREAM-INF information should be on a single line (no new-line characters):

     #EXTM3U
     #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=545600,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2"
     /hls/myvideo_low.mp4.m3u8
     #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1755600,RESOLUTION=640x360,CODECS="avc1.42e00a,mp4a.40.2"
     /hls/myvideo_high.mp4.m3u8