diff mbox series

[FFmpeg-devel] Add init_program_date_time so start time can be specified

Message ID 20231017155100.43908-1-davejohansen@gmail.com
State New
Headers show
Series [FFmpeg-devel] Add init_program_date_time so start time can be specified | expand

Checks

Context Check Description
yinshiyou/commit_msg_loongarch64 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
andriy/commit_msg_x86 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

David Johansen Oct. 17, 2023, 3:51 p.m. UTC
---
 doc/muxers.texi      | 3 +++
 libavformat/hlsenc.c | 7 ++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

Comments

Marvin Scholz Oct. 18, 2023, 1:09 a.m. UTC | #1
On 17 Oct 2023, at 17:51, Dave Johansen wrote:

> ---
>  doc/muxers.texi      | 3 +++
>  libavformat/hlsenc.c | 7 ++++++-
>  2 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/doc/muxers.texi b/doc/muxers.texi
> index f6071484ff..87c19a5cb9 100644
> --- a/doc/muxers.texi
> +++ b/doc/muxers.texi
> @@ -1086,6 +1086,9 @@ seeking. This flag should be used with the @code{hls_time} option.
>  @item program_date_time
>  Generate @code{EXT-X-PROGRAM-DATE-TIME} tags.
>
> +@item init_program_date_time
> +Time to start program date time at.
> +
>  @item second_level_segment_index
>  Makes it possible to use segment indexes as %%d in hls_segment_filename expression
>  besides date/time values when strftime is on.
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 4ef84c05c1..474322cc21 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -28,6 +28,8 @@
>  #include <unistd.h>
>  #endif
>
> +#include "float.h"
> +
>  #include "libavutil/avassert.h"
>  #include "libavutil/mathematics.h"
>  #include "libavutil/avstring.h"
> @@ -212,6 +214,8 @@ typedef struct HLSContext {
>      int64_t recording_time;
>      int64_t max_seg_size; // every segment file max size
>
> +    double init_program_date_time;
> +
>      char *baseurl;
>      char *vtt_format_options_str;
>      char *subtitle_filename;
> @@ -2867,7 +2871,7 @@ static int hls_init(AVFormatContext *s)
>      char *p = NULL;
>      int http_base_proto = ff_is_http_proto(s->url);
>      int fmp4_init_filename_len = strlen(hls->fmp4_init_filename) + 1;
> -    double initial_program_date_time = av_gettime() / 1000000.0;
> +    double initial_program_date_time = hls->init_program_date_time ? hls->init_program_date_time : av_gettime() / 1000000.0;
>
>      if (hls->use_localtime) {
>          pattern = get_default_pattern_localtime_fmt(s);
> @@ -3141,6 +3145,7 @@ static const AVOption options[] = {
>      {"split_by_time", "split the hls segment by time which user set by hls_time", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_SPLIT_BY_TIME }, 0, UINT_MAX,   E, "flags"},
>      {"append_list", "append the new segments into old hls segment list", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_APPEND_LIST }, 0, UINT_MAX,   E, "flags"},
>      {"program_date_time", "add EXT-X-PROGRAM-DATE-TIME", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_PROGRAM_DATE_TIME }, 0, UINT_MAX,   E, "flags"},
> +    {"init_program_date_time", "Time to start program date time at", OFFSET(init_program_date_time), AV_OPT_TYPE_DOUBLE, {.dbl = 0 }, 0, DBL_MAX,   E},

This should probably not be mixed into the flags options list.

It seems odd to have the user provide a double here instead of a ISO 8601 datetime, which is what the spec requires / ends up in the playlist.
If you do not want to handle the datetime string parsing, at least it would be good to give a hint what exactly the double value is expected to be here.

However usability-wise I would prefer to accept a proper date/time here…

