diff mbox

[FFmpeg-devel,1/2] add option hls_init_time to set init hls window segment

Message ID CADxeRwmksMZKa+5-=9M+qSjheT=PN9O8aGXF_d2WpDn892Fx7A@mail.gmail.com
State Changes Requested
Headers show

Commit Message

Steven Liu Aug. 26, 2016, 9:30 a.m. UTC
recover segments duration time by hls_time after init hls window.
This is reuqested by Ibrahim Tachijian

Signed-off-by: LiuQi <liuqi@gosun.com>
---
 libavformat/hlsenc.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

     if (hls->format_options_str) {
@@ -860,9 +861,19 @@ static int hls_write_packet(AVFormatContext *s,
AVPacket *pkt)
     AVStream *st = s->streams[pkt->stream_index];
     int64_t end_pts = hls->recording_time * hls->number;
     int is_ref_pkt = 1;
+    int init_list_dur = 0;
+    int after_init_list_dur = 0;
     int ret, can_split = 1;
     int stream_index = 0;

+    if (hls->sequence - hls->nb_entries > hls->start_sequence &&
hls->init_time > 0) {
+        /* reset end_pts, hls->recording_time at end of the init hls list
*/
+        init_list_dur = hls->init_time * hls->nb_entries * AV_TIME_BASE;
+        after_init_list_dur = (hls->sequence - hls->nb_entries ) *
hls->time * AV_TIME_BASE;
+        hls->recording_time = hls->time * AV_TIME_BASE;
+        end_pts = init_list_dur + after_init_list_dur ;
+    }
+
     if( st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE ) {
         oc = hls->vtt_avf;
         stream_index = 0;
@@ -972,6 +983,7 @@ static int hls_write_trailer(struct AVFormatContext *s)
 static const AVOption options[] = {
     {"start_number",  "set first number in the sequence",
 OFFSET(start_sequence),AV_OPT_TYPE_INT64,  {.i64 = 0},     0, INT64_MAX,
E},
     {"hls_time",      "set segment length in seconds",
OFFSET(time),    AV_OPT_TYPE_FLOAT,  {.dbl = 2},     0, FLT_MAX, E},
+    {"hls_init_time", "set segment length in seconds at init list",
    OFFSET(init_time),    AV_OPT_TYPE_FLOAT,  {.dbl = 0},     0, FLT_MAX,
E},
     {"hls_list_size", "set maximum number of playlist entries",
 OFFSET(max_nb_segments),    AV_OPT_TYPE_INT,    {.i64 = 5},     0,
INT_MAX, E},
     {"hls_ts_options","set hls mpegts list of options for the container
format used for hls", OFFSET(format_options_str), AV_OPT_TYPE_STRING, {.str
= NULL},  0, 0,    E},
     {"hls_vtt_options","set hls vtt list of options for the container
format used for hls", OFFSET(vtt_format_options_str), AV_OPT_TYPE_STRING,
{.str = NULL},  0, 0,    E},
--
2.7.4 (Apple Git-66)





Test :

/root/ffmpeg_patched -analyzeduration 1000000 -i udp://MCAST_ADDR:3301 -map
0:0 -map 0:1 -c:v libx264 -preset superfast -g 25 -b:v 900k -maxrate 900k
-bufsize 2000k -filter:v yadif -c:a libfdk_aac -b:a 64k -hls_time 5
*-hls_init_time
1* -hls_list_size 10 -hls_allow_cache 0 -hls_flags delete_segments -f hls
/tmp/playlist.m3u8

The output M3U8 of patched ffmpeg:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-ALLOW-CACHE:NO
#EXT-X-TARGETDURATION:5
#EXT-X-MEDIA-SEQUENCE:3
#EXTINF:1.000000,
playlist3.ts
#EXTINF:1.000000,
playlist4.ts
#EXTINF:1.000000,
playlist5.ts
#EXTINF:1.000000,
playlist6.ts
#EXTINF:1.000000,
playlist7.ts
#EXTINF:1.000000,
playlist8.ts
#EXTINF:1.600000,
playlist9.ts
#EXTINF:1.000000,
playlist10.ts
#EXTINF:4.000000,
playlist11.ts
#EXTINF:5.000000,
playlist12.ts

Comments

Michael Niedermayer Aug. 26, 2016, 8:49 p.m. UTC | #1
On Fri, Aug 26, 2016 at 05:30:41PM +0800, Steven Liu wrote:
> recover segments duration time by hls_time after init hls window.
> This is reuqested by Ibrahim Tachijian
> 
> Signed-off-by: LiuQi <liuqi@gosun.com>
> ---
>  libavformat/hlsenc.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
[...]
>  hlsenc.c |   14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> f38066079d46206d1bc970f026a7a9de25ace8d1  0001-add-option-hls_init_time-to-set-init-hls-window-segm.patch
> From 937e5301414f1c43c4c564ee59a4dfeee690293c Mon Sep 17 00:00:00 2001
> From: Steven Liu <lingjiujianke@gmail.com>
> Date: Fri, 26 Aug 2016 14:34:58 +0800
> Subject: [PATCH 1/2] add option hls_init_time to set init hls window segment
>  duration
> 
> And recover segments duration time by hls_time after init hls window.
> This is reuqested by Ibrahim Tachijian
> 
> Signed-off-by: LiuQi <liuqi@gosun.com>
> ---
>  libavformat/hlsenc.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index e65f002..f5ceb60 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -85,6 +85,7 @@ typedef struct HLSContext {
>      AVFormatContext *vtt_avf;
>  
>      float time;            // Set by a private option.
> +    float init_time;            // Set by a private option.
>      int max_nb_segments;   // Set by a private option.
>      int  wrap;             // Set by a private option.

the comment looks oddly aligned, it should be at the same horizontal
position as teh others


>      uint32_t flags;        // enum HLSFlags
> @@ -706,7 +707,7 @@ static int hls_write_header(AVFormatContext *s)
>      int vtt_basename_size;
>  
>      hls->sequence       = hls->start_sequence;
> -    hls->recording_time = hls->time * AV_TIME_BASE;
> +    hls->recording_time = (hls->init_time ? hls->init_time : hls->time) * AV_TIME_BASE;
>      hls->start_pts      = AV_NOPTS_VALUE;
>  
>      if (hls->format_options_str) {
> @@ -860,9 +861,19 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
>      AVStream *st = s->streams[pkt->stream_index];
>      int64_t end_pts = hls->recording_time * hls->number;
>      int is_ref_pkt = 1;

> +    int init_list_dur = 0;
> +    int after_init_list_dur = 0;

the initialized value is not used
also the declaration can be moved into the if() below

>      int ret, can_split = 1;
>      int stream_index = 0;
>  
> +    if (hls->sequence - hls->nb_entries > hls->start_sequence && hls->init_time > 0) {
> +        /* reset end_pts, hls->recording_time at end of the init hls list */
> +        init_list_dur = hls->init_time * hls->nb_entries * AV_TIME_BASE;
> +        after_init_list_dur = (hls->sequence - hls->nb_entries ) * hls->time * AV_TIME_BASE;
> +        hls->recording_time = hls->time * AV_TIME_BASE;
> +        end_pts = init_list_dur + after_init_list_dur ;
> +    }
> +
>      if( st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE ) {
>          oc = hls->vtt_avf;
>          stream_index = 0;
> @@ -972,6 +983,7 @@ static int hls_write_trailer(struct AVFormatContext *s)
[...]
Steven Liu Aug. 26, 2016, 11:44 p.m. UTC | #2
2016-08-27 4:49 GMT+08:00 Michael Niedermayer <michael@niedermayer.cc>:

> On Fri, Aug 26, 2016 at 05:30:41PM +0800, Steven Liu wrote:
> > recover segments duration time by hls_time after init hls window.
> > This is reuqested by Ibrahim Tachijian
> >
> > Signed-off-by: LiuQi <liuqi@gosun.com>
> > ---
> >  libavformat/hlsenc.c | 14 +++++++++++++-
> >  1 file changed, 13 insertions(+), 1 deletion(-)
> [...]
> >  hlsenc.c |   14 +++++++++++++-
> >  1 file changed, 13 insertions(+), 1 deletion(-)
> > f38066079d46206d1bc970f026a7a9de25ace8d1  0001-add-option-hls_init_time-
> to-set-init-hls-window-segm.patch
> > From 937e5301414f1c43c4c564ee59a4dfeee690293c Mon Sep 17 00:00:00 2001
> > From: Steven Liu <lingjiujianke@gmail.com>
> > Date: Fri, 26 Aug 2016 14:34:58 +0800
> > Subject: [PATCH 1/2] add option hls_init_time to set init hls window
> segment
> >  duration
> >
> > And recover segments duration time by hls_time after init hls window.
> > This is reuqested by Ibrahim Tachijian
> >
> > Signed-off-by: LiuQi <liuqi@gosun.com>
> > ---
> >  libavformat/hlsenc.c | 14 +++++++++++++-
> >  1 file changed, 13 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> > index e65f002..f5ceb60 100644
> > --- a/libavformat/hlsenc.c
> > +++ b/libavformat/hlsenc.c
> > @@ -85,6 +85,7 @@ typedef struct HLSContext {
> >      AVFormatContext *vtt_avf;
> >
> >      float time;            // Set by a private option.
> > +    float init_time;            // Set by a private option.
> >      int max_nb_segments;   // Set by a private option.
> >      int  wrap;             // Set by a private option.
>
> the comment looks oddly aligned, it should be at the same horizontal
> position as teh others
>
>
> >      uint32_t flags;        // enum HLSFlags
> > @@ -706,7 +707,7 @@ static int hls_write_header(AVFormatContext *s)
> >      int vtt_basename_size;
> >
> >      hls->sequence       = hls->start_sequence;
> > -    hls->recording_time = hls->time * AV_TIME_BASE;
> > +    hls->recording_time = (hls->init_time ? hls->init_time : hls->time)
> * AV_TIME_BASE;
> >      hls->start_pts      = AV_NOPTS_VALUE;
> >
> >      if (hls->format_options_str) {
> > @@ -860,9 +861,19 @@ static int hls_write_packet(AVFormatContext *s,
> AVPacket *pkt)
> >      AVStream *st = s->streams[pkt->stream_index];
> >      int64_t end_pts = hls->recording_time * hls->number;
> >      int is_ref_pkt = 1;
>
> > +    int init_list_dur = 0;
> > +    int after_init_list_dur = 0;
>
> the initialized value is not used
> also the declaration can be moved into the if() below
>
> >      int ret, can_split = 1;
> >      int stream_index = 0;
> >
> > +    if (hls->sequence - hls->nb_entries > hls->start_sequence &&
> hls->init_time > 0) {
> > +        /* reset end_pts, hls->recording_time at end of the init hls
> list */
> > +        init_list_dur = hls->init_time * hls->nb_entries * AV_TIME_BASE;
> > +        after_init_list_dur = (hls->sequence - hls->nb_entries ) *
> hls->time * AV_TIME_BASE;
> > +        hls->recording_time = hls->time * AV_TIME_BASE;
> > +        end_pts = init_list_dur + after_init_list_dur ;
> > +    }
> > +
> >      if( st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE ) {
> >          oc = hls->vtt_avf;
> >          stream_index = 0;
> > @@ -972,6 +983,7 @@ static int hls_write_trailer(struct AVFormatContext
> *s)
> [...]
>
>
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Let us carefully observe those good qualities wherein our enemies excel us
> and endeavor to excel them, by avoiding what is faulty, and imitating what
> is excellent in them. -- Plutarch
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> Update patch
Michael Niedermayer Aug. 27, 2016, 10:25 a.m. UTC | #3
On Sat, Aug 27, 2016 at 07:44:01AM +0800, Steven Liu wrote:
> 2016-08-27 4:49 GMT+08:00 Michael Niedermayer <michael@niedermayer.cc>:
> 
> > On Fri, Aug 26, 2016 at 05:30:41PM +0800, Steven Liu wrote:
> > > recover segments duration time by hls_time after init hls window.
> > > This is reuqested by Ibrahim Tachijian
> > >
> > > Signed-off-by: LiuQi <liuqi@gosun.com>
> > > ---
> > >  libavformat/hlsenc.c | 14 +++++++++++++-
> > >  1 file changed, 13 insertions(+), 1 deletion(-)
> > [...]
> > >  hlsenc.c |   14 +++++++++++++-
> > >  1 file changed, 13 insertions(+), 1 deletion(-)
> > > f38066079d46206d1bc970f026a7a9de25ace8d1  0001-add-option-hls_init_time-
> > to-set-init-hls-window-segm.patch
> > > From 937e5301414f1c43c4c564ee59a4dfeee690293c Mon Sep 17 00:00:00 2001
> > > From: Steven Liu <lingjiujianke@gmail.com>
> > > Date: Fri, 26 Aug 2016 14:34:58 +0800
> > > Subject: [PATCH 1/2] add option hls_init_time to set init hls window
> > segment
> > >  duration
> > >
> > > And recover segments duration time by hls_time after init hls window.
> > > This is reuqested by Ibrahim Tachijian
> > >
> > > Signed-off-by: LiuQi <liuqi@gosun.com>
> > > ---
> > >  libavformat/hlsenc.c | 14 +++++++++++++-
> > >  1 file changed, 13 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> > > index e65f002..f5ceb60 100644
> > > --- a/libavformat/hlsenc.c
> > > +++ b/libavformat/hlsenc.c
> > > @@ -85,6 +85,7 @@ typedef struct HLSContext {
> > >      AVFormatContext *vtt_avf;
> > >
> > >      float time;            // Set by a private option.
> > > +    float init_time;            // Set by a private option.
> > >      int max_nb_segments;   // Set by a private option.
> > >      int  wrap;             // Set by a private option.
> >
> > the comment looks oddly aligned, it should be at the same horizontal
> > position as teh others
> >
> >
> > >      uint32_t flags;        // enum HLSFlags
> > > @@ -706,7 +707,7 @@ static int hls_write_header(AVFormatContext *s)
> > >      int vtt_basename_size;
> > >
> > >      hls->sequence       = hls->start_sequence;
> > > -    hls->recording_time = hls->time * AV_TIME_BASE;
> > > +    hls->recording_time = (hls->init_time ? hls->init_time : hls->time)
> > * AV_TIME_BASE;
> > >      hls->start_pts      = AV_NOPTS_VALUE;
> > >
> > >      if (hls->format_options_str) {
> > > @@ -860,9 +861,19 @@ static int hls_write_packet(AVFormatContext *s,
> > AVPacket *pkt)
> > >      AVStream *st = s->streams[pkt->stream_index];
> > >      int64_t end_pts = hls->recording_time * hls->number;
> > >      int is_ref_pkt = 1;
> >
> > > +    int init_list_dur = 0;
> > > +    int after_init_list_dur = 0;
> >
> > the initialized value is not used
> > also the declaration can be moved into the if() below
> >
> > >      int ret, can_split = 1;
> > >      int stream_index = 0;
> > >
> > > +    if (hls->sequence - hls->nb_entries > hls->start_sequence &&
> > hls->init_time > 0) {
> > > +        /* reset end_pts, hls->recording_time at end of the init hls
> > list */
> > > +        init_list_dur = hls->init_time * hls->nb_entries * AV_TIME_BASE;
> > > +        after_init_list_dur = (hls->sequence - hls->nb_entries ) *
> > hls->time * AV_TIME_BASE;
> > > +        hls->recording_time = hls->time * AV_TIME_BASE;
> > > +        end_pts = init_list_dur + after_init_list_dur ;
> > > +    }
> > > +
> > >      if( st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE ) {
> > >          oc = hls->vtt_avf;
> > >          stream_index = 0;
> > > @@ -972,6 +983,7 @@ static int hls_write_trailer(struct AVFormatContext
> > *s)
> > [...]
> >
> >
> > --
> > Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> >
> > Let us carefully observe those good qualities wherein our enemies excel us
> > and endeavor to excel them, by avoiding what is faulty, and imitating what
> > is excellent in them. -- Plutarch
> >
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > Update patch

>  hlsenc.c |   14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 2feb683487b70430f2ea423d2678d7f30d0c3079  0001-add-option-hls_init_time-to-set-init-hls-window-segm.patch
> From dfadb857714867613afebe1a740a8e7fccaa5443 Mon Sep 17 00:00:00 2001
> From: Steven Liu <lingjiujianke@gmail.com>
> Date: Sat, 27 Aug 2016 07:32:40 +0800
> Subject: [PATCH 1/2] add option hls_init_time to set init hls window segment
>  duration
> 
> recover segments duration time by hls_time after init hls window.
> This is reuqested by Ibrahim Tachijian
> 
> Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
> Signed-off-by: LiuQi <liuqi@gosun.com>
> ---
>  libavformat/hlsenc.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index e65f002..95da86c 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -85,6 +85,7 @@ typedef struct HLSContext {
>      AVFormatContext *vtt_avf;
>  
>      float time;            // Set by a private option.
> +    float init_time;       // Set by a private option.
>      int max_nb_segments;   // Set by a private option.
>      int  wrap;             // Set by a private option.
>      uint32_t flags;        // enum HLSFlags
> @@ -706,7 +707,7 @@ static int hls_write_header(AVFormatContext *s)
>      int vtt_basename_size;
>  
>      hls->sequence       = hls->start_sequence;
> -    hls->recording_time = hls->time * AV_TIME_BASE;
> +    hls->recording_time = (hls->init_time ? hls->init_time : hls->time) * AV_TIME_BASE;
>      hls->start_pts      = AV_NOPTS_VALUE;
>  
>      if (hls->format_options_str) {

> @@ -863,6 +864,16 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
>      int ret, can_split = 1;
>      int stream_index = 0;
>  
> +    if (hls->sequence - hls->nb_entries > hls->start_sequence && hls->init_time > 0) {
> +        int init_list_dur = 0;
> +        int after_init_list_dur = 0;
> +        /* reset end_pts, hls->recording_time at end of the init hls list */
> +        init_list_dur = hls->init_time * hls->nb_entries * AV_TIME_BASE;
> +        after_init_list_dur = (hls->sequence - hls->nb_entries ) * hls->time * AV_TIME_BASE;

the first assignment does nothing
int a = 0;
a = 5;
is the same as
int a = 5

[...]
Steven Liu Aug. 27, 2016, 11:15 a.m. UTC | #4
2016-08-27 18:25 GMT+08:00 Michael Niedermayer <michael@niedermayer.cc>:

> On Sat, Aug 27, 2016 at 07:44:01AM +0800, Steven Liu wrote:
> > 2016-08-27 4:49 GMT+08:00 Michael Niedermayer <michael@niedermayer.cc>:
> >
> > > On Fri, Aug 26, 2016 at 05:30:41PM +0800, Steven Liu wrote:
> > > > recover segments duration time by hls_time after init hls window.
> > > > This is reuqested by Ibrahim Tachijian
> > > >
> > > > Signed-off-by: LiuQi <liuqi@gosun.com>
> > > > ---
> > > >  libavformat/hlsenc.c | 14 +++++++++++++-
> > > >  1 file changed, 13 insertions(+), 1 deletion(-)
> > > [...]
> > > >  hlsenc.c |   14 +++++++++++++-
> > > >  1 file changed, 13 insertions(+), 1 deletion(-)
> > > > f38066079d46206d1bc970f026a7a9de25ace8d1
> 0001-add-option-hls_init_time-
> > > to-set-init-hls-window-segm.patch
> > > > From 937e5301414f1c43c4c564ee59a4dfeee690293c Mon Sep 17 00:00:00
> 2001
> > > > From: Steven Liu <lingjiujianke@gmail.com>
> > > > Date: Fri, 26 Aug 2016 14:34:58 +0800
> > > > Subject: [PATCH 1/2] add option hls_init_time to set init hls window
> > > segment
> > > >  duration
> > > >
> > > > And recover segments duration time by hls_time after init hls window.
> > > > This is reuqested by Ibrahim Tachijian
> > > >
> > > > Signed-off-by: LiuQi <liuqi@gosun.com>
> > > > ---
> > > >  libavformat/hlsenc.c | 14 +++++++++++++-
> > > >  1 file changed, 13 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> > > > index e65f002..f5ceb60 100644
> > > > --- a/libavformat/hlsenc.c
> > > > +++ b/libavformat/hlsenc.c
> > > > @@ -85,6 +85,7 @@ typedef struct HLSContext {
> > > >      AVFormatContext *vtt_avf;
> > > >
> > > >      float time;            // Set by a private option.
> > > > +    float init_time;            // Set by a private option.
> > > >      int max_nb_segments;   // Set by a private option.
> > > >      int  wrap;             // Set by a private option.
> > >
> > > the comment looks oddly aligned, it should be at the same horizontal
> > > position as teh others
> > >
> > >
> > > >      uint32_t flags;        // enum HLSFlags
> > > > @@ -706,7 +707,7 @@ static int hls_write_header(AVFormatContext *s)
> > > >      int vtt_basename_size;
> > > >
> > > >      hls->sequence       = hls->start_sequence;
> > > > -    hls->recording_time = hls->time * AV_TIME_BASE;
> > > > +    hls->recording_time = (hls->init_time ? hls->init_time :
> hls->time)
> > > * AV_TIME_BASE;
> > > >      hls->start_pts      = AV_NOPTS_VALUE;
> > > >
> > > >      if (hls->format_options_str) {
> > > > @@ -860,9 +861,19 @@ static int hls_write_packet(AVFormatContext *s,
> > > AVPacket *pkt)
> > > >      AVStream *st = s->streams[pkt->stream_index];
> > > >      int64_t end_pts = hls->recording_time * hls->number;
> > > >      int is_ref_pkt = 1;
> > >
> > > > +    int init_list_dur = 0;
> > > > +    int after_init_list_dur = 0;
> > >
> > > the initialized value is not used
> > > also the declaration can be moved into the if() below
> > >
> > > >      int ret, can_split = 1;
> > > >      int stream_index = 0;
> > > >
> > > > +    if (hls->sequence - hls->nb_entries > hls->start_sequence &&
> > > hls->init_time > 0) {
> > > > +        /* reset end_pts, hls->recording_time at end of the init hls
> > > list */
> > > > +        init_list_dur = hls->init_time * hls->nb_entries *
> AV_TIME_BASE;
> > > > +        after_init_list_dur = (hls->sequence - hls->nb_entries ) *
> > > hls->time * AV_TIME_BASE;
> > > > +        hls->recording_time = hls->time * AV_TIME_BASE;
> > > > +        end_pts = init_list_dur + after_init_list_dur ;
> > > > +    }
> > > > +
> > > >      if( st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE ) {
> > > >          oc = hls->vtt_avf;
> > > >          stream_index = 0;
> > > > @@ -972,6 +983,7 @@ static int hls_write_trailer(struct
> AVFormatContext
> > > *s)
> > > [...]
> > >
> > >
> > > --
> > > Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC7
> 87040B0FAB
> > >
> > > Let us carefully observe those good qualities wherein our enemies
> excel us
> > > and endeavor to excel them, by avoiding what is faulty, and imitating
> what
> > > is excellent in them. -- Plutarch
> > >
> > > _______________________________________________
> > > ffmpeg-devel mailing list
> > > ffmpeg-devel@ffmpeg.org
> > > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > >
> > > Update patch
>
> >  hlsenc.c |   14 +++++++++++++-
> >  1 file changed, 13 insertions(+), 1 deletion(-)
> > 2feb683487b70430f2ea423d2678d7f30d0c3079  0001-add-option-hls_init_time-
> to-set-init-hls-window-segm.patch
> > From dfadb857714867613afebe1a740a8e7fccaa5443 Mon Sep 17 00:00:00 2001
> > From: Steven Liu <lingjiujianke@gmail.com>
> > Date: Sat, 27 Aug 2016 07:32:40 +0800
> > Subject: [PATCH 1/2] add option hls_init_time to set init hls window
> segment
> >  duration
> >
> > recover segments duration time by hls_time after init hls window.
> > This is reuqested by Ibrahim Tachijian
> >
> > Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
> > Signed-off-by: LiuQi <liuqi@gosun.com>
> > ---
> >  libavformat/hlsenc.c | 14 +++++++++++++-
> >  1 file changed, 13 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> > index e65f002..95da86c 100644
> > --- a/libavformat/hlsenc.c
> > +++ b/libavformat/hlsenc.c
> > @@ -85,6 +85,7 @@ typedef struct HLSContext {
> >      AVFormatContext *vtt_avf;
> >
> >      float time;            // Set by a private option.
> > +    float init_time;       // Set by a private option.
> >      int max_nb_segments;   // Set by a private option.
> >      int  wrap;             // Set by a private option.
> >      uint32_t flags;        // enum HLSFlags
> > @@ -706,7 +707,7 @@ static int hls_write_header(AVFormatContext *s)
> >      int vtt_basename_size;
> >
> >      hls->sequence       = hls->start_sequence;
> > -    hls->recording_time = hls->time * AV_TIME_BASE;
> > +    hls->recording_time = (hls->init_time ? hls->init_time : hls->time)
> * AV_TIME_BASE;
> >      hls->start_pts      = AV_NOPTS_VALUE;
> >
> >      if (hls->format_options_str) {
>
> > @@ -863,6 +864,16 @@ static int hls_write_packet(AVFormatContext *s,
> AVPacket *pkt)
> >      int ret, can_split = 1;
> >      int stream_index = 0;
> >
> > +    if (hls->sequence - hls->nb_entries > hls->start_sequence &&
> hls->init_time > 0) {
> > +        int init_list_dur = 0;
> > +        int after_init_list_dur = 0;
> > +        /* reset end_pts, hls->recording_time at end of the init hls
> list */
> > +        init_list_dur = hls->init_time * hls->nb_entries * AV_TIME_BASE;
> > +        after_init_list_dur = (hls->sequence - hls->nb_entries ) *
> hls->time * AV_TIME_BASE;
>
> the first assignment does nothing
> int a = 0;
> a = 5;
> is the same as
> int a = 5
>
> [...]
>
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Breaking DRM is a little like attempting to break through a door even
> though the window is wide open and the only thing in the house is a bunch
> of things you dont want and which you would get tomorrow for free anyway
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> refined the patch and update patch by Michael's suggestion
Steven Liu Aug. 27, 2016, 2:42 p.m. UTC | #5
2016-08-27 19:15 GMT+08:00 Steven Liu <lingjiujianke@gmail.com>:

>
>
> 2016-08-27 18:25 GMT+08:00 Michael Niedermayer <michael@niedermayer.cc>:
>
>> On Sat, Aug 27, 2016 at 07:44:01AM +0800, Steven Liu wrote:
>> > 2016-08-27 4:49 GMT+08:00 Michael Niedermayer <michael@niedermayer.cc>:
>> >
>> > > On Fri, Aug 26, 2016 at 05:30:41PM +0800, Steven Liu wrote:
>> > > > recover segments duration time by hls_time after init hls window.
>> > > > This is reuqested by Ibrahim Tachijian
>> > > >
>> > > > Signed-off-by: LiuQi <liuqi@gosun.com>
>> > > > ---
>> > > >  libavformat/hlsenc.c | 14 +++++++++++++-
>> > > >  1 file changed, 13 insertions(+), 1 deletion(-)
>> > > [...]
>> > > >  hlsenc.c |   14 +++++++++++++-
>> > > >  1 file changed, 13 insertions(+), 1 deletion(-)
>> > > > f38066079d46206d1bc970f026a7a9de25ace8d1
>> 0001-add-option-hls_init_time-
>> > > to-set-init-hls-window-segm.patch
>> > > > From 937e5301414f1c43c4c564ee59a4dfeee690293c Mon Sep 17 00:00:00
>> 2001
>> > > > From: Steven Liu <lingjiujianke@gmail.com>
>> > > > Date: Fri, 26 Aug 2016 14:34:58 +0800
>> > > > Subject: [PATCH 1/2] add option hls_init_time to set init hls window
>> > > segment
>> > > >  duration
>> > > >
>> > > > And recover segments duration time by hls_time after init hls
>> window.
>> > > > This is reuqested by Ibrahim Tachijian
>> > > >
>> > > > Signed-off-by: LiuQi <liuqi@gosun.com>
>> > > > ---
>> > > >  libavformat/hlsenc.c | 14 +++++++++++++-
>> > > >  1 file changed, 13 insertions(+), 1 deletion(-)
>> > > >
>> > > > diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> > > > index e65f002..f5ceb60 100644
>> > > > --- a/libavformat/hlsenc.c
>> > > > +++ b/libavformat/hlsenc.c
>> > > > @@ -85,6 +85,7 @@ typedef struct HLSContext {
>> > > >      AVFormatContext *vtt_avf;
>> > > >
>> > > >      float time;            // Set by a private option.
>> > > > +    float init_time;            // Set by a private option.
>> > > >      int max_nb_segments;   // Set by a private option.
>> > > >      int  wrap;             // Set by a private option.
>> > >
>> > > the comment looks oddly aligned, it should be at the same horizontal
>> > > position as teh others
>> > >
>> > >
>> > > >      uint32_t flags;        // enum HLSFlags
>> > > > @@ -706,7 +707,7 @@ static int hls_write_header(AVFormatContext *s)
>> > > >      int vtt_basename_size;
>> > > >
>> > > >      hls->sequence       = hls->start_sequence;
>> > > > -    hls->recording_time = hls->time * AV_TIME_BASE;
>> > > > +    hls->recording_time = (hls->init_time ? hls->init_time :
>> hls->time)
>> > > * AV_TIME_BASE;
>> > > >      hls->start_pts      = AV_NOPTS_VALUE;
>> > > >
>> > > >      if (hls->format_options_str) {
>> > > > @@ -860,9 +861,19 @@ static int hls_write_packet(AVFormatContext
>> *s,
>> > > AVPacket *pkt)
>> > > >      AVStream *st = s->streams[pkt->stream_index];
>> > > >      int64_t end_pts = hls->recording_time * hls->number;
>> > > >      int is_ref_pkt = 1;
>> > >
>> > > > +    int init_list_dur = 0;
>> > > > +    int after_init_list_dur = 0;
>> > >
>> > > the initialized value is not used
>> > > also the declaration can be moved into the if() below
>> > >
>> > > >      int ret, can_split = 1;
>> > > >      int stream_index = 0;
>> > > >
>> > > > +    if (hls->sequence - hls->nb_entries > hls->start_sequence &&
>> > > hls->init_time > 0) {
>> > > > +        /* reset end_pts, hls->recording_time at end of the init
>> hls
>> > > list */
>> > > > +        init_list_dur = hls->init_time * hls->nb_entries *
>> AV_TIME_BASE;
>> > > > +        after_init_list_dur = (hls->sequence - hls->nb_entries ) *
>> > > hls->time * AV_TIME_BASE;
>> > > > +        hls->recording_time = hls->time * AV_TIME_BASE;
>> > > > +        end_pts = init_list_dur + after_init_list_dur ;
>> > > > +    }
>> > > > +
>> > > >      if( st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE ) {
>> > > >          oc = hls->vtt_avf;
>> > > >          stream_index = 0;
>> > > > @@ -972,6 +983,7 @@ static int hls_write_trailer(struct
>> AVFormatContext
>> > > *s)
>> > > [...]
>> > >
>> > >
>> > > --
>> > > Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC7
>> 87040B0FAB
>> > >
>> > > Let us carefully observe those good qualities wherein our enemies
>> excel us
>> > > and endeavor to excel them, by avoiding what is faulty, and imitating
>> what
>> > > is excellent in them. -- Plutarch
>> > >
>> > > _______________________________________________
>> > > ffmpeg-devel mailing list
>> > > ffmpeg-devel@ffmpeg.org
>> > > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> > >
>> > > Update patch
>>
>> >  hlsenc.c |   14 +++++++++++++-
>> >  1 file changed, 13 insertions(+), 1 deletion(-)
>> > 2feb683487b70430f2ea423d2678d7f30d0c3079
>> 0001-add-option-hls_init_time-to-set-init-hls-window-segm.patch
>> > From dfadb857714867613afebe1a740a8e7fccaa5443 Mon Sep 17 00:00:00 2001
>> > From: Steven Liu <lingjiujianke@gmail.com>
>> > Date: Sat, 27 Aug 2016 07:32:40 +0800
>> > Subject: [PATCH 1/2] add option hls_init_time to set init hls window
>> segment
>> >  duration
>> >
>> > recover segments duration time by hls_time after init hls window.
>> > This is reuqested by Ibrahim Tachijian
>> >
>> > Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
>> > Signed-off-by: LiuQi <liuqi@gosun.com>
>> > ---
>> >  libavformat/hlsenc.c | 14 +++++++++++++-
>> >  1 file changed, 13 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> > index e65f002..95da86c 100644
>> > --- a/libavformat/hlsenc.c
>> > +++ b/libavformat/hlsenc.c
>> > @@ -85,6 +85,7 @@ typedef struct HLSContext {
>> >      AVFormatContext *vtt_avf;
>> >
>> >      float time;            // Set by a private option.
>> > +    float init_time;       // Set by a private option.
>> >      int max_nb_segments;   // Set by a private option.
>> >      int  wrap;             // Set by a private option.
>> >      uint32_t flags;        // enum HLSFlags
>> > @@ -706,7 +707,7 @@ static int hls_write_header(AVFormatContext *s)
>> >      int vtt_basename_size;
>> >
>> >      hls->sequence       = hls->start_sequence;
>> > -    hls->recording_time = hls->time * AV_TIME_BASE;
>> > +    hls->recording_time = (hls->init_time ? hls->init_time :
>> hls->time) * AV_TIME_BASE;
>> >      hls->start_pts      = AV_NOPTS_VALUE;
>> >
>> >      if (hls->format_options_str) {
>>
>> > @@ -863,6 +864,16 @@ static int hls_write_packet(AVFormatContext *s,
>> AVPacket *pkt)
>> >      int ret, can_split = 1;
>> >      int stream_index = 0;
>> >
>> > +    if (hls->sequence - hls->nb_entries > hls->start_sequence &&
>> hls->init_time > 0) {
>> > +        int init_list_dur = 0;
>> > +        int after_init_list_dur = 0;
>> > +        /* reset end_pts, hls->recording_time at end of the init hls
>> list */
>> > +        init_list_dur = hls->init_time * hls->nb_entries *
>> AV_TIME_BASE;
>> > +        after_init_list_dur = (hls->sequence - hls->nb_entries ) *
>> hls->time * AV_TIME_BASE;
>>
>> the first assignment does nothing
>> int a = 0;
>> a = 5;
>> is the same as
>> int a = 5
>>
>> [...]
>>
>> --
>> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>>
>> Breaking DRM is a little like attempting to break through a door even
>> though the window is wide open and the only thing in the house is a bunch
>> of things you dont want and which you would get tomorrow for free anyway
>>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> refined the patch and update patch by Michael's suggestion
>
Ignore prev patch, this is update patch: Update commit Author
Michael Niedermayer Aug. 29, 2016, 1:05 p.m. UTC | #6
On Sat, Aug 27, 2016 at 10:42:25PM +0800, Steven Liu wrote:
> 2016-08-27 19:15 GMT+08:00 Steven Liu <lingjiujianke@gmail.com>:
> 
> >
> >
> > 2016-08-27 18:25 GMT+08:00 Michael Niedermayer <michael@niedermayer.cc>:
> >
> >> On Sat, Aug 27, 2016 at 07:44:01AM +0800, Steven Liu wrote:
> >> > 2016-08-27 4:49 GMT+08:00 Michael Niedermayer <michael@niedermayer.cc>:
> >> >
> >> > > On Fri, Aug 26, 2016 at 05:30:41PM +0800, Steven Liu wrote:
> >> > > > recover segments duration time by hls_time after init hls window.
> >> > > > This is reuqested by Ibrahim Tachijian
> >> > > >
> >> > > > Signed-off-by: LiuQi <liuqi@gosun.com>
> >> > > > ---
> >> > > >  libavformat/hlsenc.c | 14 +++++++++++++-
> >> > > >  1 file changed, 13 insertions(+), 1 deletion(-)
> >> > > [...]
> >> > > >  hlsenc.c |   14 +++++++++++++-
> >> > > >  1 file changed, 13 insertions(+), 1 deletion(-)
> >> > > > f38066079d46206d1bc970f026a7a9de25ace8d1
> >> 0001-add-option-hls_init_time-
> >> > > to-set-init-hls-window-segm.patch
> >> > > > From 937e5301414f1c43c4c564ee59a4dfeee690293c Mon Sep 17 00:00:00
> >> 2001
> >> > > > From: Steven Liu <lingjiujianke@gmail.com>
> >> > > > Date: Fri, 26 Aug 2016 14:34:58 +0800
> >> > > > Subject: [PATCH 1/2] add option hls_init_time to set init hls window
> >> > > segment
> >> > > >  duration
> >> > > >
> >> > > > And recover segments duration time by hls_time after init hls
> >> window.
> >> > > > This is reuqested by Ibrahim Tachijian
> >> > > >
> >> > > > Signed-off-by: LiuQi <liuqi@gosun.com>
> >> > > > ---
> >> > > >  libavformat/hlsenc.c | 14 +++++++++++++-
> >> > > >  1 file changed, 13 insertions(+), 1 deletion(-)
> >> > > >
> >> > > > diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> >> > > > index e65f002..f5ceb60 100644
> >> > > > --- a/libavformat/hlsenc.c
> >> > > > +++ b/libavformat/hlsenc.c
> >> > > > @@ -85,6 +85,7 @@ typedef struct HLSContext {
> >> > > >      AVFormatContext *vtt_avf;
> >> > > >
> >> > > >      float time;            // Set by a private option.
> >> > > > +    float init_time;            // Set by a private option.
> >> > > >      int max_nb_segments;   // Set by a private option.
> >> > > >      int  wrap;             // Set by a private option.
> >> > >
> >> > > the comment looks oddly aligned, it should be at the same horizontal
> >> > > position as teh others
> >> > >
> >> > >
> >> > > >      uint32_t flags;        // enum HLSFlags
> >> > > > @@ -706,7 +707,7 @@ static int hls_write_header(AVFormatContext *s)
> >> > > >      int vtt_basename_size;
> >> > > >
> >> > > >      hls->sequence       = hls->start_sequence;
> >> > > > -    hls->recording_time = hls->time * AV_TIME_BASE;
> >> > > > +    hls->recording_time = (hls->init_time ? hls->init_time :
> >> hls->time)
> >> > > * AV_TIME_BASE;
> >> > > >      hls->start_pts      = AV_NOPTS_VALUE;
> >> > > >
> >> > > >      if (hls->format_options_str) {
> >> > > > @@ -860,9 +861,19 @@ static int hls_write_packet(AVFormatContext
> >> *s,
> >> > > AVPacket *pkt)
> >> > > >      AVStream *st = s->streams[pkt->stream_index];
> >> > > >      int64_t end_pts = hls->recording_time * hls->number;
> >> > > >      int is_ref_pkt = 1;
> >> > >
> >> > > > +    int init_list_dur = 0;
> >> > > > +    int after_init_list_dur = 0;
> >> > >
> >> > > the initialized value is not used
> >> > > also the declaration can be moved into the if() below
> >> > >
> >> > > >      int ret, can_split = 1;
> >> > > >      int stream_index = 0;
> >> > > >
> >> > > > +    if (hls->sequence - hls->nb_entries > hls->start_sequence &&
> >> > > hls->init_time > 0) {
> >> > > > +        /* reset end_pts, hls->recording_time at end of the init
> >> hls
> >> > > list */
> >> > > > +        init_list_dur = hls->init_time * hls->nb_entries *
> >> AV_TIME_BASE;
> >> > > > +        after_init_list_dur = (hls->sequence - hls->nb_entries ) *
> >> > > hls->time * AV_TIME_BASE;
> >> > > > +        hls->recording_time = hls->time * AV_TIME_BASE;
> >> > > > +        end_pts = init_list_dur + after_init_list_dur ;
> >> > > > +    }
> >> > > > +
> >> > > >      if( st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE ) {
> >> > > >          oc = hls->vtt_avf;
> >> > > >          stream_index = 0;
> >> > > > @@ -972,6 +983,7 @@ static int hls_write_trailer(struct
> >> AVFormatContext
> >> > > *s)
> >> > > [...]
> >> > >
> >> > >
> >> > > --
> >> > > Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC7
> >> 87040B0FAB
> >> > >
> >> > > Let us carefully observe those good qualities wherein our enemies
> >> excel us
> >> > > and endeavor to excel them, by avoiding what is faulty, and imitating
> >> what
> >> > > is excellent in them. -- Plutarch
> >> > >
> >> > > _______________________________________________
> >> > > ffmpeg-devel mailing list
> >> > > ffmpeg-devel@ffmpeg.org
> >> > > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >> > >
> >> > > Update patch
> >>
> >> >  hlsenc.c |   14 +++++++++++++-
> >> >  1 file changed, 13 insertions(+), 1 deletion(-)
> >> > 2feb683487b70430f2ea423d2678d7f30d0c3079
> >> 0001-add-option-hls_init_time-to-set-init-hls-window-segm.patch
> >> > From dfadb857714867613afebe1a740a8e7fccaa5443 Mon Sep 17 00:00:00 2001
> >> > From: Steven Liu <lingjiujianke@gmail.com>
> >> > Date: Sat, 27 Aug 2016 07:32:40 +0800
> >> > Subject: [PATCH 1/2] add option hls_init_time to set init hls window
> >> segment
> >> >  duration
> >> >
> >> > recover segments duration time by hls_time after init hls window.
> >> > This is reuqested by Ibrahim Tachijian
> >> >
> >> > Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
> >> > Signed-off-by: LiuQi <liuqi@gosun.com>
> >> > ---
> >> >  libavformat/hlsenc.c | 14 +++++++++++++-
> >> >  1 file changed, 13 insertions(+), 1 deletion(-)
> >> >
> >> > diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> >> > index e65f002..95da86c 100644
> >> > --- a/libavformat/hlsenc.c
> >> > +++ b/libavformat/hlsenc.c
> >> > @@ -85,6 +85,7 @@ typedef struct HLSContext {
> >> >      AVFormatContext *vtt_avf;
> >> >
> >> >      float time;            // Set by a private option.
> >> > +    float init_time;       // Set by a private option.
> >> >      int max_nb_segments;   // Set by a private option.
> >> >      int  wrap;             // Set by a private option.
> >> >      uint32_t flags;        // enum HLSFlags
> >> > @@ -706,7 +707,7 @@ static int hls_write_header(AVFormatContext *s)
> >> >      int vtt_basename_size;
> >> >
> >> >      hls->sequence       = hls->start_sequence;
> >> > -    hls->recording_time = hls->time * AV_TIME_BASE;
> >> > +    hls->recording_time = (hls->init_time ? hls->init_time :
> >> hls->time) * AV_TIME_BASE;
> >> >      hls->start_pts      = AV_NOPTS_VALUE;
> >> >
> >> >      if (hls->format_options_str) {
> >>
> >> > @@ -863,6 +864,16 @@ static int hls_write_packet(AVFormatContext *s,
> >> AVPacket *pkt)
> >> >      int ret, can_split = 1;
> >> >      int stream_index = 0;
> >> >
> >> > +    if (hls->sequence - hls->nb_entries > hls->start_sequence &&
> >> hls->init_time > 0) {
> >> > +        int init_list_dur = 0;
> >> > +        int after_init_list_dur = 0;
> >> > +        /* reset end_pts, hls->recording_time at end of the init hls
> >> list */
> >> > +        init_list_dur = hls->init_time * hls->nb_entries *
> >> AV_TIME_BASE;
> >> > +        after_init_list_dur = (hls->sequence - hls->nb_entries ) *
> >> hls->time * AV_TIME_BASE;
> >>
> >> the first assignment does nothing
> >> int a = 0;
> >> a = 5;
> >> is the same as
> >> int a = 5
> >>
> >> [...]
> >>
> >> --
> >> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> >>
> >> Breaking DRM is a little like attempting to break through a door even
> >> though the window is wide open and the only thing in the house is a bunch
> >> of things you dont want and which you would get tomorrow for free anyway
> >>
> >> _______________________________________________
> >> ffmpeg-devel mailing list
> >> ffmpeg-devel@ffmpeg.org
> >> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >>
> >> refined the patch and update patch by Michael's suggestion
> >
> Ignore prev patch, this is update patch: Update commit Author

>  hlsenc.c |   12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 7bd461c0aa903c61e2c24ab039599559366a3bbf  0001-add-option-hls_init_time-to-set-init-hls-window-segm.patch
> From a5ae310a049c3a4c0531c5700246ace62261798a Mon Sep 17 00:00:00 2001
> From: Steven Liu <lingjiujianke@gmail.com>
> Date: Sat, 27 Aug 2016 19:11:14 +0800
> Subject: [PATCH 1/2] add option hls_init_time to set init hls window segment
>  duration
> 
> recover segments duration time by hls_time after init hls window.
> This is reuqested by Ibrahim Tachijian
> 
> Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>

applied

thx

[...]
diff mbox

Patch

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index e65f002..f5ceb60 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -85,6 +85,7 @@  typedef struct HLSContext {
     AVFormatContext *vtt_avf;

     float time;            // Set by a private option.
+    float init_time;            // Set by a private option.
     int max_nb_segments;   // Set by a private option.
     int  wrap;             // Set by a private option.
     uint32_t flags;        // enum HLSFlags
@@ -706,7 +707,7 @@  static int hls_write_header(AVFormatContext *s)
     int vtt_basename_size;

     hls->sequence       = hls->start_sequence;
-    hls->recording_time = hls->time * AV_TIME_BASE;
+    hls->recording_time = (hls->init_time ? hls->init_time : hls->time) *
AV_TIME_BASE;
     hls->start_pts      = AV_NOPTS_VALUE;