我正在使用带有 RTMP 模块的 NGINX 以 HLS 格式流式传输视频。我想让它存储以 HLS 格式流式传输的实时视频。我知道hls_cleanup
RTMP 模块的指令,但是关闭清理并不能防止.m3u8
被一遍又一遍地覆盖。如何让 NGINX 将新块附加到.m3u8
文件而不是覆盖它?如果这不是解决此问题的正确方法,我还有哪些其他选择?
问问题
569 次
1 回答
0
虽然答案可能有点晚,但我面临同样的挑战,因此考虑回答。简而言之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;
}
于 2021-01-20T18:08:31.700 回答