[FFmpeg-devel] [PATCH] avformat/flvdec: enhance parsing timestamps

Anton Khirnov anton at khirnov.net
Fri May 14 11:34:12 EEST 2021


Quoting Marton Balint (2021-05-12 20:55:45)
> Take into account timezone. Use millisecond precision. Maybe we could also use
> nanosecond, but there were some float rounding concerns.
> 
> Signed-off-by: Marton Balint <cus at passwd.hu>
> ---
>  libavformat/flvdec.c     | 13 ++-----------
>  tests/ref/fate/flv-demux |  2 +-
>  2 files changed, 3 insertions(+), 12 deletions(-)
> 
> diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
> index ddaceaafe4..3791687072 100644
> --- a/libavformat/flvdec.c
> +++ b/libavformat/flvdec.c
> @@ -28,6 +28,7 @@
>  #include "libavutil/channel_layout.h"
>  #include "libavutil/dict.h"
>  #include "libavutil/opt.h"
> +#include "libavutil/internal.h"
>  #include "libavutil/intfloat.h"
>  #include "libavutil/mathematics.h"
>  #include "libavutil/time_internal.h"
> @@ -682,17 +683,7 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream,
>          } else if (amf_type == AMF_DATA_TYPE_STRING) {
>              av_dict_set(&s->metadata, key, str_val, 0);
>          } else if (amf_type == AMF_DATA_TYPE_DATE) {
> -            time_t time;
> -            struct tm t;
> -            char datestr[128];
> -            time =  date.milliseconds / 1000; // to seconds
> -            gmtime_r(&time, &t);
> -
> -            // timezone is ignored, since there is no easy way to offset the UTC
> -            // timestamp into the specified timezone
> -            strftime(datestr, sizeof(datestr), "%Y-%m-%dT%H:%M:%SZ", &t);
> -
> -            av_dict_set(&s->metadata, key, datestr, 0);
> +            avpriv_dict_set_timestamp(&s->metadata, key, -date.timezone * 60000000LL + 1000 * (int64_t)date.milliseconds);

This is wrong -- date.milliseconds is in UTC, if you add the timezone
offset it will no longer be in UTC.

-- 
Anton Khirnov


More information about the ffmpeg-devel mailing list