diff mbox series

[FFmpeg-devel] avformat/hlsenc: increase initial program date time precision

Message ID 20200718220349.8334-1-cus@passwd.hu
State Accepted
Commit b2318c1e537f15c4c23f302a5193d6218dffdde8
Headers show
Series [FFmpeg-devel] avformat/hlsenc: increase initial program date time precision | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Marton Balint July 18, 2020, 10:03 p.m. UTC
Also query time only once, not for every variant stream, otherwise variant
streams might get a slightly different initial program date time. And we can
set this unconditionally because HLS_PROGRAM_DATE_TIME flag is checked
elsewhere.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavformat/hlsenc.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

Comments

Steven Liu July 19, 2020, 9:20 a.m. UTC | #1
Marton Balint <cus@passwd.hu> 于2020年7月19日周日 上午6:04写道:
>
> Also query time only once, not for every variant stream, otherwise variant
> streams might get a slightly different initial program date time. And we can
> set this unconditionally because HLS_PROGRAM_DATE_TIME flag is checked
> elsewhere.
>
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
>  libavformat/hlsenc.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index df84e6487d..39ff1fa1e7 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -2704,6 +2704,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;
is it AV_TIME_BASE?
>
>      if (hls->use_localtime) {
>          pattern = get_default_pattern_localtime_fmt(s);
> @@ -2798,12 +2799,7 @@ static int hls_init(AVFormatContext *s)
>          vs->start_pts = AV_NOPTS_VALUE;
>          vs->end_pts   = AV_NOPTS_VALUE;
>          vs->current_segment_final_filename_fmt[0] = '\0';
> -
> -        if (hls->flags & HLS_PROGRAM_DATE_TIME) {
> -            time_t now0;
> -            time(&now0);
> -            vs->initial_prog_date_time = now0;
> -        }
> +        vs->initial_prog_date_time = initial_program_date_time;
>
>          for (j = 0; j < vs->nb_streams; j++) {
>              vs->has_video += vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO;
> --
> 2.26.2
>
> _______________________________________________
> 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".
Zhao Zhili July 19, 2020, 10:26 a.m. UTC | #2
> On Jul 19, 2020, at 5:20 PM, Steven Liu <lingjiujianke@gmail.com> wrote:
> 
> Marton Balint <cus@passwd.hu> 于2020年7月19日周日 上午6:04写道:
>> 
>> Also query time only once, not for every variant stream, otherwise variant
>> streams might get a slightly different initial program date time. And we can
>> set this unconditionally because HLS_PROGRAM_DATE_TIME flag is checked
>> elsewhere.
>> 
>> Signed-off-by: Marton Balint <cus@passwd.hu>
>> ---
>> libavformat/hlsenc.c | 8 ++------
>> 1 file changed, 2 insertions(+), 6 deletions(-)
>> 
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index df84e6487d..39ff1fa1e7 100644
>> --- a/libavformat/hlsenc.c
>> +++ b/libavformat/hlsenc.c
>> @@ -2704,6 +2704,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;
> is it AV_TIME_BASE?

According to the documentation of av_gettime, it's not related to AV_TIME_BASE.

/**
 * Get the current time in microseconds.
 */
int64_t av_gettime(void);

>> 
>>     if (hls->use_localtime) {
>>         pattern = get_default_pattern_localtime_fmt(s);
>> @@ -2798,12 +2799,7 @@ static int hls_init(AVFormatContext *s)
>>         vs->start_pts = AV_NOPTS_VALUE;
>>         vs->end_pts   = AV_NOPTS_VALUE;
>>         vs->current_segment_final_filename_fmt[0] = '\0';
>> -
>> -        if (hls->flags & HLS_PROGRAM_DATE_TIME) {
>> -            time_t now0;
>> -            time(&now0);
>> -            vs->initial_prog_date_time = now0;
>> -        }
>> +        vs->initial_prog_date_time = initial_program_date_time;
>> 
>>         for (j = 0; j < vs->nb_streams; j++) {
>>             vs->has_video += vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO;
>> --
>> 2.26.2
>> 
>> _______________________________________________
>> 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".
> _______________________________________________
> 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".
Steven Liu July 19, 2020, 11:45 a.m. UTC | #3
Zhao Zhili <quinkblack@foxmail.com> 于2020年7月19日周日 下午6:26写道:
>
>
>
> > On Jul 19, 2020, at 5:20 PM, Steven Liu <lingjiujianke@gmail.com> wrote:
> >
> > Marton Balint <cus@passwd.hu> 于2020年7月19日周日 上午6:04写道:
> >>
> >> Also query time only once, not for every variant stream, otherwise variant
> >> streams might get a slightly different initial program date time. And we can
> >> set this unconditionally because HLS_PROGRAM_DATE_TIME flag is checked
> >> elsewhere.
> >>
> >> Signed-off-by: Marton Balint <cus@passwd.hu>
> >> ---
> >> libavformat/hlsenc.c | 8 ++------
> >> 1 file changed, 2 insertions(+), 6 deletions(-)
> >>
> >> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> >> index df84e6487d..39ff1fa1e7 100644
> >> --- a/libavformat/hlsenc.c
> >> +++ b/libavformat/hlsenc.c
> >> @@ -2704,6 +2704,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;
> > is it AV_TIME_BASE?
>
> According to the documentation of av_gettime, it's not related to AV_TIME_BASE.
>
> /**
>  * Get the current time in microseconds.
>  */
> int64_t av_gettime(void);
I saw
 /**
 * Internal time base represented as integer
 */

#define AV_TIME_BASE            1000000
Do you mean cannot av_gettime() / AV_TIME_BASE?
>
> >>
> >>     if (hls->use_localtime) {
> >>         pattern = get_default_pattern_localtime_fmt(s);
> >> @@ -2798,12 +2799,7 @@ static int hls_init(AVFormatContext *s)
> >>         vs->start_pts = AV_NOPTS_VALUE;
> >>         vs->end_pts   = AV_NOPTS_VALUE;
> >>         vs->current_segment_final_filename_fmt[0] = '\0';
> >> -
> >> -        if (hls->flags & HLS_PROGRAM_DATE_TIME) {
> >> -            time_t now0;
> >> -            time(&now0);
> >> -            vs->initial_prog_date_time = now0;
> >> -        }
> >> +        vs->initial_prog_date_time = initial_program_date_time;
> >>
> >>         for (j = 0; j < vs->nb_streams; j++) {
> >>             vs->has_video += vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO;
> >> --
> >> 2.26.2
> >>
> >> _______________________________________________
> >> 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".
> > _______________________________________________
> > 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".
>
> _______________________________________________
> 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".
Marton Balint July 19, 2020, 12:37 p.m. UTC | #4
On Sun, 19 Jul 2020, Steven Liu wrote:

> Zhao Zhili <quinkblack@foxmail.com> 于2020年7月19日周日 下午6:26写道:
>>
>>
>>
>> > On Jul 19, 2020, at 5:20 PM, Steven Liu <lingjiujianke@gmail.com> wrote:
>> >
>> > Marton Balint <cus@passwd.hu> 于2020年7月19日周日 上午6:04写道:
>> >>
>> >> Also query time only once, not for every variant stream, otherwise variant
>> >> streams might get a slightly different initial program date time. And we can
>> >> set this unconditionally because HLS_PROGRAM_DATE_TIME flag is checked
>> >> elsewhere.
>> >>
>> >> Signed-off-by: Marton Balint <cus@passwd.hu>
>> >> ---
>> >> libavformat/hlsenc.c | 8 ++------
>> >> 1 file changed, 2 insertions(+), 6 deletions(-)
>> >>
>> >> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> >> index df84e6487d..39ff1fa1e7 100644
>> >> --- a/libavformat/hlsenc.c
>> >> +++ b/libavformat/hlsenc.c
>> >> @@ -2704,6 +2704,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;
>> > is it AV_TIME_BASE?
>>
>> According to the documentation of av_gettime, it's not related to AV_TIME_BASE.
>>
>> /**
>>  * Get the current time in microseconds.
>>  */
>> int64_t av_gettime(void);
> I saw
> /**
> * Internal time base represented as integer
> */
>
> #define AV_TIME_BASE            1000000
> Do you mean cannot av_gettime() / AV_TIME_BASE?

av_gettime() is always microsec according to docs, even if AV_TIME_BASE is 
not 1000000. In practice however AV_TIME_BASE is assumed to be 1000000 in 
a lot of places, so one can't really change it.

IMHO it is cleaner to use 1000000.0 instead of AV_TIME_BASE, because 
AV_TIME_BASE is integer, so you'd have to use (double)AV_TIME_BASE and 
that would be ugly. So I'd rather keep 1000000.0.

Regards,
Marton

>>
>> >>
>> >>     if (hls->use_localtime) {
>> >>         pattern = get_default_pattern_localtime_fmt(s);
>> >> @@ -2798,12 +2799,7 @@ static int hls_init(AVFormatContext *s)
>> >>         vs->start_pts = AV_NOPTS_VALUE;
>> >>         vs->end_pts   = AV_NOPTS_VALUE;
>> >>         vs->current_segment_final_filename_fmt[0] = '\0';
>> >> -
>> >> -        if (hls->flags & HLS_PROGRAM_DATE_TIME) {
>> >> -            time_t now0;
>> >> -            time(&now0);
>> >> -            vs->initial_prog_date_time = now0;
>> >> -        }
>> >> +        vs->initial_prog_date_time = initial_program_date_time;
>> >>
>> >>         for (j = 0; j < vs->nb_streams; j++) {
>> >>             vs->has_video += vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO;
>> >> --
>> >> 2.26.2
>> >>
>> >> _______________________________________________
>> >> 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".
>> > _______________________________________________
>> > 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".
>>
>> _______________________________________________
>> 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".
> _______________________________________________
> 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".
Marton Balint July 27, 2020, 8:14 p.m. UTC | #5
On Sun, 19 Jul 2020, Marton Balint wrote:

>
>
> On Sun, 19 Jul 2020, Steven Liu wrote:
>
>> Zhao Zhili <quinkblack@foxmail.com> 于2020年7月19日周日 下午6:26写道:
>>>
>>>
>>>
>>> > On Jul 19, 2020, at 5:20 PM, Steven Liu <lingjiujianke@gmail.com> wrote:
>>> >
>>> > Marton Balint <cus@passwd.hu> 于2020年7月19日周日 上午6:04写道:
>>> >>
>>> >> Also query time only once, not for every variant stream, otherwise 
> variant
>>> >> streams might get a slightly different initial program date time. And 
> we can
>>> >> set this unconditionally because HLS_PROGRAM_DATE_TIME flag is checked
>>> >> elsewhere.
>>> >>
>>> >> Signed-off-by: Marton Balint <cus@passwd.hu>
>>> >> ---
>>> >> libavformat/hlsenc.c | 8 ++------
>>> >> 1 file changed, 2 insertions(+), 6 deletions(-)
>>> >>
>>> >> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>>> >> index df84e6487d..39ff1fa1e7 100644
>>> >> --- a/libavformat/hlsenc.c
>>> >> +++ b/libavformat/hlsenc.c
>>> >> @@ -2704,6 +2704,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;
>>> > is it AV_TIME_BASE?
>>>
>>> According to the documentation of av_gettime, it's not related to 
> AV_TIME_BASE.
>>>
>>> /**
>>>  * Get the current time in microseconds.
>>>  */
>>> int64_t av_gettime(void);
>> I saw
>> /**
>> * Internal time base represented as integer
>> */
>>
>> #define AV_TIME_BASE            1000000
>> Do you mean cannot av_gettime() / AV_TIME_BASE?
>
> av_gettime() is always microsec according to docs, even if AV_TIME_BASE is 
> not 1000000. In practice however AV_TIME_BASE is assumed to be 1000000 in 
> a lot of places, so one can't really change it.
>
> IMHO it is cleaner to use 1000000.0 instead of AV_TIME_BASE, because 
> AV_TIME_BASE is integer, so you'd have to use (double)AV_TIME_BASE and 
> that would be ugly. So I'd rather keep 1000000.0.

Ping, thanks,

Marton

>>>
>>> >>
>>> >>     if (hls->use_localtime) {
>>> >>         pattern = get_default_pattern_localtime_fmt(s);
>>> >> @@ -2798,12 +2799,7 @@ static int hls_init(AVFormatContext *s)
>>> >>         vs->start_pts = AV_NOPTS_VALUE;
>>> >>         vs->end_pts   = AV_NOPTS_VALUE;
>>> >>         vs->current_segment_final_filename_fmt[0] = '\0';
>>> >> -
>>> >> -        if (hls->flags & HLS_PROGRAM_DATE_TIME) {
>>> >> -            time_t now0;
>>> >> -            time(&now0);
>>> >> -            vs->initial_prog_date_time = now0;
>>> >> -        }
>>> >> +        vs->initial_prog_date_time = initial_program_date_time;
>>> >>
>>> >>         for (j = 0; j < vs->nb_streams; j++) {
>>> >>             vs->has_video += vs->streams[j]->codecpar->codec_type == 
> AVMEDIA_TYPE_VIDEO;
>>> >> --
>>> >> 2.26.2
>>> >>
>>> >> _______________________________________________
>>> >> 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".
>>> > _______________________________________________
>>> > 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".
>>>
>>> _______________________________________________
>>> 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".
>> _______________________________________________
>> 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".
> _______________________________________________
> 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".
Steven Liu July 28, 2020, 1:09 a.m. UTC | #6
Marton Balint <cus@passwd.hu> 于2020年7月28日周二 上午4:15写道:
>
>
>
> On Sun, 19 Jul 2020, Marton Balint wrote:
>
> >
> >
> > On Sun, 19 Jul 2020, Steven Liu wrote:
> >
> >> Zhao Zhili <quinkblack@foxmail.com> 于2020年7月19日周日 下午6:26写道:
> >>>
> >>>
> >>>
> >>> > On Jul 19, 2020, at 5:20 PM, Steven Liu <lingjiujianke@gmail.com> wrote:
> >>> >
> >>> > Marton Balint <cus@passwd.hu> 于2020年7月19日周日 上午6:04写道:
> >>> >>
> >>> >> Also query time only once, not for every variant stream, otherwise
> > variant
> >>> >> streams might get a slightly different initial program date time. And
> > we can
> >>> >> set this unconditionally because HLS_PROGRAM_DATE_TIME flag is checked
> >>> >> elsewhere.
> >>> >>
> >>> >> Signed-off-by: Marton Balint <cus@passwd.hu>
> >>> >> ---
> >>> >> libavformat/hlsenc.c | 8 ++------
> >>> >> 1 file changed, 2 insertions(+), 6 deletions(-)
> >>> >>
> >>> >> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> >>> >> index df84e6487d..39ff1fa1e7 100644
> >>> >> --- a/libavformat/hlsenc.c
> >>> >> +++ b/libavformat/hlsenc.c
> >>> >> @@ -2704,6 +2704,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;
> >>> > is it AV_TIME_BASE?
> >>>
> >>> According to the documentation of av_gettime, it's not related to
> > AV_TIME_BASE.
> >>>
> >>> /**
> >>>  * Get the current time in microseconds.
> >>>  */
> >>> int64_t av_gettime(void);
> >> I saw
> >> /**
> >> * Internal time base represented as integer
> >> */
> >>
> >> #define AV_TIME_BASE            1000000
> >> Do you mean cannot av_gettime() / AV_TIME_BASE?
> >
> > av_gettime() is always microsec according to docs, even if AV_TIME_BASE is
> > not 1000000. In practice however AV_TIME_BASE is assumed to be 1000000 in
> > a lot of places, so one can't really change it.
> >
> > IMHO it is cleaner to use 1000000.0 instead of AV_TIME_BASE, because
> > AV_TIME_BASE is integer, so you'd have to use (double)AV_TIME_BASE and
> > that would be ugly. So I'd rather keep 1000000.0.
>
> Ping, thanks,
I have no question about it, thanks for your clarify respond, LGTM.

>
> Marton
>
> >>>
> >>> >>
> >>> >>     if (hls->use_localtime) {
> >>> >>         pattern = get_default_pattern_localtime_fmt(s);
> >>> >> @@ -2798,12 +2799,7 @@ static int hls_init(AVFormatContext *s)
> >>> >>         vs->start_pts = AV_NOPTS_VALUE;
> >>> >>         vs->end_pts   = AV_NOPTS_VALUE;
> >>> >>         vs->current_segment_final_filename_fmt[0] = '\0';
> >>> >> -
> >>> >> -        if (hls->flags & HLS_PROGRAM_DATE_TIME) {
> >>> >> -            time_t now0;
> >>> >> -            time(&now0);
> >>> >> -            vs->initial_prog_date_time = now0;
> >>> >> -        }
> >>> >> +        vs->initial_prog_date_time = initial_program_date_time;
> >>> >>
> >>> >>         for (j = 0; j < vs->nb_streams; j++) {
> >>> >>             vs->has_video += vs->streams[j]->codecpar->codec_type ==
> > AVMEDIA_TYPE_VIDEO;
> >>> >> --
> >>> >> 2.26.2
> >>> >>

Thanks

Steven
Marton Balint July 29, 2020, 9:11 p.m. UTC | #7
On Tue, 28 Jul 2020, Steven Liu wrote:

> Marton Balint <cus@passwd.hu> 于2020年7月28日周二 上午4:15写道:
>>
>>
>>
>> On Sun, 19 Jul 2020, Marton Balint wrote:
>>
>> >
>> >
>> > On Sun, 19 Jul 2020, Steven Liu wrote:
>> >
>> >> Zhao Zhili <quinkblack@foxmail.com> 于2020年7月19日周日 下午6:26写道:
>> >>>
>> >>>
>> >>>
>> >>> > On Jul 19, 2020, at 5:20 PM, Steven Liu <lingjiujianke@gmail.com> wrote:
>> >>> >
>> >>> > Marton Balint <cus@passwd.hu> 于2020年7月19日周日 上午6:04写道:
>> >>> >>
>> >>> >> Also query time only once, not for every variant stream, otherwise
>> > variant
>> >>> >> streams might get a slightly different initial program date time. And
>> > we can
>> >>> >> set this unconditionally because HLS_PROGRAM_DATE_TIME flag is checked
>> >>> >> elsewhere.
>> >>> >>
>> >>> >> Signed-off-by: Marton Balint <cus@passwd.hu>
>> >>> >> ---
>> >>> >> libavformat/hlsenc.c | 8 ++------
>> >>> >> 1 file changed, 2 insertions(+), 6 deletions(-)
>> >>> >>
>> >>> >> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> >>> >> index df84e6487d..39ff1fa1e7 100644
>> >>> >> --- a/libavformat/hlsenc.c
>> >>> >> +++ b/libavformat/hlsenc.c
>> >>> >> @@ -2704,6 +2704,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;
>> >>> > is it AV_TIME_BASE?
>> >>>
>> >>> According to the documentation of av_gettime, it's not related to
>> > AV_TIME_BASE.
>> >>>
>> >>> /**
>> >>>  * Get the current time in microseconds.
>> >>>  */
>> >>> int64_t av_gettime(void);
>> >> I saw
>> >> /**
>> >> * Internal time base represented as integer
>> >> */
>> >>
>> >> #define AV_TIME_BASE            1000000
>> >> Do you mean cannot av_gettime() / AV_TIME_BASE?
>> >
>> > av_gettime() is always microsec according to docs, even if AV_TIME_BASE is
>> > not 1000000. In practice however AV_TIME_BASE is assumed to be 1000000 in
>> > a lot of places, so one can't really change it.
>> >
>> > IMHO it is cleaner to use 1000000.0 instead of AV_TIME_BASE, because
>> > AV_TIME_BASE is integer, so you'd have to use (double)AV_TIME_BASE and
>> > that would be ugly. So I'd rather keep 1000000.0.
>>
>> Ping, thanks,
> I have no question about it, thanks for your clarify respond, LGTM.

Thanks, applied.

Regards,
Marton
diff mbox series

Patch

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index df84e6487d..39ff1fa1e7 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -2704,6 +2704,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;
 
     if (hls->use_localtime) {
         pattern = get_default_pattern_localtime_fmt(s);
@@ -2798,12 +2799,7 @@  static int hls_init(AVFormatContext *s)
         vs->start_pts = AV_NOPTS_VALUE;
         vs->end_pts   = AV_NOPTS_VALUE;
         vs->current_segment_final_filename_fmt[0] = '\0';
-
-        if (hls->flags & HLS_PROGRAM_DATE_TIME) {
-            time_t now0;
-            time(&now0);
-            vs->initial_prog_date_time = now0;
-        }
+        vs->initial_prog_date_time = initial_program_date_time;
 
         for (j = 0; j < vs->nb_streams; j++) {
             vs->has_video += vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO;