[FFmpeg-user] Fixed GOP encoding for HLS

Andrew Sinclair ajsinclair at gmail.com
Wed Dec 5 00:15:46 CET 2012


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

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!):
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOWCACHE:1
#EXTINF:7.719244,
out_gop12_seg6-000.ts
#EXTINF:4.750000,
out_gop12_seg6-001.ts
#EXTINF:6.125000,
out_gop12_seg6-002.ts
#EXTINF:6.541667,
out_gop12_seg6-003.ts
#EXTINF:9.333333,
out_gop12_seg6-004.ts
#EXTINF:1.750000,
out_gop12_seg6-005.ts
#EXTINF:6.666667,
out_gop12_seg6-006.ts
#EXTINF:6.166667,
out_gop12_seg6-007.ts
#EXTINF:5.166667,
out_gop12_seg6-008.ts
#EXTINF:6.625000,
out_gop12_seg6-009.ts
#EXTINF:6.541667,
out_gop12_seg6-010.ts
#EXTINF:6.291667,
out_gop12_seg6-011.ts
#EXTINF:9.583333,
out_gop12_seg6-012.ts


More information about the ffmpeg-user mailing list