[FFmpeg-user] Fixed GOP encoding for HLS

Anatol anatol2002 at gmail.com
Wed Dec 5 08:14:26 CET 2012


You can use 'sc_threshold' option to control the generation of KF's on
scene-cut cases. Setting this option to 0 turns it off. Inadvisable.
For 'force_key_frames' - simple sec count is enough, no need for
hh:mm:ss.mmm.
Apples's 'mediastreamvalidator' checks validity of HLS streams. Important
if u r trying to get Apple Appstore validation.

On Wed, Dec 5, 2012 at 7:29 AM, Andrew Sinclair <ajsinclair at gmail.com>wrote:

> Thanks for the tip and getting closer
>
> As if I use:
>
> ffmpeg -i 131375031.mp4 -vcodec libx264 -b:v 500k -r 24 -coder 0 -profile:v
> baseline -force_key_frames
>
> 00:00:06.000,00:00:12.000,00:00:18.000,00:00:24.000,00:00:30.000,00:00:36.000,00:00:42.000
> out_gop12_forcekeyframes.ts
>
> I get a much better m3u8 (not sure how the segmenter rounding works...) as
> the iframes look spot on.
>
> Would be great if there was a way to just specify every x seconds.
>
>
> #EXTM3U
> #EXT-X-VERSION:3
> #EXT-X-MEDIA-SEQUENCE:0
> #EXT-X-ALLOWCACHE:1
> #EXTINF:6.034289,
> out_seg6-000.ts
> #EXTINF:6.005422,
> out_seg6-001.ts
> #EXTINF:6.013578,
> out_seg6-002.ts
> #EXTINF:6.021744,
> out_seg6-003.ts
> #EXTINF:6.003789,
> out_seg6-004.ts
> #EXTINF:6.011944,
> out_seg6-005.ts
> #EXTINF:6.020111,
> out_seg6-006.ts
> #EXTINF:6.002156,
> out_seg6-007.ts
> #EXTINF:6.010322,
> out_seg6-008.ts
> #EXTINF:6.018478,
> out_seg6-009.ts
> #EXTINF:6.627456,
> out_seg6-010.ts
> #EXTINF:6.141233,
>
>
> Also what do you mean by "Don't turn of the scenecut frames"?
>
> Agreed half sec too small was just experimenting and there is a note in the
> -segment docs suggesting 1/2*frame_rate this which may need fixing
>
>
> On 5 December 2012 15:19, Anatol <anatol2002 at gmail.com> wrote:
>
> > Your command line does not 'force' key-frame every 12 frames, it just
> > 'recommends' it. Default ffmpeg settings has 'scenecut' key-frames
> > generation. This option is vital for preserving video quality. In order
> to
> > 'force' key frames at certain rate u actually have to spell-out the exact
> > timings that u want them to appear at. Use 'froce_keyframes' command line
> > option. DON'T turn of the scenecut key frames.
> >
> > By the way half sec GOPs are by far much too small, this also
> > can degrade the quality. 2-3 sec is enough.
> >
> > On Wed, Dec 5, 2012 at 1:15 AM, Andrew Sinclair <ajsinclair at gmail.com
> > >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
> > >
> > > 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
> > > _______________________________________________
> > > ffmpeg-user mailing list
> > > ffmpeg-user at ffmpeg.org
> > > http://ffmpeg.org/mailman/listinfo/ffmpeg-user
> > >
> > _______________________________________________
> > ffmpeg-user mailing list
> > ffmpeg-user at ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-user
> >
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>


More information about the ffmpeg-user mailing list