[FFmpeg-devel] avformat/hlsenc: add option hls_out_list_size

Submitted by Steven Liu on April 10, 2018, 8:28 a.m.

Details

Message ID 20180410082826.10169-1-lq@chinaffmpeg.org
State New
Headers show

Commit Message

Steven Liu April 10, 2018, 8:28 a.m.
when use hls_list_size and hls_flags delete_segments, there will saving
hls_list_size * 2 +- segments, so this option can control the segments
numbers.

fix ticket: #7131

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
---
 doc/muxers.texi      |  4 ++++
 libavformat/hlsenc.c | 13 +++++++++++++
 2 files changed, 17 insertions(+)

Comments

Aman Gupta April 10, 2018, 3:41 p.m.
On Tue, Apr 10, 2018 at 1:28 AM, Steven Liu <lq@chinaffmpeg.org> wrote:

> when use hls_list_size and hls_flags delete_segments, there will saving
> hls_list_size * 2 +- segments, so this option can control the segments
> numbers.
>
> fix ticket: #7131
>
> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
> ---
>  doc/muxers.texi      |  4 ++++
>  libavformat/hlsenc.c | 13 +++++++++++++
>  2 files changed, 17 insertions(+)
>
> diff --git a/doc/muxers.texi b/doc/muxers.texi
> index cb75c261c5..21ef786bcf 100644
> --- a/doc/muxers.texi
> +++ b/doc/muxers.texi
> @@ -513,6 +513,10 @@ Segment will be cut on the next key frame after this
> time has passed.
>  Set the maximum number of playlist entries. If set to 0 the list file
>  will contain all the segments. Default value is 5.
>
> +@item hls_out_list_size @var{size}
> +Set the maximum number out of playlist entries. Default value is 1.
> +This option should be used with @code{hls_flags delete_segments}.
>

I don't understand why a new option is required. Why can't the value of
hls_list_size be re-used?


