[FFmpeg-user] Generating HLS chunks on demand

Vincent Deconinck vdeconinck at gmail.com
Fri Jan 27 14:38:16 EET 2023


Hi all,

I tried analyzing the differences between the ts files generated "all at
once" (using the hls muxer) and the ones generetad individually using -ss,
-t and the mpegts muxer.
I extracted the gop structure of the first ts segment using ffprobe then
reformated it in IBBP format, and here are the results
-f hls (works):
IBBBPPBBPBPBPPBPBPPBPBBPP
IPPBBBPBBPBBBPBBBPBPBBBPP
IBBBPBBBPBBBPBBBPBBBPBBBP
IBBPBPBBBPBBBPBBPBBPBBBPP
-ss -t -f mpegts (does not work):
IBBBPPBBPBPBPPBPBPPBPBBPP
IPPBBBPBBPBBBPBBBPBPBBBPP
IBBBPBBBPBBBPBBBPBBBPBBBP
IBBPBPBBBPBBBPBBPBBP
(and that's it !)

In other words, the structure looks ok but 5 frames seem to be missing from
the second segment ! No wonder it looks choppy...
And indeed, I had overlooked that a simple ffprobe on the non-working
segment shows a duration of 00:00:03.82 while the working one has a
duration of  00:00:04.02 (don't know where the 0.02 comes from).

So it seems it all boils down to frame accurate splicing indeed.
Any help in that regard would be greatly appreciated...

KR,

Vincent


On Thu, Jan 26, 2023 at 5:42 PM Vincent Deconinck <vdeconinck at gmail.com>
wrote:

> Hi,
>
> OK, I made some progress, so replying to self :
>
> So although I'm forcing keyframes, the durations are actually not 4
>> seconds (the EXT-X-TARGETDURATION field even says 5)
>> Is there another way to force all segments to be exactly the same
>> duration ?
>>
>
> After a bit of reading, the -g option only forces the *maximum* interval
> between keyframes, but the scene detection can trigger the creation of
> additional keyframes.
> E.g. with a -g 25 in a 25fps video, if there is a scene change at frame
> 12, the encoder will create a keyframe at 12, and then subsequent keyframes
> could be at e.g. 37, 62, etc. , so the last gop would end after the
> requested segment length.
>
> The --min-keyint 25 option didn't seem to change anything, so I finally
> resorted to using specific x264 options with the following command :
> ffmpeg -i source.ts -c:v libx264 -b:v 1000k -c:a aac -b:a 128k -x264opts
> "keyint=25:min-keyint=25:no-scenecut" -f hls -hls_time 4 -hls_playlist_type
> vod sample_fixed.m3u8
> and then the segments finally are exactly 4 seconds long (and the playback
> is OK).
> Good.
>
> Now I'm back to my initial problem : Dynamically generating a playable
> subset of segments.
>
> But cannot achieve a playable stream (tried -s mpegts, -s segment, -s hls,
> to no avail). For example, i ran the following commands :
> ffmpeg -ss 0 -i source.ts -c:v libx264 -b:v 1000k -c:a aac -b:a 128k
> -x264opts "keyint=25:min-keyint=25:no-scenecut" -t 4 -f segment
> -segment_list sample_segg.m3u8 -segment_time 4 sample0_%%d.ts
> ffmpeg -ss 4 -i source.ts -c:v libx264 -b:v 1000k -c:a aac -b:a 128k
> -x264opts "keyint=25:min-keyint=25:no-scenecut" -t 4 -f segment
> -segment_list sample_segg.m3u8 -segment_time 4 sample1_%%d.ts
> ffmpeg -ss 8 -i source.ts -c:v libx264 -b:v 1000k -c:a aac -b:a 128k
> -x264opts "keyint=25:min-keyint=25:no-scenecut" -t 4 -f segment
> -segment_list sample_segg.m3u8 -segment_time 4 sample2_%%d.ts
> ffmpeg -ss 12 -i source.ts -c:v libx264 -b:v 1000k -c:a aac -b:a 128k
> -x264opts "keyint=25:min-keyint=25:no-scenecut" -t 4 -f segment
> -segment_list sample_segg.m3u8 -segment_time 4 sample3_%%d.ts
> ffmpeg -ss 16 -i source.ts -c:v libx264 -b:v 1000k -c:a aac -b:a 128k
> -x264opts "keyint=25:min-keyint=25:no-scenecut" -t 4 -f segment
> -segment_list sample_segg.m3u8 -segment_time 4 sample4_%%d.ts
> then created by hand a playlist containing the generated segments, but the
> playback is choppy and stops after the first segment.
>
> Any idea how to create valid segments ?
> Is there another option than -ss and -t to splice the stream ?
>
> Kind regards,
>
> Vincent
>
>
>


More information about the ffmpeg-user mailing list