[FFmpeg-user] Fixed GOP encoding for HLS

Stefano Sabatini stefasab at gmail.com
Wed Dec 5 01:00:08 CET 2012


On date Wednesday 2012-12-05 10:15:46 +1100, Andrew Sinclair wrote:
> Hi,
> 
> I am trying to encode and segment for Apple HLS devices and am look for any
> tips from anyone that has mastered this.
> 
> I am trying to get the segments in the .m3u8 files to be exactly aligned
> for so that each segment is precisely 6 seconds long and I have experience
> with encoders that do this quite well as I suspect that not being aligned
> is causing issues on an Android device I am working on.
> 
> To get this aligned I am encoding with frame rate 24 and a min/max GOP of
> 12 (based on notes in the ffmpeg docs on the -segment command) however I
> still see variation in the segment size.
> 

> Can anyone tell me what the optimal settings for this are? Does anyone know
> how the segments end up not aligned if I am forcing requesting keyframes
> every 12 frames and this shows up in ffprobe?

> 
> Example encode:
> ffmpeg -i 131375031.mp4 -vcodec libx264 -b:v 500k -r 24 -g 12 -keyint_min
> 12 -coder 0 -profile:b baseline out_gop12.ts

Can you confirm that the resulting ts has the timestamp at the exact
location? Or in other words, are you sure that -g 12 -keyint_min 12
produces a fixed GOP of 12 frames (ffprobe -show_packets or
-show_frames should confirm this).

> Example segment:
> ffmpeg -i out_gop12.ts -codec copy -map 0  -f segment -segment_list
> playlist_gop12.m3u8 -segment_time 6 out_gop12_seg6-%03d.ts
> 
> Resulting index file extract (note the segment lengths vary a lot!):

The trick I used was using -force_key_frames in ffmpeg and then use a
reasonable value for -segment_time_delta (half the value of the
framerate should be safe), check the segment examples.

We could eventually extend -force_key_frames to accept an expression,
in case specifying 0,6,12,... etc. is awkward.
-- 
FFmpeg = Fast Fancy Merciless Peaceful Elegant Guide


More information about the ffmpeg-user mailing list