Wednesday, August 28, 2013

HLS full urls in nginx-rtmp-module

In the latest master of nginx-rtmp-module I have added a new directive hls_base_url which makes it possible to have full urls in HLS playlists. With this feature enabled you can download playlist and play it locally since it references remote files. The feature is supported in master(variant) and slave playlists.


location /hls {
    root /tmp;
}
...
application mystream {
    live on;
    hls on;
    hls_path /tmp/hls;
    hls_base_url http://localhost:8080/hls/;
}

Here's the contents of HLS playlist for mystream stream

$ cat /tmp/hls/mystream.m3u8
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-TARGETDURATION:15
#EXT-X-DISCONTINUITY
#EXTINF:9.333,
http://localhost:8080/hls/mystream-0.ts
#EXTINF:7.167,
http://localhost:8080/hls/mystream-1.ts
#EXTINF:5.417,
http://localhost:8080/hls/mystream-2.ts
#EXTINF:5.500,
http://localhost:8080/hls/mystream-3.ts
#EXTINF:15.166,
http://localhost:8080/hls/mystream-4.ts
#EXTINF:9.584,
http://localhost:8080/hls/mystream-5.ts
#EXTINF:9.333,
http://localhost:8080/hls/mystream-6.ts

7 comments:

  1. Hi,
    Is there a way to check whether a stream is active (being pulished live) ?

    Thing is, I want make a ip camera mjpeg stream pull and publish as rtmp (using ffmepg) only when first viewer for stream comes in

    Thanks

    ReplyDelete
  2. is record_lock right way or the stats xml?

    ReplyDelete
  3. There's no way to start exec when first client comes in and kill it when the last one leaves. You can only pull RTMP stream with "pull" directive.

    ReplyDelete
  4. I am doing the pull using ffmpeg and not from rtmp module. I pushing this mjpeg as rtmp
    ffmpeg -i http://ip/cgi/x.mjpeg -flv rtmp://localhost/app/stream

    found a solution via a perl wrapper and using my own lock file for each unique stream.

    Thanks

    ReplyDelete
  5. Roman,
    Would it be possible to generate an "EVENT" type hls playlist? where EXT-X-MEDIA-SEQUENCE remains 0,
    and new segments are appended to playlist in hls_continuous mode?

    #EXT-X-PLAYLIST-TYPE:EVENT header is needed as well

    Thanks

    ReplyDelete
    Replies
    1. I think that's a good idea. I will implement it.

      Delete