我正在使用带有RTMP模块的NGINX来流式传输HLS格式的视频。我想让它存储正在以HLS格式流式传输的实时视频。我知道RTMP模块的hls_cleanup指令,但是关闭清理并不能防止.m3u8被反复覆盖。如何让NGINX将新的块添加到.m3u8文件中而不是覆盖它?如果这不是解决这个问题的正确方法,我还有其他选择吗?
发布于 2021-01-21 02:08:32
虽然答案可能有点晚,但我面临着同样的挑战,因此考虑回答。In short 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;
}https://stackoverflow.com/questions/64010808
复制相似问题