'Live streaming from FFMPEG: output a window m3u8 and also an all-segments m3u8
I've been experimenting with using FFMPEG to take an incoming RTMP stream, transcode into a selection of bitrates, and output it as HLS. It works.
I wanted to store the live stream as a VOD. And found by adding the -hls_list_size 0 flag, sure enough, all segment are in the .m3u8. Making it super easy to turn into a VOD afterwards. So far, so good.
But the obvious consequence of using -hls_list_size 0 is that now the m3u8 is huge during the live stream. That's fine for a VOD where it is only requested once, but less good during a live stream where it is requested over and over.
So ... my question: without re-transcoding, can FFMPEG output both an all-segments all.m3u8 (to keep internally for making a VOD afterwards, ie using -hls_list_size 0) and also output a sliding-window style latest.m3u8 (of only the last X segments, ie using -hls_list_size 3)?
That way, viewers of the live stream could be served that little latest.m3u8, as a tiny file, with only the last few segments in. And after the event ends, I'd ditch that little latest.m3u8 and only keep the all.m3u8 to make a VOD version of the stream?
Thanks!
Solution 1:[1]
Here is my two cents. As @Gyan suggested in comments above I made use of tee command. This takes input single time and performance of my system remains almost same if I would do only Live. Only drawback is it creates duplicate copy of that many segments which are being used in HLS segments for live.
ffmpeg -y \ -hide_banner \ -i $input_url \ -preset veryfast -g 48 -sc_threshold 0 \ -map 0:1 -map 0:2 -map 0:1 -map 0:2 -map 0:1 -map 0:2 \ -filter:v:1 "scale=-2:360" -c:v:1 libx264 -b:v:1 365k \ -filter:v:2 "scale=-2:480" -c:v:2 libx264 -b:v:2 1600k \ -c:v:4 copy \ -f hls -hls_time 10 -hls_list_size 10 \ -var_stream_map "v:0,a:0 v:1,a:1 v:2,a:2" \ -hls_segment_filename "$stream_key-v%v/%d.ts" \ -f hls -f tee \ "[var_stream_map=\'v:0,a:0 v:1,a:1 v:2,a:2 \': \ master_pl_name=\'master-live.m3u8\': \ hls_flags=delete_segments: \ hls_list_size=60]$master-live%v/live.m3u8| \ [var_stream_map=\'v:0,a:0 v:1,a:1 v:2,a:2\': \ master_pl_name=\'master-record.m3u8\': \ hls_playlist_type=vod]$master-record%v/record.m3u8"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | skygeek |
