diff mbox series

[FFmpeg-devel,5/5] avformat/hlsenc: use AV_OPT_TYPE_DURATION

Message ID 1609947331-6849-5-git-send-email-lance.lmwang@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,1/5] avformat/udp: add memory alloc checks | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Lance Wang Jan. 6, 2021, 3:35 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 doc/muxers.texi      |  4 ++--
 libavformat/hlsenc.c | 18 +++++++++---------
 2 files changed, 11 insertions(+), 11 deletions(-)

Comments

Lance Wang Jan. 14, 2021, 3 p.m. UTC | #1
ping

On Wed, Jan 06, 2021 at 11:35:31PM +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  doc/muxers.texi      |  4 ++--
>  libavformat/hlsenc.c | 18 +++++++++---------
>  2 files changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/doc/muxers.texi b/doc/muxers.texi
> index 8e12aca..044c16b 100644
> --- a/doc/muxers.texi
> +++ b/doc/muxers.texi
> @@ -609,13 +609,13 @@ segmentation.
>  This muxer supports the following options:
>  
>  @table @option
> -@item hls_init_time @var{seconds}
> +@item hls_init_time @var{duration}
>  Set the initial target segment length in seconds. Default value is @var{0}.
>  Segment will be cut on the next key frame after this time has passed on the first m3u8 list.
>  After the initial playlist is filled @command{ffmpeg} will cut segments
>  at duration equal to @code{hls_time}
>  
> -@item hls_time @var{seconds}
> +@item hls_time @var{duration}
>  Set the target segment length in seconds. Default value is 2.
>  Segment will be cut on the next key frame after this time has passed.
>  
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 7f38db7..021a1ea 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -196,8 +196,8 @@ typedef struct HLSContext {
>      int64_t start_sequence;
>      uint32_t start_sequence_source_type;  // enum StartSequenceSourceType
>  
> -    float time;            // Set by a private option.
> -    float init_time;       // Set by a private option.
> +    int64_t time;          // Set by a private option.
> +    int64_t init_time;     // Set by a private option.
>      int max_nb_segments;   // Set by a private option.
>      int hls_delete_threshold; // Set by a private option.
>  #if FF_API_HLS_WRAP
> @@ -2454,9 +2454,9 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
>  
>      if (vs->sequence - vs->nb_entries > hls->start_sequence && hls->init_time > 0) {
>          /* reset end_pts, hls->recording_time at end of the init hls list */
> -        int64_t init_list_dur = hls->init_time * vs->nb_entries * AV_TIME_BASE;
> -        int64_t after_init_list_dur = (vs->sequence - hls->start_sequence - vs->nb_entries) * (hls->time * AV_TIME_BASE);
> -        hls->recording_time = hls->time * AV_TIME_BASE;
> +        int64_t init_list_dur = hls->init_time * vs->nb_entries;
> +        int64_t after_init_list_dur = (vs->sequence - hls->start_sequence - vs->nb_entries) * hls->time;
> +        hls->recording_time = hls->time;
>          end_pts = init_list_dur + after_init_list_dur ;
>      }
>  
> @@ -2941,7 +2941,7 @@ static int hls_init(AVFormatContext *s)
>          av_log(hls, AV_LOG_DEBUG, "start_number evaluated to %"PRId64"\n", hls->start_sequence);
>      }
>  
> -    hls->recording_time = (hls->init_time ? hls->init_time : hls->time) * AV_TIME_BASE;
> +    hls->recording_time = hls->init_time ? hls->init_time : hls->time;
>  
>      if (hls->flags & HLS_SPLIT_BY_TIME && hls->flags & HLS_INDEPENDENT_SEGMENTS) {
>          // Independent segments cannot be guaranteed when splitting by time
> @@ -3094,7 +3094,7 @@ static int hls_init(AVFormatContext *s)
>                  av_log(s, AV_LOG_WARNING, "append_list mode does not support hls_init_time,"
>                         " hls_init_time value will have no effect\n");
>                  hls->init_time = 0;
> -                hls->recording_time = hls->time * AV_TIME_BASE;
> +                hls->recording_time = hls->time;
>              }
>          }
>  
> @@ -3110,8 +3110,8 @@ static int hls_init(AVFormatContext *s)
>  #define E AV_OPT_FLAG_ENCODING_PARAM
>  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_time",      "set segment length in seconds",           OFFSET(time),    AV_OPT_TYPE_DURATION,  {.i64 = 2000000},     0, INT64_MAX, E},
> +    {"hls_init_time", "set segment length in seconds at init list",           OFFSET(init_time),    AV_OPT_TYPE_DURATION,  {.i64 = 0},     0, INT64_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_delete_threshold", "set number of unreferenced segments to keep before deleting",  OFFSET(hls_delete_threshold),    AV_OPT_TYPE_INT,    {.i64 = 1},     1, INT_MAX, E},
>      {"hls_ts_options","set hls mpegts list of options for the container format used for hls", OFFSET(format_options), AV_OPT_TYPE_DICT, {.str = NULL},  0, 0,    E},
> -- 
> 1.8.3.1
>
Moritz Barsnick Jan. 15, 2021, 1:27 p.m. UTC | #2
On Wed, Jan 06, 2021 at 23:35:31 +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
>
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  doc/muxers.texi      |  4 ++--
>  libavformat/hlsenc.c | 18 +++++++++---------
>  2 files changed, 11 insertions(+), 11 deletions(-)
>
> diff --git a/doc/muxers.texi b/doc/muxers.texi
> index 8e12aca..044c16b 100644
> --- a/doc/muxers.texi
> +++ b/doc/muxers.texi
> @@ -609,13 +609,13 @@ segmentation.
>  This muxer supports the following options:
>
>  @table @option
> -@item hls_init_time @var{seconds}
> +@item hls_init_time @var{duration}
>  Set the initial target segment length in seconds. Default value is @var{0}.
>  Segment will be cut on the next key frame after this time has passed on the first m3u8 list.
>  After the initial playlist is filled @command{ffmpeg} will cut segments
>  at duration equal to @code{hls_time}

AV_OPT_TYPE_DURATION is not strictly seconds. It can use other
syntaxes. You could refer to the appropriate section:

> see @ref{time duration syntax,,the Time duration section in the ffmpeg-utils(1) manual,ffmpeg-utils}.


>  Set the target segment length in seconds. Default value is 2.

Ditto.

> -    {"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_time",      "set segment length in seconds",           OFFSET(time),    AV_OPT_TYPE_DURATION,  {.i64 = 2000000},     0, INT64_MAX, E},
> +    {"hls_init_time", "set segment length in seconds at init list",           OFFSET(init_time),    AV_OPT_TYPE_DURATION,  {.i64 = 0},     0, INT64_MAX, E},

Ditto, just "set segment length".

Cheers,
Moritz
Lance Wang Jan. 16, 2021, 12:36 a.m. UTC | #3
On Fri, Jan 15, 2021 at 02:27:44PM +0100, Moritz Barsnick wrote:
> On Wed, Jan 06, 2021 at 23:35:31 +0800, lance.lmwang@gmail.com wrote:
> > From: Limin Wang <lance.lmwang@gmail.com>
> >
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> >  doc/muxers.texi      |  4 ++--
> >  libavformat/hlsenc.c | 18 +++++++++---------
> >  2 files changed, 11 insertions(+), 11 deletions(-)
> >
> > diff --git a/doc/muxers.texi b/doc/muxers.texi
> > index 8e12aca..044c16b 100644
> > --- a/doc/muxers.texi
> > +++ b/doc/muxers.texi
> > @@ -609,13 +609,13 @@ segmentation.
> >  This muxer supports the following options:
> >
> >  @table @option
> > -@item hls_init_time @var{seconds}
> > +@item hls_init_time @var{duration}
> >  Set the initial target segment length in seconds. Default value is @var{0}.
> >  Segment will be cut on the next key frame after this time has passed on the first m3u8 list.
> >  After the initial playlist is filled @command{ffmpeg} will cut segments
> >  at duration equal to @code{hls_time}
> 
> AV_OPT_TYPE_DURATION is not strictly seconds. It can use other
> syntaxes. You could refer to the appropriate section:
> 
> > see @ref{time duration syntax,,the Time duration section in the ffmpeg-utils(1) manual,ffmpeg-utils}.

OK, will add the section for reference if have update.

> 
> 
> >  Set the target segment length in seconds. Default value is 2.
> 
> Ditto.

will fix it.

> 
> > -    {"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_time",      "set segment length in seconds",           OFFSET(time),    AV_OPT_TYPE_DURATION,  {.i64 = 2000000},     0, INT64_MAX, E},
> > +    {"hls_init_time", "set segment length in seconds at init list",           OFFSET(init_time),    AV_OPT_TYPE_DURATION,  {.i64 = 0},     0, INT64_MAX, E},
> 
> Ditto, just "set segment length".

will fix it.


> 
> Cheers,
> Moritz
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 8e12aca..044c16b 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -609,13 +609,13 @@  segmentation.
 This muxer supports the following options:
 
 @table @option
-@item hls_init_time @var{seconds}
+@item hls_init_time @var{duration}
 Set the initial target segment length in seconds. Default value is @var{0}.
 Segment will be cut on the next key frame after this time has passed on the first m3u8 list.
 After the initial playlist is filled @command{ffmpeg} will cut segments
 at duration equal to @code{hls_time}
 
-@item hls_time @var{seconds}
+@item hls_time @var{duration}
 Set the target segment length in seconds. Default value is 2.
 Segment will be cut on the next key frame after this time has passed.
 
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 7f38db7..021a1ea 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -196,8 +196,8 @@  typedef struct HLSContext {
     int64_t start_sequence;
     uint32_t start_sequence_source_type;  // enum StartSequenceSourceType
 
-    float time;            // Set by a private option.
-    float init_time;       // Set by a private option.
+    int64_t time;          // Set by a private option.
+    int64_t init_time;     // Set by a private option.
     int max_nb_segments;   // Set by a private option.
     int hls_delete_threshold; // Set by a private option.
 #if FF_API_HLS_WRAP
@@ -2454,9 +2454,9 @@  static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
 
     if (vs->sequence - vs->nb_entries > hls->start_sequence && hls->init_time > 0) {
         /* reset end_pts, hls->recording_time at end of the init hls list */
-        int64_t init_list_dur = hls->init_time * vs->nb_entries * AV_TIME_BASE;
-        int64_t after_init_list_dur = (vs->sequence - hls->start_sequence - vs->nb_entries) * (hls->time * AV_TIME_BASE);
-        hls->recording_time = hls->time * AV_TIME_BASE;
+        int64_t init_list_dur = hls->init_time * vs->nb_entries;
+        int64_t after_init_list_dur = (vs->sequence - hls->start_sequence - vs->nb_entries) * hls->time;
+        hls->recording_time = hls->time;
         end_pts = init_list_dur + after_init_list_dur ;
     }
 
@@ -2941,7 +2941,7 @@  static int hls_init(AVFormatContext *s)
         av_log(hls, AV_LOG_DEBUG, "start_number evaluated to %"PRId64"\n", hls->start_sequence);
     }
 
-    hls->recording_time = (hls->init_time ? hls->init_time : hls->time) * AV_TIME_BASE;
+    hls->recording_time = hls->init_time ? hls->init_time : hls->time;
 
     if (hls->flags & HLS_SPLIT_BY_TIME && hls->flags & HLS_INDEPENDENT_SEGMENTS) {
         // Independent segments cannot be guaranteed when splitting by time
@@ -3094,7 +3094,7 @@  static int hls_init(AVFormatContext *s)
                 av_log(s, AV_LOG_WARNING, "append_list mode does not support hls_init_time,"
                        " hls_init_time value will have no effect\n");
                 hls->init_time = 0;
-                hls->recording_time = hls->time * AV_TIME_BASE;
+                hls->recording_time = hls->time;
             }
         }
 
@@ -3110,8 +3110,8 @@  static int hls_init(AVFormatContext *s)
 #define E AV_OPT_FLAG_ENCODING_PARAM
 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_time",      "set segment length in seconds",           OFFSET(time),    AV_OPT_TYPE_DURATION,  {.i64 = 2000000},     0, INT64_MAX, E},
+    {"hls_init_time", "set segment length in seconds at init list",           OFFSET(init_time),    AV_OPT_TYPE_DURATION,  {.i64 = 0},     0, INT64_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_delete_threshold", "set number of unreferenced segments to keep before deleting",  OFFSET(hls_delete_threshold),    AV_OPT_TYPE_INT,    {.i64 = 1},     1, INT_MAX, E},
     {"hls_ts_options","set hls mpegts list of options for the container format used for hls", OFFSET(format_options), AV_OPT_TYPE_DICT, {.str = NULL},  0, 0,    E},