[FFmpeg-user] Fixed GOP encoding for HLS

Andrew Sinclair ajsinclair at gmail.com
Tue Dec 18 06:42:53 CET 2012


Looking at the proposed code change the +1 isn't necessary as according the
HLS spec the #EXT-X-TARGETDURATION only needs to be >= the segment
timeframe so as long as it is equal to it is OK.

I am also getting closer to the issue that I am seeing and it could be for
support for some older players as using a decimal/float as the duration is
only a reasonably recent addition to the spec as previously the #EXTINF
needed to be an int. I am going to play with some patches to the code I
have done for this and will report back.

However there is definitely some significant variaion in what segment.c is
generating as the #EXTINF durations and what ffprobe reports as the
duration. Can anyone point me in the direction of how segment.c calculates
the duration?


On 13 December 2012 18:28, Steven Liu <lingjiujianke at gmail.com> wrote:

> 2012/12/6 Christian Ebert <blacktrash at gmx.net>:
> > * Christian Ebert on Wednesday, December 05, 2012 at 21:00:43 +0000
> >> 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
> >
> > Oops, that's audio, but it seems the keyframes always are at +1.4
> > secs:
> >
> > ffprobe -show_frames test.ts 2>/dev/null | fgrep -B 14 -A 7 pict_type=I
> | head -45
> > [FRAME]
> > media_type=video
> > key_frame=1
> > pkt_pts=126000
> > pkt_pts_time=1.400000
> > pkt_dts=126000
> > pkt_dts_time=1.400000
> > pkt_duration=3600
> > pkt_duration_time=0.040000
> > pkt_pos=564
> > width=512
> > height=384
> > pix_fmt=yuv420p
> > sample_aspect_ratio=1:1
> > pict_type=I
> > coded_picture_number=0
> > display_picture_number=0
> > interlaced_frame=0
> > top_field_first=0
> > repeat_pict=0
> > reference=0
> > [/FRAME]
> > --
> > [FRAME]
> > media_type=video
> > key_frame=1
> > pkt_pts=1026000
> > pkt_pts_time=11.400000
> > pkt_dts=1026000
> > pkt_dts_time=11.400000
> > pkt_duration=3600
> > pkt_duration_time=0.040000
> > pkt_pos=161116
> > width=512
> > height=384
> > pix_fmt=yuv420p
> > sample_aspect_ratio=1:1
> > pict_type=I
> > coded_picture_number=250
> > display_picture_number=0
> > interlaced_frame=0
> > top_field_first=0
> > repeat_pict=0
> > reference=0
> > [/FRAME]
> >
> > But the above makes this entry:
> >
> > #EXTINF:10.030933,
> > test-000.ts
> >
> > even less understandable.
> >
> Christian
>
>       I have the same problem with you , the first segment starttime
> from 1.4s, Carl responsed me perhaps it's mpegts property, if you can
> fix this case, can you shared the way?
>
>       You can modify the libavformat/segment.c code,
>       the duration time was input from ffmpeg parameters,
>
>       I have modified the code and the patch is like follow:
>
> reference from
> http://tools.ietf.org/html/draft-pantos-http-live-streaming-10
> if the EXT-X-VERSION equ 3, the EXT-X-TARGETDURATION MUST large than EXTINF
>
> Signed-off-by: Steven Liu <liuqi at zecloud.cn>
> ---
>  libavformat/segment.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/segment.c b/libavformat/segment.c
> index 53feec4..57a58a5 100644
> --- a/libavformat/segment.c
> +++ b/libavformat/segment.c
> @@ -189,7 +189,7 @@ static int segment_list_open(AVFormatContext *s)
>                      !!(seg->list_flags & SEGMENT_LIST_FLAG_CACHE));
>          if (seg->list_flags & SEGMENT_LIST_FLAG_LIVE)
>              avio_printf(seg->list_pb,
> -                        "#EXT-X-TARGETDURATION:%"PRId64"\n",
> seg->time / 1000000);
> +                        "#EXT-X-TARGETDURATION:%"PRId64"\n",
> seg->time / 1000000 + 1);
>      }
>
>      return ret;
> @@ -202,7 +202,7 @@ static void segment_list_close(AVFormatContext *s)
>      if (seg->list_type == LIST_TYPE_M3U8) {
>          if (!(seg->list_flags & SEGMENT_LIST_FLAG_LIVE))
>              avio_printf(seg->list_pb, "#EXT-X-TARGETDURATION:%d\n",
> -                        (int)ceil(seg->list_max_segment_time));
> +                        (int)ceil(seg->list_max_segment_time) + 1);
>          avio_printf(seg->list_pb, "#EXT-X-ENDLIST\n");
>      }
>
> --
> 1.8.0.2
>
>
> I don't know if this modfy is right or wrong, but it can work. I hope
> this patch can help you.
>
>
>
> Thanks
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>


More information about the ffmpeg-user mailing list