如何使NGINX RTMP模块存储流式HLS



我正在使用带有RTMP模块的NGINX以HLS格式流式传输视频。我想让它存储HLS格式的直播视频。我知道RTMP模块的hls_cleanup指令,但是关闭清理并不能防止.m3u8被一次又一次地覆盖。如何使NGINX将新块附加到.m3u8文件而不是覆盖它?如果这不是解决这个问题的正确方法,我还有什么其他选择?

虽然答案可能有点晚,但我面临着同样的挑战,因此考虑回答简而言之,hls_playlist_length就是解决方案

hls_playlist_lenght 100d; #d = days y = years

您可能还需要关闭hls_continious

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

但是,请注意,播放列表时间过长会使m3u8文件迅速膨胀到巨大的大小。因此,由于担心直播可能会对服务器端和客户端产生负面影响,我采取了以下方法。

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;
}

直播设置(低延迟(

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;
}

保存完整的hls以备日后使用

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;
}

相关内容

  • 没有找到相关文章