Context: I'm working for a TV station with many .TS (VOD) files that sometimes require a manual check. I would like the check to happen in a browser, hence using HLS or equivalent.
Goal: I have to create the requested HLS stream on the fly. So the M3U8 playlist is created when the request comes in (declaring as many segments as required for the whole file), then when the browser requests the actual segments, they are generated on the fly by ffmpeg and returned. Each segment must thus be generated qu!ickly and independently before being served, without processing the whole file (manual checks mostly consist of peeking a few seconds at the start, at the middle and at the end of the video).
Test: I created the following playlist:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:4
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:4.000000,
sample-0.ts
#EXTINF:4.000000,
sample-1.ts
#EXTINF:4,000000,
sample-2.ts
#EXTINF:4,000000,
sample-3.ts
#EXTINF:4,000000,
sample-4.ts
#EXT-X-ENDLIST
I then tried generating the segments with the following commands:
ffmpeg -i source.ts -c:v libx264 -b:v 1000k -c:a aac -b:a 128k -g 25 -ss 0 -t 4 -f mpegts cache\sample-0.ts
ffmpeg -i source.ts -c:v libx264 -b:v 1000k -c:a aac -b:a 128k -g 25 -ss 4 -t 4 -f mpegts cache\sample-1.ts
ffmpeg -i source.ts -c:v libx264 -b:v 1000k -c:a aac -b:a 128k -g 25 -ss 8 -t 4 -f mpegts cache\sample-2.ts
ffmpeg -i source.ts -c:v libx264 -b:v 1000k -c:a aac -b:a 128k -g 25 -ss 12 -t 4 -f mpegts cache\sample-3.ts
ffmpeg -i source.ts -c:v libx264 -b:v 1000k -c:a aac -b:a 128k -g 25 -ss 16 -t 4 -f mpegts cache\sample-4.ts
Issue : Although each segment plays fine in VLC, the resulting playlist does not play correctly and video stops after the first segment. I tried with VLC 3.0.18 but also with HLS.JS
Question: What is wrong in my ffmpeg commands (or M3U8 file) above ? How can I create segments of HLS independently ?
Any help or hint would be greatly appreciated
Vincent