progweb / gpx2video

Creating video with telemetry overlay from GPX data
GNU General Public License v3.0
186 stars 10 forks source link

Option `--offset` doesn't work when no GPS fix in video #28

Closed fpokryvk closed 1 year ago

fpokryvk commented 1 year ago

I have some short video where there is no GPS fix. If I provide --offset [in ms] that I manually computed, I still see message saying that time sync failed. In verbose mode, correct speed seems to be reported for each frame, but resulting video is without widgets (probably there is a problem with timezones, not sure why GPX time is converted to local timezone).

Also, I have to provide the offset of roughly one hour, even though video and GPX seems both to use UTC timezone (that I got computed from other videos of the ride, those videos with GPS fix contains the widgets after render).

...
Time synchronization...
ERROR: No GPS data stream found
WARNING: Time synchronization failure!
Rendering...
FRAME: 0 - PTS: 0 - TIMESTAMP: 0 ms - TIME: 2023-11-04 10:13:52
  [41755] GPX Time: 2023-11-04 11:13:39 Distance: 24.561 km in 4284 seconds, current speed is 11.298 (valid: true)
FRAME: 1 - PTS: 16683 - TIMESTAMP: 16 ms - TIME: 2023-11-04 10:13:52
  [41755] GPX Time: 2023-11-04 11:13:39 Distance: 24.561 km in 4284 seconds, current speed is 11.298 (valid: true)
FRAME: 2 - PTS: 33366 - TIMESTAMP: 33 ms - TIME: 2023-11-04 10:13:52
...
progweb commented 1 year ago

... Time synchronization... ERROR: No GPS data stream found WARNING: Time synchronization failure!


Your input media hasn't a GoPro stream with GPS data. So gpx2video use the file metadata to determine the start time. 

Rendering... FRAME: 0 - PTS: 0 - TIMESTAMP: 0 ms - TIME: 2023-11-04 10:13:52 [41755] GPX Time: 2023-11-04 11:13:39 Distance: 24.561 km in 4284 seconds, current speed is 11.298 (valid: true) FRAME: 1 - PTS: 16683 - TIMESTAMP: 16 ms - TIME: 2023-11-04 10:13:52 [41755] GPX Time: 2023-11-04 11:13:39 Distance: 24.561 km in 4284 seconds, current speed is 11.298 (valid: true) FRAME: 2 - PTS: 33366 - TIMESTAMP: 33 ms - TIME: 2023-11-04 10:13:52 ...

Frame time is printed in your local time (from your computer settings) It's the time moment in the video. If you add the time widget, you'll see the same value.

GPX time is the GPX file stream. And here you have near 1 hour offset!

The widget 'gpx' can help to understand.

fpokryvk commented 1 year ago

Other videos have this message:

Video stream synchronized with success (offset: 3585 s)

And widgets are rendered with this near 1 hour offset. With no-GPS video, there is no widget in the output, video looks just like input, even though in command line it prints correct speed (so time sync seems fine, something breaks later on). If I try no offset (0 ms) program ends with error, that gpx data are out of range.

progweb commented 1 year ago

This message means that gpx2video has found the stream with GPX data. (You can check with ffprobe).The GPS has the fix.

About the video with no fix, can you share it that I test myself ?

fpokryvk commented 1 year ago

Sure, but it is not a small one, so I uploaded to mega (gpx is also there).

https://mega.nz/folder/iR4wHT4J#jwlDDb7rQJHuoYjBPp0y3Q

progweb commented 1 year ago

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '../../videos/nofix/GX010012_1699097123740.mp4':

  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    creation_time   : 2023-11-04T10:13:52.000000Z
    encoder         : Lavf59.27.100

<= At first, gpx2video uses 'creation_time' (GoPro sets this time in localtime !) gpx2video converts it in UTC. So, your computer & your GoPro has to be at the same time.

  Duration: 00:01:17.03, start: 0.000000, bitrate: 52055 kb/s
  Stream #0:0[0x1](und): Video: hevc (Main) (hvc1 / 0x31637668), yuv420p(tv, bt709), 3840x2160, 52093 kb/s, 60.15 fps, 59.94 tbr, 1000k tbn (default)
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)

