HLS files being deleted prematurely
Hi,
I'm seeing an issue with the HLS files generation. With some versions of OBS, what I was not able to determine why, the chunk files are being deleted prematurely and sometimes even the m3u8 files are deleted for a few seconds that sometimes are enough for the player to receive 404 errors.
For working around this I added the following line in configuration file:
hls_cleanup off;
And, in order to still keep the destination directory clean, I also added the following cron job:
* * * * * /bin/find /path-to-hls_dir/* -mmin +1 -delete
I'm not sure if this is related, but when it happens the hls_fragment parameter is also not being respected. For instance, consider the following configuration:
hls_fragment 2s;
hls_playlist_length 6s;
With this parameters the m3u8 file always has 3 chunks (6 / 2 = 3), what seems to be good, but the chunks duration are 8 seconds. Take a look at this example:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:5
#EXT-X-TARGETDURATION:8
#EXTINF:8.334,
5.ts
#EXTINF:8.333,
6.ts
#EXTINF:8.333,
7.ts
I hope it helps.
Thanks,
Renato A. Ferreira
+1
Figured out a workaround with OBS Studio on Mac. You'll need to set your keyframe interval manually (ex. 1s) in the output settings; the default is 0 (auto). That solved the issue for me.
I met the same problem today. Pleeease tell me your solution, I'm nearly desperate now.
In case someone may encounter the same problem... I find out the reason causes the problem today----------the particular source video missing audio part which may result in HLS slicing problem. When the audio part been added then the bug was fixed. Simple and easy.
Hi, I encounter the problem today.
yypnathan: could you explain more about your solution.
Hi, guys... Sorry, but I'm not activelly working on this project anymore. What I can say is that the "hls_cleanup off" parameter and the cron job was good enough to fix the 404 errors on live strraming.
Hi, thanks for kind reply,
I have a question, am I mis-understanding the cron-job?
/bin/find /path-to-hls_dir/* -mmin +1 -delete
Is it suppose to clean ALL the files in the folder at specific interval (here is 1m?)?
Hi van7hu: Lack of audio part of the live stream caused my problem. After the audio part been added to live stream then problem solved. I'm not sure if it is effective in your case.
Hi yypnathan:
- What is 'audio part'?, could you explain it more clearly? I'm using OBS.
- I've reviewed my problem. The .ts file is generated, I tried also with
hls_cleanup off;, and the problem persists.
For more clearly, my problem is as follow:
- I made and endpoint to live RTMP
- Convert RTMP to HLS with FFMPEG Result:
- The RTMP could not be watched, it just display nothing.
- I view on Server, the .ts file generated, and also the index.m3u8, I could watch for some .ts file with VLC player, and then the stream ends, although, the last .ts I watched is some
indexless than on server.
van7hu: We were working on live stream server last year. Which means our procedure is as follows: camera & speaker ---> live stream ---> push to rtmp server ---> convert to hls --->client. Our problem was that the live stream didn't have audio track ----- not muted, NO AUDIO TRACK at all! Hence rtmp server seems has problem in converting this kind of video. Hope I've conveyed my idea clearly.
I meet the same problem today and solve this when I change the source input keyframe. See https://stackoverflow.com/questions/38216051/hls-fragment-length-and-playlist-length-with-nginx-rtmp-module/44063680#44063680
Also: https://github.com/arut/nginx-rtmp-module/issues/775#issuecomment-195900365
In obs studio, see https://support.mediamotiononline.com/portal/kb/articles/how-to-change-the-keyframe-interval-in-obs-studio
It looks like this plugin keeps files newer than 2 * the playlist length by default, but that might not be enough depending on keyframe settings and the overall latency.
I worked around the problem by patching the code to keep files newer than 5 * the playlist length: https://github.com/chenxiaolong/rtmp2hls/blob/db93ec26b45bfc53685dc27ce0f255c14591211d/0001-ngx_rtmp_hls_cleanup_dir-Only-delete-files-older-tha.patch
Hello friends I'm not very familiar with the Nginx and I installed it on a Windows server Could you help me to define cron job? Where should I define that?
thank you
Two options to avoid premature deletion of segments:
- Reduce keyframe interval at the source. 2 sec is good for live streaming scenario (set hls_fragment=2 in such case).
- Increase the playlist length (hls_playlist_length)
If your source is OBS, then the default keyframe interval (0) is 10 secs. Set hls_playlist_length=10 (or higher) to avoid playback issues.