[FFmpeg-user] Fixed GOP encoding for HLS

Steven Liu lingjiujianke at gmail.com
Thu Dec 13 08:28:04 CET 2012


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


More information about the ffmpeg-user mailing list