<= As expected from your comment, there isn't a GoPro stream:

    Stream #0:3(eng): Data: none (gpmd / 0x646D7067), 48 kb/s (default)
    Metadata:
      creation_time   : 2021-12-08T09:56:26.000000Z
      handler_name    : GoPro MET  

who contains GPS data. And you get the output:

  ERROR: No GPS data stream found
  WARNING: Time synchronization failure!

=> To sum up, no GPS data in the input video file, gpx2video assues that the video starts at '2023-11-04T10:13:52.000000Z' (in localtime)

I assume that your local is UTC+1 (Czech Republic) So creation_time in UTC: 2023-11-04T09:13:52

Now, look at gpx file. First point is:

     <trkpt lat="..." lon="...">
      <ele>239.6</ele>
      <time>2023-11-04T09:02:14Z</time>
      <extensions>
       <gpxtpx:TrackPointExtension>
        <gpxtpx:atemp>21</gpxtpx:atemp>
        <gpxtpx:hr>97</gpxtpx:hr>
        <gpxtpx:cad>0</gpxtpx:cad>
       </gpxtpx:TrackPointExtension>
      </extensions>
     </trkpt>

the last point:

     <trkpt lat="..." lon="...">
      <ele>244.8</ele>
      <time>2023-11-04T10:59:32Z</time>
      <extensions>
       <gpxtpx:TrackPointExtension>
        <gpxtpx:atemp>11</gpxtpx:atemp>
        <gpxtpx:hr>168</gpxtpx:hr>
        <gpxtpx:cad>0</gpxtpx:cad>
       </gpxtpx:TrackPointExtension>
      </extensions>
     </trkpt>

Here, 'time' is in UTC.

Without 'offset' value (or offset=0), gpx2video use the GPX point:

     <trkpt lat="..." lon="...">
      <ele>246.0</ele>
      <time>2023-11-04T09:13:51Z</time>
      <extensions>
       <gpxtpx:TrackPointExtension>
        <gpxtpx:atemp>7</gpxtpx:atemp>
        <gpxtpx:hr>154</gpxtpx:hr>
        <gpxtpx:cad>10</gpxtpx:cad>
       </gpxtpx:TrackPointExtension>
      </extensions>
     </trkpt>

If offset=10000, gpx2video searches next point. If offset=-10000, gpx2video searches previous point.

In using your media, I notice that pixel aspect ratio isn't set in the stream. I take incount it now from last commit 207de5e.

fpokryvk commented 1 year ago

But gopro video started at 10:13 UTC time, so it should be paired with 10:13 UTC wayponit in gpx, hence 1 hour offset (maybe gopro time was out of sync due to DST). Did you get widgets shown in video? It should start with speed around 11kmh...

progweb commented 1 year ago

No, GoPro starts at 10:13 in localtime. GoPro hasn't timezone settings (unfortunatly).

4k-no-offset

Here, with offset = 0.

If I set offset to '+3600000', I'am always on the track.

If I set offset to '-3600000', I'am before the track... so the speed & distance are null.

fpokryvk commented 1 year ago

Aha, I have pulled new changes and labels are on screen now! Thank you for the fix!!! Probably it was not offset issue at all, but the aspect ratio...

GoPro is showing my local time (I have just checked), but saves timestamp in UTC (at least hero 11). Nevermind, since override really works. That video was just bad coincidence (mising GPS and missing aspect ratio).

Btw, I have managed to switch to intel QSV codec, it is more than twice as fast asultrafast preset, no drop in quality when correct bitrate is set. But it is still about 10x slower than transcode with ffmpeg using qsv codec. I have no idea what the bottleneck is, but I can open MR even to this simple QSV change, someone might find it handy. (will do when I find some time to tidy up my code changes :)

progweb commented 1 year ago

Great, so I close the issue.

And thank you very much for your tests & report.