>      {"second_level_segment_index", "include segment index in segment filenames when use_localtime", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_SECOND_LEVEL_SEGMENT_INDEX }, 0, UINT_MAX,   E, "flags"},
>      {"second_level_segment_duration", "include segment duration in segment filenames when use_localtime", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_SECOND_LEVEL_SEGMENT_DURATION }, 0, UINT_MAX,   E, "flags"},
>      {"second_level_segment_size", "include segment size in segment filenames when use_localtime", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_SECOND_LEVEL_SEGMENT_SIZE }, 0, UINT_MAX,   E, "flags"},
> -- 
> 2.39.2 (Apple Git-143)
>
> _______________________________________________
> 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".
David Johansen Oct. 18, 2023, 1:14 a.m. UTC | #2
On Tue, Oct 17, 2023 at 7:09 PM <epirat07@gmail.com> wrote:

>
>
> On 17 Oct 2023, at 17:51, Dave Johansen wrote:
>
> > ---
> >  doc/muxers.texi      | 3 +++
> >  libavformat/hlsenc.c | 7 ++++++-
> >  2 files changed, 9 insertions(+), 1 deletion(-)
> >
> > diff --git a/doc/muxers.texi b/doc/muxers.texi
> > index f6071484ff..87c19a5cb9 100644
> > --- a/doc/muxers.texi
> > +++ b/doc/muxers.texi
> > @@ -1086,6 +1086,9 @@ seeking. This flag should be used with the
> @code{hls_time} option.
> >  @item program_date_time
> >  Generate @code{EXT-X-PROGRAM-DATE-TIME} tags.
> >
> > +@item init_program_date_time
> > +Time to start program date time at.
> > +
> >  @item second_level_segment_index
> >  Makes it possible to use segment indexes as %%d in hls_segment_filename
> expression
> >  besides date/time values when strftime is on.
> > diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> > index 4ef84c05c1..474322cc21 100644
> > --- a/libavformat/hlsenc.c
> > +++ b/libavformat/hlsenc.c
> > @@ -28,6 +28,8 @@
> >  #include <unistd.h>
> >  #endif
> >
> > +#include "float.h"
> > +
> >  #include "libavutil/avassert.h"
> >  #include "libavutil/mathematics.h"
> >  #include "libavutil/avstring.h"
> > @@ -212,6 +214,8 @@ typedef struct HLSContext {
> >      int64_t recording_time;
> >      int64_t max_seg_size; // every segment file max size
> >
> > +    double init_program_date_time;
> > +
> >      char *baseurl;
> >      char *vtt_format_options_str;
> >      char *subtitle_filename;
> > @@ -2867,7 +2871,7 @@ static int hls_init(AVFormatContext *s)
> >      char *p = NULL;
> >      int http_base_proto = ff_is_http_proto(s->url);
> >      int fmp4_init_filename_len = strlen(hls->fmp4_init_filename) + 1;
> > -    double initial_program_date_time = av_gettime() / 1000000.0;
> > +    double initial_program_date_time = hls->init_program_date_time ?
> hls->init_program_date_time : av_gettime() / 1000000.0;
> >
> >      if (hls->use_localtime) {
> >          pattern = get_default_pattern_localtime_fmt(s);
> > @@ -3141,6 +3145,7 @@ static const AVOption options[] = {
> >      {"split_by_time", "split the hls segment by time which user set by
> hls_time", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_SPLIT_BY_TIME }, 0, UINT_MAX,
>  E, "flags"},
> >      {"append_list", "append the new segments into old hls segment
> list", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_APPEND_LIST }, 0, UINT_MAX,   E,
> "flags"},
> >      {"program_date_time", "add EXT-X-PROGRAM-DATE-TIME", 0,
> AV_OPT_TYPE_CONST, {.i64 = HLS_PROGRAM_DATE_TIME }, 0, UINT_MAX,   E,
> "flags"},
> > +    {"init_program_date_time", "Time to start program date time at",
> OFFSET(init_program_date_time), AV_OPT_TYPE_DOUBLE, {.dbl = 0 }, 0,
> DBL_MAX,   E},
>
> This should probably not be mixed into the flags options list.
>
> It seems odd to have the user provide a double here instead of a ISO 8601
> datetime, which is what the spec requires / ends up in the playlist.
> If you do not want to handle the datetime string parsing, at least it
> would be good to give a hint what exactly the double value is expected to
> be here.
>
> However usability-wise I would prefer to accept a proper date/time here…
>

Is there an example of how to accept a string as the option and then do the
parsing that I could base the code on?
Marvin Scholz Oct. 18, 2023, 2:11 p.m. UTC | #3
On 18 Oct 2023, at 3:14, David Johansen wrote:

> On Tue, Oct 17, 2023 at 7:09 PM <epirat07@gmail.com> wrote:
>
>>
>>
>> On 17 Oct 2023, at 17:51, Dave Johansen wrote:
>>
>>> ---
>>>  doc/muxers.texi      | 3 +++
>>>  libavformat/hlsenc.c | 7 ++++++-
>>>  2 files changed, 9 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/doc/muxers.texi b/doc/muxers.texi
>>> index f6071484ff..87c19a5cb9 100644
>>> --- a/doc/muxers.texi
>>> +++ b/doc/muxers.texi
>>> @@ -1086,6 +1086,9 @@ seeking. This flag should be used with the
>> @code{hls_time} option.
>>>  @item program_date_time
>>>  Generate @code{EXT-X-PROGRAM-DATE-TIME} tags.
>>>
>>> +@item init_program_date_time
>>> +Time to start program date time at.
>>> +
>>>  @item second_level_segment_index
>>>  Makes it possible to use segment indexes as %%d in hls_segment_filename
>> expression
>>>  besides date/time values when strftime is on.
>>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>>> index 4ef84c05c1..474322cc21 100644
>>> --- a/libavformat/hlsenc.c
>>> +++ b/libavformat/hlsenc.c
>>> @@ -28,6 +28,8 @@
>>>  #include <unistd.h>
>>>  #endif
>>>
>>> +#include "float.h"
>>> +
>>>  #include "libavutil/avassert.h"
>>>  #include "libavutil/mathematics.h"
>>>  #include "libavutil/avstring.h"
>>> @@ -212,6 +214,8 @@ typedef struct HLSContext {
>>>      int64_t recording_time;
>>>      int64_t max_seg_size; // every segment file max size
>>>
>>> +    double init_program_date_time;
>>> +
>>>      char *baseurl;
>>>      char *vtt_format_options_str;
>>>      char *subtitle_filename;
>>> @@ -2867,7 +2871,7 @@ static int hls_init(AVFormatContext *s)
>>>      char *p = NULL;
>>>      int http_base_proto = ff_is_http_proto(s->url);
>>>      int fmp4_init_filename_len = strlen(hls->fmp4_init_filename) + 1;
>>> -    double initial_program_date_time = av_gettime() / 1000000.0;
>>> +    double initial_program_date_time = hls->init_program_date_time ?
>> hls->init_program_date_time : av_gettime() / 1000000.0;
>>>
>>>      if (hls->use_localtime) {
>>>          pattern = get_default_pattern_localtime_fmt(s);
>>> @@ -3141,6 +3145,7 @@ static const AVOption options[] = {
>>>      {"split_by_time", "split the hls segment by time which user set by
>> hls_time", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_SPLIT_BY_TIME }, 0, UINT_MAX,
>>  E, "flags"},
>>>      {"append_list", "append the new segments into old hls segment
>> list", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_APPEND_LIST }, 0, UINT_MAX,   E,
>> "flags"},
>>>      {"program_date_time", "add EXT-X-PROGRAM-DATE-TIME", 0,
>> AV_OPT_TYPE_CONST, {.i64 = HLS_PROGRAM_DATE_TIME }, 0, UINT_MAX,   E,
>> "flags"},
>>> +    {"init_program_date_time", "Time to start program date time at",
>> OFFSET(init_program_date_time), AV_OPT_TYPE_DOUBLE, {.dbl = 0 }, 0,
>> DBL_MAX,   E},
>>
>> This should probably not be mixed into the flags options list.
>>
>> It seems odd to have the user provide a double here instead of a ISO 8601
>> datetime, which is what the spec requires / ends up in the playlist.
>> If you do not want to handle the datetime string parsing, at least it
>> would be good to give a hint what exactly the double value is expected to
>> be here.
>>
>> However usability-wise I would prefer to accept a proper date/time here…
>>
>
> Is there an example of how to accept a string as the option and then do the
> parsing that I could base the code on?

For the option itself, just change the type (of course adjust the struct variable as well):

{"init_program_date_time", "Time to start program date time at",
 OFFSET(init_program_date_time), AV_OPT_TYPE_STRING, .flags = E},

And for parsing maybe have a look at libavformat/dashdec.c around line 191 which does
rudimentary ISO-8601 parsing.

> _______________________________________________
> 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 f6071484ff..87c19a5cb9 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1086,6 +1086,9 @@  seeking. This flag should be used with the @code{hls_time} option.
 @item program_date_time
 Generate @code{EXT-X-PROGRAM-DATE-TIME} tags.
 
+@item init_program_date_time
+Time to start program date time at.
+
 @item second_level_segment_index
 Makes it possible to use segment indexes as %%d in hls_segment_filename expression
 besides date/time values when strftime is on.
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 4ef84c05c1..474322cc21 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -28,6 +28,8 @@ 
 #include <unistd.h>
 #endif
 
+#include "float.h"
+
 #include "libavutil/avassert.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/avstring.h"
@@ -212,6 +214,8 @@  typedef struct HLSContext {
     int64_t recording_time;
     int64_t max_seg_size; // every segment file max size
 
+    double init_program_date_time;
+
     char *baseurl;
     char *vtt_format_options_str;
     char *subtitle_filename;
@@ -2867,7 +2871,7 @@  static int hls_init(AVFormatContext *s)
     char *p = NULL;
     int http_base_proto = ff_is_http_proto(s->url);
     int fmp4_init_filename_len = strlen(hls->fmp4_init_filename) + 1;
-    double initial_program_date_time = av_gettime() / 1000000.0;
+    double initial_program_date_time = hls->init_program_date_time ? hls->init_program_date_time : av_gettime() / 1000000.0;
 
     if (hls->use_localtime) {
         pattern = get_default_pattern_localtime_fmt(s);
@@ -3141,6 +3145,7 @@  static const AVOption options[] = {
     {"split_by_time", "split the hls segment by time which user set by hls_time", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_SPLIT_BY_TIME }, 0, UINT_MAX,   E, "flags"},
     {"append_list", "append the new segments into old hls segment list", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_APPEND_LIST }, 0, UINT_MAX,   E, "flags"},
     {"program_date_time", "add EXT-X-PROGRAM-DATE-TIME", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_PROGRAM_DATE_TIME }, 0, UINT_MAX,   E, "flags"},
+    {"init_program_date_time", "Time to start program date time at", OFFSET(init_program_date_time), AV_OPT_TYPE_DOUBLE, {.dbl = 0 }, 0, DBL_MAX,   E},
     {"second_level_segment_index", "include segment index in segment filenames when use_localtime", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_SECOND_LEVEL_SEGMENT_INDEX }, 0, UINT_MAX,   E, "flags"},
     {"second_level_segment_duration", "include segment duration in segment filenames when use_localtime", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_SECOND_LEVEL_SEGMENT_DURATION }, 0, UINT_MAX,   E, "flags"},
     {"second_level_segment_size", "include segment size in segment filenames when use_localtime", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_SECOND_LEVEL_SEGMENT_SIZE }, 0, UINT_MAX,   E, "flags"},