On 2021-05-11 17:51 +0200, Anton Khirnov wrote:
> Quoting Alexander Strasser (2021-05-10 15:35:02)
> > On 2021-05-10 10:22 +0200, Anton Khirnov wrote:
> > > Export them in UTC, not the local timezone. This way the output is
> > > the same everywhere. The timezone information stored in the file is
> > > still ignored, since there seems to be no simple way to export it
> > > correctly.
> > >
> > > Format them according to ISO 8601, which we generally use for exporting
> > > dates.
> > > ---
> > > If anyone has practical suggestions for exporting the timezone, I would
> > > love to hear them. Don't see anything in the standard library for
> > > "express this UTC timestamp in a given timezone". Just adding the offset
> > > to the timestamp would AFAIU not be correct wrt leap seconds (and maybe
> > > something else? dates are hard).
> >
> > Surprisingly it seems best to ignore the timezone part on purpose!
> >
> > In 2.13 of Adobe's AMF 0 spec
> >   
> > https://www.adobe.com/content/dam/acom/en/devnet/pdf/amf0-file-format-specification.pdf
> >
> > it is stated that the timezone part should not be filled, nor
> > used.
> >
> > So the commit message part about it and the comment in the
> > added by this patch should probably be removed.
> >
> > Though independent of this patch, one could maybe add a
> > check that states sample welcome if a file with a timezone
> > offset is found.
>
> I have no idea how FLV is related to AMF0,

FLV reuses AMF0 spec for serialization of the metadata we talk about?


> but the sample used in the
> test in question here does have a non-zero value of the tz offset. So
> the comment seems appropriate to me.

Interesting.

In case of that sample it is probably FLVTool2 that wrote that
wrote the metadata. Then this should be its Ruby code for handling
the AMF date type:

    def write__AMF_date(time)
      write__UI8 11
      write [(time.to_f * 1000.0)].pack('G')
      write__SI16( (Time.now.gmtoff / 60).to_i )
    end

    def read__AMF_date
      utc_time = Time.at((read__AMF_double / 1000).to_i)
      utc_time + (read__SI16 * 60) - Time.now.gmtoff
    end

I have a attached patch, that on top of your patch, adds output of
timezone information according to the quoted interpretation of
FLVTool2.


Best regards,
  Alexander

[...]
From 3fd6c8f81baacace49e0a6cc431295dc56a077bc Mon Sep 17 00:00:00 2001
From: Alexander Strasser <eclip...@gmx.net>
Date: Wed, 12 May 2021 00:46:54 +0200
Subject: [PATCH] lavf/flvdec: metadata date: respect timezone information if
 present

If the timezone data of an AMF 0 date type is non-zero, include that
information as UTC offset in hours and minutes.
---
 libavformat/flvdec.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index ddaceaafe4..c941e62e23 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -688,9 +688,21 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream,
             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);
+            strftime(datestr, sizeof(datestr), "%Y-%m-%dT%H:%M:%S", &t);
+
+            if (date.timezone) {
+                int off_tz = date.timezone; // offset in minutes
+                char ch_sign = '+';
+                if (off_tz < 0) {
+                    off_tz = -off_tz;
+                    ch_sign = '-';
+                }
+                if (off_tz > 99*60 + 59)
+                    off_tz = 99*60 + 59;
+
+                av_strlcatf(datestr, sizeof(datestr), "%c%02d%02d", ch_sign, off_tz / 60, off_tz % 60);
+            } else
+                av_strlcat(datestr, "Z", sizeof(datestr));

             av_dict_set(&s->metadata, key, datestr, 0);
         }
--
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to