[FFmpeg-user] Fixed GOP encoding for HLS

Andrew Sinclair ajsinclair at gmail.com
Wed Dec 5 22:13:59 CET 2012


Christian - That is my experience as well in getting the keyframes to line
up exactly and it would be interesting to see how the calcs are done as the
values are smaller than a frame duration.

Steven - you don't quite have the m3u8 format correct. The #EXTINF:<value>
tag specifies the length of the following segment where the value is in
seconds. Note that having variable segment durations is perfectly within
the Apple HLS spec and would pass the media stream validator.

http://tools.ietf.org/html/draft-pantos-http-live-streaming-10#section-3.3.2


While the Apple spec does allow you to have varying length fragments my
experience is not all devices handle this well though in some cases this
may be due to older version of libavf. The output I provided was from an
Envivio encoder where possibly they are just rounding to the nearest
integer which is also within the spec.

I am going to try and encode a 2 hour movie with set keyframes which is
going to be a very long string of values to pass in to ffmpeg!


On 6 December 2012 08:00, Christian Ebert <blacktrash at gmx.net> wrote:

> * Christian Ebert on Wednesday, December 05, 2012 at 11:09:10 +0000
> > * Stefano Sabatini on Wednesday, December 05, 2012 at 01:00:08 +0100
> >> 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.
> >
> > This is a bit unclear to me: for 25 fps that would be half of
> > 0.04, i.e. 0.02?? The example says 0.05 which would point to a
> > very low framerate?
>
> I tried with 0.02 although it does not make a difference to
> omitting it in my case.
>
> To me it looks like -force_key_frames is not precise enough, I
> set it at 10,20,30 etc. and:
>
> key_frame=1
> pkt_pts_time=9.991300
> key_frame=1
> pkt_pts_time=10.014511
>
> With
>
> ffmpeg -i test.ts -c copy -map 0 -f segment -segment_time 10
> -segment_time_delta 0.02 -segment_list test.m3u8 test-%3d.ts
> ffmpeg version N-47489-g5381960 Copyright (c) 2000-2012 the FFmpeg
> developers
>   built on Dec  5 2012 19:39:55 with gcc 4.0.1 (GCC) (Apple Inc. build
> 5493)
>   configuration: --enable-gpl --enable-version3 --enable-nonfree
> --disable-network --disable-ffserver --disable-ffplay --enable-shared
> --enable-pthreads --enable-postproc --enable-libx264 --enable-libxvid
> --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis
> --enable-libvpx --enable-librtmp --extra-cflags=-I/sw/include
> --extra-libs=-L/sw/lib
>   libavutil      52. 11.102 / 52. 11.102
>   libavcodec     54. 79.100 / 54. 79.100
>   libavformat    54. 46.100 / 54. 46.100
>   libavdevice    54.  3.102 / 54.  3.102
>   libavfilter     3. 24.100 /  3. 24.100
>   libswscale      2.  1.103 /  2.  1.103
>   libswresample   0. 17.102 /  0. 17.102
>   libpostproc    52.  2.100 / 52.  2.100
> [mpegts @ 0x2002620] max_analyze_duration 5000000 reached at 5000000
> Input #0, mpegts, from 'test.ts':
>   Duration: 00:04:14.22, start: 1.376778, bitrate: 872 kb/s
>   Program 1
>     Metadata:
>       service_name    : Service01
>       service_provider: FFmpeg
>     Stream #0:0[0x100]: Video: h264 (Constrained Baseline) ([27][0][0][0]
> / 0x001B), yuv420p, 512x384 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 90k tbn, 50
> tbc
>     Stream #0:1[0x101](eng): Audio: aac ([15][0][0][0] / 0x000F), 44100
> Hz, stereo, fltp, 73 kb/s
> Output #0, segment, to 'test-%3d.ts':
>   Metadata:
>     encoder         : Lavf54.46.100
>     Stream #0:0: Video: h264 ([27][0][0][0] / 0x001B), yuv420p, 512x384
> [SAR 1:1 DAR 4:3], q=2-31, 25 fps, 90k tbn, 25 tbc
>     Stream #0:1(eng): Audio: aac ([15][0][0][0] / 0x000F), 44100 Hz,
> stereo, 73 kb/s
> Stream mapping:
>   Stream #0:0 -> #0:0 (copy)
>   Stream #0:1 -> #0:1 (copy)
> Press [q] to stop, [?] for help
> frame= 6356 fps=0.0 q=-1.0 Lsize=       0kB time=00:04:14.28 bitrate=
> 0.0kbits/s
> video:21843kB audio:2483kB subtitle:0 global headers:0kB muxing overhead
> -100.000000%
>
> this results in an unexpected/undesired EXT-X-TARGETDURATION of
> 11 instead of 10:
>
> tail test.m3u8
> #EXTINF:10.016744,
> test-022.ts
> #EXTINF:10.001378,
> test-023.ts
> #EXTINF:10.009189,
> test-024.ts
> #EXTINF:4.258411,
> test-025.ts
> #EXT-X-TARGETDURATION:11
> #EXT-X-ENDLIST
>
> Comments?
>
> --
> theatre - books - texts - movies
> Black Trash Productions at home: http://www.blacktrash.org
> Black Trash Productions on Facebook:
> http://www.facebook.com/blacktrashproductions
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>


More information about the ffmpeg-user mailing list