0

I am using NGINX with RTMP module to stream video in HLS format. I want to make it store the live video being streamed in HLS format. I am aware of the hls_cleanup directive for RTMP module, however turning off the cleanup does not prevent the .m3u8 from being overwritten over and over. How do I make NGINX append new chunks to the .m3u8 file rather than overwrite it? If it isn't the right way to solve this problem what other options do I have?

monomonedula
  • 606
  • 4
  • 17

1 Answers1

1

Although the answer might be a little late, yet I faced the same challenge, therefore considered to answer. In short hls_playlist_length is the solution.

hls_playlist_lenght 100d; #d = days y = years

You may also want to turn off hls_continious.

hls_continious off; # plays video from the beginning I assume.

However, please note that a lengthy playlist time will quickly bloat the m3u8 file to a mammoth size. Hence, fearing that the live-stream might have an negative impact on both, the server and the client side, I took the following approach.

application live {
    live on;
    hls on;

    on_publish http://example.com/auth/onpublish;
    on_update http://example.com/auth/onupdate;
    on_done http://example.com/auth/ondone;

    # Use some encrypted channel name to avoid unwanted streaming
    # Make sure the push channels publish only from localhost
    # 
    push rtmp://<ip>/livechannel_8jzh%6ifu....DZBVzdbdg12; 
    push rtmp://<ip>/hls_raid_8jzh%6ifu....DZBVzdbdg12;
}

Live streaming settings (low latency)

application livechannel_8jzh%6ifu....DZBVzdbdg12 {

    # Only allow localhost to publish
    allow publish 127.0.0.1; #!important

    hls on; 
    hls_path /path/to/live/hls_storage;
    hls_cleanup on; 
    # set play from present segment or
    # right from beginning. Default off
    hls_continuous on;
    # push stream to stream key directory
    hls_nested on;

    # Low latency optimisation
    # hls_sync 2ms;
    hls_fragment 2s;
    hls_playlist_length 6s;
}

Save full hls for later purposes

application hls_raid_8jzh%6ifu....DZBVzdbdg12 {

    # Only allow localhost to publish
    allow publish 127.0.0.1; #!important

    live on;
    hls on;
    hls_nested on;
    hls_path /another/path/to/hls_raid;
    hls_cleanup off;
    hls_fragment 10s;
    hls_playlist_length 100d;# choose any large number
    hls_continuous off;

}
Odd
  • 563
  • 8
  • 20