> +
>  @item hls_ts_options @var{options_list}
>  Set output format options using a :-separated list of key=value
>  parameters. Values containing @code{:} special characters must be
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 2a54b4342e..ff4c88d798 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -171,6 +171,7 @@ typedef struct HLSContext {
>      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 hls_out_list_size; // Set by a private option.
>  #if FF_API_HLS_WRAP
>      int  wrap;             // Set by a private option.
>  #endif
> @@ -443,6 +444,7 @@ static int hls_delete_old_segments(AVFormatContext
> *s, HLSContext *hls,
>      HLSSegment *segment, *previous_segment = NULL;
>      float playlist_duration = 0.0f;
>      int ret = 0, path_size, sub_path_size;
> +    int segment_cnt = 0;
>      char *dirname = NULL, *p, *sub_path;
>      char *path = NULL;
>      AVDictionary *options = NULL;
> @@ -456,14 +458,24 @@ static int hls_delete_old_segments(AVFormatContext
> *s, HLSContext *hls,
>      }
>
>      segment = vs->old_segments;
> +    segment_cnt = 0;
>      while (segment) {
>          playlist_duration -= segment->duration;
>          previous_segment = segment;
>          segment = previous_segment->next;
> +        segment_cnt++;
>          if (playlist_duration <= -previous_segment->duration) {
>              previous_segment->next = NULL;
>              break;
>          }
> +
> +        if (!hls->hls_out_list_size) {
> +            av_log(s, AV_LOG_WARNING, "the hls_out_list_size value is 0,
> that's wrong, so turn it to default value 1.\n");
>

If 0 is invalid value, it should be disallowed instead of showing a warning.


> +        }
> +        if (segment_cnt >= hls->hls_out_list_size) {
> +            previous_segment->next = NULL;
> +            break;
> +        }
>      }
>
>      if (segment && !hls->use_localtime_mkdir) {
> @@ -2779,6 +2791,7 @@ static const AVOption options[] = {
>      {"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_out_list_size", "set maximum number of out to playlist
> entries",  OFFSET(hls_out_list_size),    AV_OPT_TYPE_INT,    {.i64 = 1},
>  0, INT_MAX, E},
>

I think you can change this to 1, INT_MAX to disallow 0 values.


>      {"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},
>  #if FF_API_HLS_WRAP
> --
> 2.15.1
>
>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
Bodecs Bela April 10, 2018, 4:49 p.m.
2018.04.10. 17:41 keltezéssel, Aman Gupta írta:
> On Tue, Apr 10, 2018 at 1:28 AM, Steven Liu <lq@chinaffmpeg.org> wrote:
>
>> when use hls_list_size and hls_flags delete_segments, there will saving
>> hls_list_size * 2 +- segments, so this option can control the segments
>> numbers.
>>
>> fix ticket: #7131
>>
>> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
>> ---
>>   doc/muxers.texi      |  4 ++++
>>   libavformat/hlsenc.c | 13 +++++++++++++
>>   2 files changed, 17 insertions(+)
>>
>> diff --git a/doc/muxers.texi b/doc/muxers.texi
>> index cb75c261c5..21ef786bcf 100644
>> --- a/doc/muxers.texi
>> +++ b/doc/muxers.texi
>> @@ -513,6 +513,10 @@ Segment will be cut on the next key frame after this
>> time has passed.
>>   Set the maximum number of playlist entries. If set to 0 the list file
>>   will contain all the segments. Default value is 5.
>>
>> +@item hls_out_list_size @var{size}
>> +Set the maximum number out of playlist entries. Default value is 1.
>> +This option should be used with @code{hls_flags delete_segments}.
>>
> I don't understand why a new option is required. Why can't the value of
> hls_list_size be re-used?
as I understand this is a totally different option:
nb_existing_segments = hls_list_size + hls_out_list_size
currently:
nb_existing_segments = hls_list_size + 1

I think this is a usefull new option. e.g. when network speed is very 
fluctuating and your client want to save all the segments.

>
>
>> +
>>   @item hls_ts_options @var{options_list}
>>   Set output format options using a :-separated list of key=value
>>   parameters. Values containing @code{:} special characters must be
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index 2a54b4342e..ff4c88d798 100644
>> --- a/libavformat/hlsenc.c
>> +++ b/libavformat/hlsenc.c
>> @@ -171,6 +171,7 @@ typedef struct HLSContext {
>>       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 hls_out_list_size; // Set by a private option.
>>   #if FF_API_HLS_WRAP
>>       int  wrap;             // Set by a private option.
>>   #endif
>> @@ -443,6 +444,7 @@ static int hls_delete_old_segments(AVFormatContext
>> *s, HLSContext *hls,
>>       HLSSegment *segment, *previous_segment = NULL;
>>       float playlist_duration = 0.0f;
>>       int ret = 0, path_size, sub_path_size;
>> +    int segment_cnt = 0;
>>       char *dirname = NULL, *p, *sub_path;
>>       char *path = NULL;
>>       AVDictionary *options = NULL;
>> @@ -456,14 +458,24 @@ static int hls_delete_old_segments(AVFormatContext
>> *s, HLSContext *hls,
>>       }
>>
>>       segment = vs->old_segments;
>> +    segment_cnt = 0;
>>       while (segment) {
>>           playlist_duration -= segment->duration;
>>           previous_segment = segment;
>>           segment = previous_segment->next;
>> +        segment_cnt++;
>>           if (playlist_duration <= -previous_segment->duration) {
>>               previous_segment->next = NULL;
>>               break;
>>           }
>> +
>> +        if (!hls->hls_out_list_size) {
>> +            av_log(s, AV_LOG_WARNING, "the hls_out_list_size value is 0,
>> that's wrong, so turn it to default value 1.\n");
>>
> If 0 is invalid value, it should be disallowed instead of showing a warning.
>
>
>> +        }
>> +        if (segment_cnt >= hls->hls_out_list_size) {
>> +            previous_segment->next = NULL;
>> +            break;
>> +        }
>>       }
>>
>>       if (segment && !hls->use_localtime_mkdir) {
>> @@ -2779,6 +2791,7 @@ static const AVOption options[] = {
>>       {"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_out_list_size", "set maximum number of out to playlist
>> entries",  OFFSET(hls_out_list_size),    AV_OPT_TYPE_INT,    {.i64 = 1},
>>   0, INT_MAX, E},
>>
> I think you can change this to 1, INT_MAX to disallow 0 values.
>
>
>>       {"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},
>>   #if FF_API_HLS_WRAP
>> --
>> 2.15.1
>>
>>
>>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Aman Gupta April 10, 2018, 5:23 p.m.
On Tue, Apr 10, 2018 at 9:49 AM, Bodecs Bela <bodecsb@vivanet.hu> wrote:

>
>
> 2018.04.10. 17:41 keltezéssel, Aman Gupta írta:
>
>> On Tue, Apr 10, 2018 at 1:28 AM, Steven Liu <lq@chinaffmpeg.org> wrote:
>>
>> when use hls_list_size and hls_flags delete_segments, there will saving
>>> hls_list_size * 2 +- segments, so this option can control the segments
>>> numbers.
>>>
>>> fix ticket: #7131
>>>
>>> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
>>> ---
>>>   doc/muxers.texi      |  4 ++++
>>>   libavformat/hlsenc.c | 13 +++++++++++++
>>>   2 files changed, 17 insertions(+)
>>>
>>> diff --git a/doc/muxers.texi b/doc/muxers.texi
>>> index cb75c261c5..21ef786bcf 100644
>>> --- a/doc/muxers.texi
>>> +++ b/doc/muxers.texi
>>> @@ -513,6 +513,10 @@ Segment will be cut on the next key frame after this
>>> time has passed.
>>>   Set the maximum number of playlist entries. If set to 0 the list file
>>>   will contain all the segments. Default value is 5.
>>>
>>> +@item hls_out_list_size @var{size}
>>> +Set the maximum number out of playlist entries. Default value is 1.
>>> +This option should be used with @code{hls_flags delete_segments}.
>>>
>>> I don't understand why a new option is required. Why can't the value of
>> hls_list_size be re-used?
>>
> as I understand this is a totally different option:
> nb_existing_segments = hls_list_size + hls_out_list_size
> currently:
> nb_existing_segments = hls_list_size + 1
>

According to #7131, the current behavior is to keep hls_list_size*2 + 1
segments on disk.


>
> I think this is a usefull new option. e.g. when network speed is very
> fluctuating and your client want to save all the segments.


I don't follow.. if the m3u8 only advertises the last hls_list_size
segments, then why does keeping the older ones help? How would the client
even know they exist?

Aman


>
>
>
>>
>> +
>>>   @item hls_ts_options @var{options_list}
>>>   Set output format options using a :-separated list of key=value
>>>   parameters. Values containing @code{:} special characters must be
>>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>>> index 2a54b4342e..ff4c88d798 100644
>>> --- a/libavformat/hlsenc.c
>>> +++ b/libavformat/hlsenc.c
>>> @@ -171,6 +171,7 @@ typedef struct HLSContext {
>>>       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 hls_out_list_size; // Set by a private option.
>>>   #if FF_API_HLS_WRAP
>>>       int  wrap;             // Set by a private option.
>>>   #endif
>>> @@ -443,6 +444,7 @@ static int hls_delete_old_segments(AVFormatContext
>>> *s, HLSContext *hls,
>>>       HLSSegment *segment, *previous_segment = NULL;
>>>       float playlist_duration = 0.0f;
>>>       int ret = 0, path_size, sub_path_size;
>>> +    int segment_cnt = 0;
>>>       char *dirname = NULL, *p, *sub_path;
>>>       char *path = NULL;
>>>       AVDictionary *options = NULL;
>>> @@ -456,14 +458,24 @@ static int hls_delete_old_segments(AVFormatContext
>>> *s, HLSContext *hls,
>>>       }
>>>
>>>       segment = vs->old_segments;
>>> +    segment_cnt = 0;
>>>       while (segment) {
>>>           playlist_duration -= segment->duration;
>>>           previous_segment = segment;
>>>           segment = previous_segment->next;
>>> +        segment_cnt++;
>>>           if (playlist_duration <= -previous_segment->duration) {
>>>               previous_segment->next = NULL;
>>>               break;
>>>           }
>>> +
>>> +        if (!hls->hls_out_list_size) {
>>> +            av_log(s, AV_LOG_WARNING, "the hls_out_list_size value is 0,
>>> that's wrong, so turn it to default value 1.\n");
>>>
>>> If 0 is invalid value, it should be disallowed instead of showing a
>> warning.
>>
>>
>> +        }
>>> +        if (segment_cnt >= hls->hls_out_list_size) {
>>> +            previous_segment->next = NULL;
>>> +            break;
>>> +        }
>>>       }
>>>
>>>       if (segment && !hls->use_localtime_mkdir) {
>>> @@ -2779,6 +2791,7 @@ static const AVOption options[] = {
>>>       {"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_out_list_size", "set maximum number of out to playlist
>>> entries",  OFFSET(hls_out_list_size),    AV_OPT_TYPE_INT,    {.i64 = 1},
>>>   0, INT_MAX, E},
>>>
>>> I think you can change this to 1, INT_MAX to disallow 0 values.
>>
>>
>>       {"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},
>>>   #if FF_API_HLS_WRAP
>>> --
>>> 2.15.1
>>>
>>>
>>>
>>> _______________________________________________
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel@ffmpeg.org
>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>>
>>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
Bodecs Bela April 10, 2018, 5:36 p.m.
2018.04.10. 19:23 keltezéssel, Aman Gupta írta:
> On Tue, Apr 10, 2018 at 9:49 AM, Bodecs Bela <bodecsb@vivanet.hu> wrote:
>
>>
>> 2018.04.10. 17:41 keltezéssel, Aman Gupta írta:
>>
>>> On Tue, Apr 10, 2018 at 1:28 AM, Steven Liu <lq@chinaffmpeg.org> wrote:
>>>
>>> when use hls_list_size and hls_flags delete_segments, there will saving
>>>> hls_list_size * 2 +- segments, so this option can control the segments
>>>> numbers.
>>>>
>>>> fix ticket: #7131
>>>>
>>>> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
>>>> ---
>>>>    doc/muxers.texi      |  4 ++++
>>>>    libavformat/hlsenc.c | 13 +++++++++++++
>>>>    2 files changed, 17 insertions(+)
>>>>
>>>> diff --git a/doc/muxers.texi b/doc/muxers.texi
>>>> index cb75c261c5..21ef786bcf 100644
>>>> --- a/doc/muxers.texi
>>>> +++ b/doc/muxers.texi
>>>> @@ -513,6 +513,10 @@ Segment will be cut on the next key frame after this
>>>> time has passed.
>>>>    Set the maximum number of playlist entries. If set to 0 the list file
>>>>    will contain all the segments. Default value is 5.
>>>>
>>>> +@item hls_out_list_size @var{size}
>>>> +Set the maximum number out of playlist entries. Default value is 1.
>>>> +This option should be used with @code{hls_flags delete_segments}.
>>>>
>>>> I don't understand why a new option is required. Why can't the value of
>>> hls_list_size be re-used?
>>>
>> as I understand this is a totally different option:
>> nb_existing_segments = hls_list_size + hls_out_list_size
>> currently:
>> nb_existing_segments = hls_list_size + 1
>>
> According to #7131, the current behavior is to keep hls_list_size*2 + 1
> segments on disk.
sorry, you are right.
>
>> I think this is a usefull new option. e.g. when network speed is very
>> fluctuating and your client want to save all the segments.
>
> I don't follow.. if the m3u8 only advertises the last hls_list_size
> segments, then why does keeping the older ones help? How would the client
> even know they exist?
a currently joining client of course won't be aware about the earlier 
but still available segments,
but a client, joinig eearlier and continouosly following m3u8 but 
temporarily having slower than realtime net connection speed
may have benefit to successfully download these earlier segments.

it is not so usefull when realtime displaying the live stream, but it is 
usefull if you archive the live stream.

bb

>
> Aman
>
>
>>
>>
>>> +
>>>>    @item hls_ts_options @var{options_list}
>>>>    Set output format options using a :-separated list of key=value
>>>>    parameters. Values containing @code{:} special characters must be
>>>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>>>> index 2a54b4342e..ff4c88d798 100644
>>>> --- a/libavformat/hlsenc.c
>>>> +++ b/libavformat/hlsenc.c
>>>> @@ -171,6 +171,7 @@ typedef struct HLSContext {
>>>>        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 hls_out_list_size; // Set by a private option.
>>>>    #if FF_API_HLS_WRAP
>>>>        int  wrap;             // Set by a private option.
>>>>    #endif
>>>> @@ -443,6 +444,7 @@ static int hls_delete_old_segments(AVFormatContext
>>>> *s, HLSContext *hls,
>>>>        HLSSegment *segment, *previous_segment = NULL;
>>>>        float playlist_duration = 0.0f;
>>>>        int ret = 0, path_size, sub_path_size;
>>>> +    int segment_cnt = 0;
>>>>        char *dirname = NULL, *p, *sub_path;
>>>>        char *path = NULL;
>>>>        AVDictionary *options = NULL;
>>>> @@ -456,14 +458,24 @@ static int hls_delete_old_segments(AVFormatContext
>>>> *s, HLSContext *hls,
>>>>        }
>>>>
>>>>        segment = vs->old_segments;
>>>> +    segment_cnt = 0;
>>>>        while (segment) {
>>>>            playlist_duration -= segment->duration;
>>>>            previous_segment = segment;
>>>>            segment = previous_segment->next;
>>>> +        segment_cnt++;
>>>>            if (playlist_duration <= -previous_segment->duration) {
>>>>                previous_segment->next = NULL;
>>>>                break;
>>>>            }
>>>> +
>>>> +        if (!hls->hls_out_list_size) {
>>>> +            av_log(s, AV_LOG_WARNING, "the hls_out_list_size value is 0,
>>>> that's wrong, so turn it to default value 1.\n");
>>>>
>>>> If 0 is invalid value, it should be disallowed instead of showing a
>>> warning.
>>>
>>>
>>> +        }
>>>> +        if (segment_cnt >= hls->hls_out_list_size) {
>>>> +            previous_segment->next = NULL;
>>>> +            break;
>>>> +        }
>>>>        }
>>>>
>>>>        if (segment && !hls->use_localtime_mkdir) {
>>>> @@ -2779,6 +2791,7 @@ static const AVOption options[] = {
>>>>        {"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_out_list_size", "set maximum number of out to playlist
>>>> entries",  OFFSET(hls_out_list_size),    AV_OPT_TYPE_INT,    {.i64 = 1},
>>>>    0, INT_MAX, E},
>>>>
>>>> I think you can change this to 1, INT_MAX to disallow 0 values.
>>>
>>>        {"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},
>>>>    #if FF_API_HLS_WRAP
>>>> --
>>>> 2.15.1
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> ffmpeg-devel mailing list
>>>> ffmpeg-devel@ffmpeg.org
>>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>>>
>>>> _______________________________________________
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel@ffmpeg.org
>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Aman Gupta April 10, 2018, 5:41 p.m.
On Tue, Apr 10, 2018 at 10:36 AM, Bodecs Bela <bodecsb@vivanet.hu> wrote:

>
>
> 2018.04.10. 19:23 keltezéssel, Aman Gupta írta:
>
>> On Tue, Apr 10, 2018 at 9:49 AM, Bodecs Bela <bodecsb@vivanet.hu> wrote:
>>
>>
>>> 2018.04.10. 17:41 keltezéssel, Aman Gupta írta:
>>>
>>> On Tue, Apr 10, 2018 at 1:28 AM, Steven Liu <lq@chinaffmpeg.org> wrote:
>>>>
>>>> when use hls_list_size and hls_flags delete_segments, there will saving
>>>>
>>>>> hls_list_size * 2 +- segments, so this option can control the segments
>>>>> numbers.
>>>>>
>>>>> fix ticket: #7131
>>>>>
>>>>> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
>>>>> ---
>>>>>    doc/muxers.texi      |  4 ++++
>>>>>    libavformat/hlsenc.c | 13 +++++++++++++
>>>>>    2 files changed, 17 insertions(+)
>>>>>
>>>>> diff --git a/doc/muxers.texi b/doc/muxers.texi
>>>>> index cb75c261c5..21ef786bcf 100644
>>>>> --- a/doc/muxers.texi
>>>>> +++ b/doc/muxers.texi
>>>>> @@ -513,6 +513,10 @@ Segment will be cut on the next key frame after
>>>>> this
>>>>> time has passed.
>>>>>    Set the maximum number of playlist entries. If set to 0 the list
>>>>> file
>>>>>    will contain all the segments. Default value is 5.
>>>>>
>>>>> +@item hls_out_list_size @var{size}
>>>>> +Set the maximum number out of playlist entries. Default value is 1.
>>>>> +This option should be used with @code{hls_flags delete_segments}.
>>>>>
>>>>> I don't understand why a new option is required. Why can't the value of
>>>>>
>>>> hls_list_size be re-used?
>>>>
>>>> as I understand this is a totally different option:
>>> nb_existing_segments = hls_list_size + hls_out_list_size
>>> currently:
>>> nb_existing_segments = hls_list_size + 1
>>>
>>> According to #7131, the current behavior is to keep hls_list_size*2 + 1
>> segments on disk.
>>
> sorry, you are right.
>
>>
>> I think this is a usefull new option. e.g. when network speed is very
>>> fluctuating and your client want to save all the segments.
>>>
>>
>> I don't follow.. if the m3u8 only advertises the last hls_list_size
>> segments, then why does keeping the older ones help? How would the client
>> even know they exist?
>>
> a currently joining client of course won't be aware about the earlier but
> still available segments,
> but a client, joinig eearlier and continouosly following m3u8 but
> temporarily having slower than realtime net connection speed
> may have benefit to successfully download these earlier segments.
>

Okay I understand now. You're right, this is a valid use-case. Thanks for
the clarification.

Aman


>
> it is not so usefull when realtime displaying the live stream, but it is
> usefull if you archive the live stream.
>
> bb
>
>
>
>> Aman
>>
>>
>>
>>>
>>> +
>>>>
>>>>>    @item hls_ts_options @var{options_list}
>>>>>    Set output format options using a :-separated list of key=value
>>>>>    parameters. Values containing @code{:} special characters must be
>>>>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>>>>> index 2a54b4342e..ff4c88d798 100644
>>>>> --- a/libavformat/hlsenc.c
>>>>> +++ b/libavformat/hlsenc.c
>>>>> @@ -171,6 +171,7 @@ typedef struct HLSContext {
>>>>>        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 hls_out_list_size; // Set by a private option.
>>>>>    #if FF_API_HLS_WRAP
>>>>>        int  wrap;             // Set by a private option.
>>>>>    #endif
>>>>> @@ -443,6 +444,7 @@ static int hls_delete_old_segments(AVFormatContext
>>>>> *s, HLSContext *hls,
>>>>>        HLSSegment *segment, *previous_segment = NULL;
>>>>>        float playlist_duration = 0.0f;
>>>>>        int ret = 0, path_size, sub_path_size;
>>>>> +    int segment_cnt = 0;
>>>>>        char *dirname = NULL, *p, *sub_path;
>>>>>        char *path = NULL;
>>>>>        AVDictionary *options = NULL;
>>>>> @@ -456,14 +458,24 @@ static int hls_delete_old_segments(AVForm
>>>>> atContext
>>>>> *s, HLSContext *hls,
>>>>>        }
>>>>>
>>>>>        segment = vs->old_segments;
>>>>> +    segment_cnt = 0;
>>>>>        while (segment) {
>>>>>            playlist_duration -= segment->duration;
>>>>>            previous_segment = segment;
>>>>>            segment = previous_segment->next;
>>>>> +        segment_cnt++;
>>>>>            if (playlist_duration <= -previous_segment->duration) {
>>>>>                previous_segment->next = NULL;
>>>>>                break;
>>>>>            }
>>>>> +
>>>>> +        if (!hls->hls_out_list_size) {
>>>>> +            av_log(s, AV_LOG_WARNING, "the hls_out_list_size value is
>>>>> 0,
>>>>> that's wrong, so turn it to default value 1.\n");
>>>>>
>>>>> If 0 is invalid value, it should be disallowed instead of showing a
>>>>>
>>>> warning.
>>>>
>>>>
>>>> +        }
>>>>
>>>>> +        if (segment_cnt >= hls->hls_out_list_size) {
>>>>> +            previous_segment->next = NULL;
>>>>> +            break;
>>>>> +        }
>>>>>        }
>>>>>
>>>>>        if (segment && !hls->use_localtime_mkdir) {
>>>>> @@ -2779,6 +2791,7 @@ static const AVOption options[] = {
>>>>>        {"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_out_list_size", "set maximum number of out to playlist
>>>>> entries",  OFFSET(hls_out_list_size),    AV_OPT_TYPE_INT,    {.i64 =
>>>>> 1},
>>>>>    0, INT_MAX, E},
>>>>>
>>>>> I think you can change this to 1, INT_MAX to disallow 0 values.
>>>>>
>>>>
>>>>        {"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},
>>>>>    #if FF_API_HLS_WRAP
>>>>> --
>>>>> 2.15.1
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> ffmpeg-devel mailing list
>>>>> ffmpeg-devel@ffmpeg.org
>>>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>>>>
>>>>> _______________________________________________
>>>>>
>>>> ffmpeg-devel mailing list
>>>> ffmpeg-devel@ffmpeg.org
>>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>>>
>>>> _______________________________________________
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel@ffmpeg.org
>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>>
>>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

Patch hide | download patch | download mbox

diff --git a/doc/muxers.texi b/doc/muxers.texi
index cb75c261c5..21ef786bcf 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -513,6 +513,10 @@  Segment will be cut on the next key frame after this time has passed.
 Set the maximum number of playlist entries. If set to 0 the list file
 will contain all the segments. Default value is 5.
 
+@item hls_out_list_size @var{size}
+Set the maximum number out of playlist entries. Default value is 1.
+This option should be used with @code{hls_flags delete_segments}.
+
 @item hls_ts_options @var{options_list}
 Set output format options using a :-separated list of key=value
 parameters. Values containing @code{:} special characters must be
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 2a54b4342e..ff4c88d798 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -171,6 +171,7 @@  typedef struct HLSContext {
     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 hls_out_list_size; // Set by a private option.
 #if FF_API_HLS_WRAP
     int  wrap;             // Set by a private option.
 #endif
@@ -443,6 +444,7 @@  static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
     HLSSegment *segment, *previous_segment = NULL;
     float playlist_duration = 0.0f;
     int ret = 0, path_size, sub_path_size;
+    int segment_cnt = 0;
     char *dirname = NULL, *p, *sub_path;
     char *path = NULL;
     AVDictionary *options = NULL;
@@ -456,14 +458,24 @@  static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
     }
 
     segment = vs->old_segments;
+    segment_cnt = 0;
     while (segment) {
         playlist_duration -= segment->duration;
         previous_segment = segment;
         segment = previous_segment->next;
+        segment_cnt++;
         if (playlist_duration <= -previous_segment->duration) {
             previous_segment->next = NULL;
             break;
         }
+
+        if (!hls->hls_out_list_size) {
+            av_log(s, AV_LOG_WARNING, "the hls_out_list_size value is 0, that's wrong, so turn it to default value 1.\n");
+        }
+        if (segment_cnt >= hls->hls_out_list_size) {
+            previous_segment->next = NULL;
+            break;
+        }
     }
 
     if (segment && !hls->use_localtime_mkdir) {
@@ -2779,6 +2791,7 @@  static const AVOption options[] = {
     {"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_out_list_size", "set maximum number of out to playlist entries",  OFFSET(hls_out_list_size),    AV_OPT_TYPE_INT,    {.i64 = 1},     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},
 #if FF_API_HLS_WRAP