Possible to create higher-resolution GPX files from GoPro MP4s?

Started by superwattage64, September 04, 2021, 03:22:42 PM

Previous topic - Next topic

superwattage64

Hello ExifTool community. Long post, but trying to give as much info up-front.

I am trying to create GPX extracts from MP4 files out of a GoPro Hero 7. These will be used to create speed and map overlays for the videos.

I'm currently getting useful GPX files from ExifTool. But the resolution/frequency seems to be just 1 GPS trkpt per second (1 Hz). And the resulting videos with overlays are not as accurate as I'd like. These are recordings from my friend at a track day. And the speeds being shown are just not good enough.

Is there a way to extract more granular data from the source file (ideally all trkpts)? From what I've read (see sources below), the GoPro Hero 5 and above update GPS info at 18 Hz. This would be much better! A GPS reading 18 times a second!

For reference, one of the source files from the GoPro is 409 seconds (i.e. 6 min 49 sec) long. And the resulting GPX file from ExifTool has 409 trkpts. But it would be great to have all 7362 (409 sec x 18 points/sec) trkpts!  😊

Is this doable? Am I just missing some options/settings in my command string?

Here is the command I'm using and a snippet of the output:

.\exiftool.exe -p gpx.fmt -ee3 .\gx010012.MP4 > .\gx010012.gpx

gpx file snippet:
<?xml version="1.0" encoding="utf-8"?>
<gpx version="1.0"
creator="ExifTool 12.30"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/0"
xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
<trk>
<number>1</number>
<trkseg>
<trkpt lat="34.4875" lon="-80.596">
</trkpt>
<trkpt lat="34.4875292" lon="-80.5960356">
  <ele>104.068</ele>
  <time>2021-09-01T20:00:07.634Z</time>
</trkpt>
<trkpt lat="34.4875281" lon="-80.5960338">
  <ele>104.159</ele>
  <time>2021-09-01T20:00:08.679Z</time>
</trkpt>
<trkpt lat="34.4875284" lon="-80.5960338">
  <ele>104.114</ele>
  <time>2021-09-01T20:00:09.669Z</time>
</trkpt>
<trkpt lat="34.4875284" lon="-80.5960336">
  <ele>104.115</ele>
  <time>2021-09-01T20:00:10.659Z</time>
</trkpt>


I've done a fair amount of digging and from what I've read, the GoPro Hero 5 and newer devices use GoPro's own in-house developed and open-source metadata format called GPMF to embed the GPS data in the video file.

Source 1: GoPro's GPMF explained - https://gopro.com/en/us/news/gopro-video-metadata-open-source-explained
"Running the GPS 18 times faster than your average smartphone..."

And they also released an open-source parser to really dig into the embedded data.

Source 2: GPMF-Parser - https://github.com/gopro/gpmf-parser#mp4-implementation
"GPMF might be stored at 1Hz (stored in the track description), but contain gyro data at 400Hz, accelerometer at 200Hz and GPS at 18Hz (HERO5 launch data-rates)."

Currently, my workflow is to use ExifTool to extract the GPX data from the MP4. Then I convert the GPX from v1.0 to v1.1 (using the utility below) for compatibility with Garmin's helpful VIRB video editing software (used to merge the MP4 and GPX files to create the cool overlays). Unfortunately, VIRB does not seem able to read the embedded GPS data in the MP4 from the GoPro Hero 7. It's not their product, so can't really fault them there.

While I'm at it, is there any way to update the gpx.fmt (or create another one) to be GPX v1.1 compatible? I currently use GPS Visualizer's online converter for this step.
Source 3: https://www.gpsvisualizer.com/convert_input?convert_format=gpx

ExifTool's an awesome utility. I appreciate any help you can offer.

Thank you!  8)



StarGeek

Just to let you know, Phil (the program author) will be away from the computer for a couple of weeks, so there may be some delay in getting a response.  You can hit the Notify button in the upper right of this thread to get an email when there is one.

It would also help if you have a sample video prepared ahead of time.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

superwattage64

@StarGeek - Thanks for the tip on setting the Notify flag. Done!   8)

And I've got a sample file I can share/link when Phil's back. It's a whopper - 4 GB! So I'll wait til he's back before I upload it to Google Drive.

Thanks!

Phil Harvey

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

I got the file you sent.  ExifTool does extract all of the GPS from this file (18 samples per second).  The problem is that not all of the GPS is timestamped, and multiple GPS fixes are stored in what ExifTool is calling a single sub-document.  For example, here is the information in the first sub-document:

> exiftool -ee3 -G3 -doc1:all GX010012.MP4
[Doc1]          Sample Time                     : 0 s
[Doc1]          Sample Duration                 : 1.00 s
[Doc1]          Device Name                     : Hero7 Black
[Doc1]          Accelerometer                   : (Binary data 10426 bytes, use -b option to extract)
[Doc1]          Gyroscope                       : (Binary data 11708 bytes, use -b option to extract)
[Doc1]          GPS Measure Mode                : 3-Dimensional Measurement
[Doc1]          GPS Date Time                   : 2021:09:01 20:00:07.634
[Doc1]          GPS Horizontal Positioning Error: 1.07
[Doc1]          GPS Latitude                    : 34 deg 29' 15.10" N
[Doc1]          GPS Longitude                   : 80 deg 35' 45.73" W
[Doc1]          GPS Altitude                    : 104.12 m
[Doc1]          GPS Speed                       : 0.097
[Doc1]          GPS Speed 3D                    : 0.07
[Doc1]          GPS Latitude                    : 34 deg 29' 15.10" N
[Doc1]          GPS Longitude                   : 80 deg 35' 45.73" W
[Doc1]          GPS Altitude                    : 104.139 m
[Doc1]          GPS Speed                       : 0.077
[Doc1]          GPS Speed 3D                    : 0.1
[Doc1]          GPS Latitude                    : 34 deg 29' 15.10" N
[Doc1]          GPS Longitude                   : 80 deg 35' 45.73" W
[Doc1]          GPS Altitude                    : 104.084 m
[Doc1]          GPS Speed                       : 0.209
[Doc1]          GPS Speed 3D                    : 0.08
[Doc1]          GPS Latitude                    : 34 deg 29' 15.10" N
[Doc1]          GPS Longitude                   : 80 deg 35' 45.73" W
[Doc1]          GPS Altitude                    : 104.084 m
[Doc1]          GPS Speed                       : 0.147
[Doc1]          GPS Speed 3D                    : 0.22
[Doc1]          GPS Latitude                    : 34 deg 29' 15.10" N
[Doc1]          GPS Longitude                   : 80 deg 35' 45.73" W
[Doc1]          GPS Altitude                    : 104.107 m
[Doc1]          GPS Speed                       : 0.033
[Doc1]          GPS Speed 3D                    : 0.15
[Doc1]          GPS Latitude                    : 34 deg 29' 15.10" N
[Doc1]          GPS Longitude                   : 80 deg 35' 45.73" W
[Doc1]          GPS Altitude                    : 104.088 m
[Doc1]          GPS Speed                       : 0.024
[Doc1]          GPS Speed 3D                    : 0.04
[Doc1]          GPS Latitude                    : 34 deg 29' 15.10" N
[Doc1]          GPS Longitude                   : 80 deg 35' 45.73" W
[Doc1]          GPS Altitude                    : 104.082 m
[Doc1]          GPS Speed                       : 0.04
[Doc1]          GPS Speed 3D                    : 0.04
[Doc1]          GPS Latitude                    : 34 deg 29' 15.10" N
[Doc1]          GPS Longitude                   : 80 deg 35' 45.73" W
[Doc1]          GPS Altitude                    : 104.083 m
[Doc1]          GPS Speed                       : 0.018
[Doc1]          GPS Speed 3D                    : 0.05
[Doc1]          GPS Latitude                    : 34 deg 29' 15.10" N
[Doc1]          GPS Longitude                   : 80 deg 35' 45.73" W
[Doc1]          GPS Altitude                    : 104.074 m
[Doc1]          GPS Speed                       : 0.053
[Doc1]          GPS Speed 3D                    : 0.04
[Doc1]          GPS Latitude                    : 34 deg 29' 15.10" N
[Doc1]          GPS Longitude                   : 80 deg 35' 45.73" W
[Doc1]          GPS Altitude                    : 104.051 m
[Doc1]          GPS Speed                       : 0.015
[Doc1]          GPS Speed 3D                    : 0.06
[Doc1]          GPS Latitude                    : 34 deg 29' 15.10" N
[Doc1]          GPS Longitude                   : 80 deg 35' 45.73" W
[Doc1]          GPS Altitude                    : 104.035 m
[Doc1]          GPS Speed                       : 0.063
[Doc1]          GPS Speed 3D                    : 0.05
[Doc1]          GPS Latitude                    : 34 deg 29' 15.10" N
[Doc1]          GPS Longitude                   : 80 deg 35' 45.73" W
[Doc1]          GPS Altitude                    : 104.061 m
[Doc1]          GPS Speed                       : 0.036
[Doc1]          GPS Speed 3D                    : 0.08
[Doc1]          GPS Latitude                    : 34 deg 29' 15.10" N
[Doc1]          GPS Longitude                   : 80 deg 35' 45.73" W
[Doc1]          GPS Altitude                    : 104.048 m
[Doc1]          GPS Speed                       : 0.049
[Doc1]          GPS Speed 3D                    : 0.05
[Doc1]          GPS Latitude                    : 34 deg 29' 15.11" N
[Doc1]          GPS Longitude                   : 80 deg 35' 45.73" W
[Doc1]          GPS Altitude                    : 104.037 m
[Doc1]          GPS Speed                       : 0.026
[Doc1]          GPS Speed 3D                    : 0.06
[Doc1]          GPS Latitude                    : 34 deg 29' 15.11" N
[Doc1]          GPS Longitude                   : 80 deg 35' 45.73" W
[Doc1]          GPS Altitude                    : 104.044 m
[Doc1]          GPS Speed                       : 0.023
[Doc1]          GPS Speed 3D                    : 0.04
[Doc1]          GPS Latitude                    : 34 deg 29' 15.11" N
[Doc1]          GPS Longitude                   : 80 deg 35' 45.73" W
[Doc1]          GPS Altitude                    : 104.05 m
[Doc1]          GPS Speed                       : 0.049
[Doc1]          GPS Speed 3D                    : 0.03
[Doc1]          GPS Latitude                    : 34 deg 29' 15.11" N
[Doc1]          GPS Longitude                   : 80 deg 35' 45.73" W
[Doc1]          GPS Altitude                    : 104.069 m
[Doc1]          GPS Speed                       : 0.034
[Doc1]          GPS Speed 3D                    : 0.05
[Doc1]          GPS Latitude                    : 34 deg 29' 15.11" N
[Doc1]          GPS Longitude                   : 80 deg 35' 45.73" W
[Doc1]          GPS Altitude                    : 104.063 m
[Doc1]          GPS Speed                       : 0.07
[Doc1]          GPS Speed 3D                    : 0.04
[Doc1]          GPS Latitude                    : 34 deg 29' 15.11" N
[Doc1]          GPS Longitude                   : 80 deg 35' 45.73" W
[Doc1]          GPS Altitude                    : 104.068 m
[Doc1]          GPS Speed                       : 0.051
[Doc1]          GPS Speed 3D                    : 0.07
[Doc1]          ISO Speeds                      : 487 485 487 483 475 468 462 455 448 443 438 433 426 423 419 415 412 407 404 401 399 401 399 401 399 399 401 399 401 401
[Doc1]          Exposure Times                  : 1/240 1/240 1/240 1/235 1/229 1/227 1/224 1/222 1/221 1/219 1/217 1/216 1/214 1/213 1/212 1/210 1/208 1/207 1/205 1/205 1/205 1/205 1/205 1/205 1/205 1/205 1/205 1/205 1/206 1/206
[Doc1]          Auto Low Light Duration         : 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[Doc1]          Color Temperatures              : 7024 7001 6977 6977 6977 7001 7001 7024 7048 7048
[Doc1]          White Balance RGB               : (Binary data 221 bytes, use -b option to extract)


Unfortunately the -p option prints one line per sub-document, so you can't use it to see all of the GPS fixes.  Instead, you'll have to use some other ExifTool output format and process it yourself if you want a GPX file.

It would be difficult build this into ExifTool because the logic would have to be specific to this device since there isn't enough a-priori information to know how to timestamp each of the GPS records.

On a side note, do you have any idea about the meaning of any of these unknown GoPro tags?:

> exiftool -u -ee3 -G3 --a "-gopro*" GX010012.MP4
[Main]          GoPro LINF                      : LAJ8090533600502
[Main]          GoPro CINF                      : 235 159 27 132 120 40 160 4 210 196 137 208 146 169 36 78
[Main]          GoPro MUID                      : 2216402923 77604984 3498689746 1311025554 0 0 0 0
[Main]          GoPro CMOD                      : 12
[Main]          GoPro MTYP                      : 0
[Main]          GoPro DZST                      : 0
[Main]          GoPro SMTR                      : N
[Main]          GoPro EXPT                      :
[Main]          GoPro VLTE                      : Y
[Main]          GoPro VLTA                      : 89
[Main]          GoPro EISE                      : Y
[Main]          GoPro AUPT                      : N
[Main]          GoPro APTO                      : RAW
[Main]          GoPro BROD                      :
[Main]          GoPro BRID                      : 0
[Doc1]          GoPro MTRX                      : 0 0 1 0 -1 0 1 0 0
[Doc1]          GoPro ORIN                      : YxZ
[Doc1]          GoPro ORIO                      : ZXY
[Doc1]          GoPro UNIF                      : 0 0.1435546875 0.1435546875 0.1435546875 0.1435546875 0.1435546875 0.1435546875 0.115234375 0.0859375 0.0859375
[Doc1]          GoPro SROT                      : 8.01500034332275 8.01500034332275 8.01600074768066 8.01500034332275 8.01500034332275 8.01600074768066 8.01500034332275 8.01500034332275 8.01600074768066 8.01500034332275 8.01500034332275 8.01600074768066 8.01500034332275 8.01500034332275 8.01600074768066 8.01500034332275 8.01500034332275 8.01600074768066 8.01500034332275 8.01500034332275 8.01600074768066 8.01500034332275 8.01500034332275 8.01600074768066 8.01500034332275 8.01500034332275 8.01600074768066 8.01500034332275 8.01500034332275 8.01600074768066


- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

superwattage64

Thanks for the quick reply, Phil. That's great that ExifTool can already deliver all the 18 Hz GPS samples. Please tell me the proper command and options to get the all the sub-documents and lovely GPS data. I'll use that to get the output so I can build up a GPX file with all the detail! Fingers-crossed! ;D

I was able to unearth a handful of the GoPro tags you asked about. Here they are with sources. The others evaded detection from my Google-Fu. Most of the hits go to pages with output from ExifTool! Ha!

GoPro MUID - "Media Unique ID" - https://github.com/gopro/gpmf-parser/issues/28
GoPro EXPT - "Maximum Shutter Angle (EXPT)" - https://gopro.github.io/labs/control/extensions/
GoPro MTRX - "3x3 matrix to re-orient the ACCL data" - https://github.com/gopro/gpmf-parser/issues/56
GoPro ORIN - Input Orientation - https://github.com/gopro/gpmf-parser/issues/56
GoPro ORIO - Output Orientation - https://github.com/gopro/gpmf-parser/issues/56
GoPro UNIF - Image uniformity - https://github.com/gopro/gpmf-parser#where-to-find-gpmf-data (see tables at bottom)
GoPro SROT - Sensor Read Out Time - https://github.com/gopro/gpmf-parser#where-to-find-gpmf-data (see tables at bottom)


There's just not much info out there on this obscure topic. I suppose we could reach out to David Newman - https://github.com/dnewman-gpsw. I'm guessing he's a GoPro dev since he answered many of the questions on the GPMF Parser's issues pages.

Thanks again for all your help on this!


StarGeek

Quote from: superwattage64 on September 16, 2021, 12:03:41 AMPlease tell me the proper command and options to get the all the sub-documents and lovely GPS data.

Try the command in your first post above but without the -p gpx.fmt.

Edit:  Oh yeah, probably need the -a (-duplicates) option as well.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

superwattage64

Removing the -p and adding -a worked like a charm, StarGeek! Cool! Now I can (hopefully) build up a GPX that'll have a whole lot more resolution in it! So great that it was already built into ExifTool!

Thanks again very much Phil and StarGeek for the help and insights. This'll be a fun project. Now we'll have a nice, detailed map to watch the progress and speed along the course!

Take care fellas!  8)

zoffty

Hi all :D

Very interesting topic here!
superwattage64, did you find a way to convert all 18hz precision to a GPX with trackpoint for each hz?

Thanks a lot!

superwattage64

@zoffty  Not yet. But I'm working on it. I really enjoy text processing, so this is a fun challenge.

Like Phil pointed out, there's just one timestamp per sub-document. See the sample sub-document he provided. And because of this https://github.com/gopro/gpmf-parser#gpmf-timing-and-clocks, the actual/observed frequency present in the data can vary every so slightly camera-to-camera, model-to-model, etc.

So in my data for the GoPro Hero 7 for example, I'm seeing either 18 or 19 GPS samples per second within each sub-document (since the actual frequency isn't exactly 18 Hz). And it's random. You might see four or five sub-documents in a row with 18. Then a few with 19 to spice things up. So before I can calculate a timestamp (i.e. fraction of a second) for each sample within that sub-document, I have to count-up the number of samples present in the particular sub-document. Or find all the ones with 19 and discard the last one. Lots of different approaches.

And then there's the matter of converting the actual Lat/Lon coordinates stored in the stream from Degrees/Minutes/Seconds to Decimal Degrees (used by the GPX format). But that part shouldn't be too tough. This page https://www.latlong.net/degrees-minutes-seconds-to-decimal-degrees gives a great explanation and provides the formula Decimal Degrees = degrees + (minutes/60) + (seconds/3600).

And then finally (I think) formatting all that it as a GPX file. Luckily Phil provides the gpx.fmt file as a template.

So yeah, much to do. But it's fun. Right now, I'm in the early stages

I'll share whatever script(s) I come up with. Whenever that may be. This is a fun hobby. But I'm not a pro developer/programmer. So it ain't gonna be quick.   ;D  Currently working with 'awk' and 'python' to parse the initial stream. Just for reference, the 4GB MP4 from the GoPro becomes a 4MB tagged text file (about 43k lines) from ExifTool. There's a ton of other data in there! I can share the text file if anyone wants to have a go at making a script. But again, like Phil said, this would be a very model-camera specific script. It would need slight tweaks for a different camera.

My driver friend found an app that already does all the magic and a whole lot more right out of the box using the GoPro's MP4s directly. It's called TrackAddict - https://racerender.com/TrackAddict/Features.html  And given the Gordian Knot that is GPMF data, the devs of that app deserve every penny of their modest asking price.

But I still want to do this as an exercise for my own satisfaction! What if that app didn't already exist? Or if it goes away. Stuff like that... Ok, enough rambling...

StarGeek

Quote from: superwattage64 on September 19, 2021, 08:07:08 AM
And then there's the matter of converting the actual Lat/Lon coordinates stored in the stream from Degrees/Minutes/Seconds to Decimal Degrees (used by the GPX format).

Let exiftool do it for your.  Use the -n (--printConv) option to get the raw decimal number, either with -n for all tags or the # shortcut for just the coordinates.  Or you can use the -c (-coordFormat) option to reformat the coordinates any way you want.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

Quote from: superwattage64 on September 16, 2021, 12:03:41 AM
I was able to unearth a handful of the GoPro tags you asked about. Here they are with sources. The others evaded detection from my Google-Fu.

Great, thanks!  I'll add decoding of these in the next release.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

zoffty

Hi!
OK cool!
I have a GoPro 7 Black too for trackday
I unfolded my mp4 with -a to have a preview and I have same thing as you, sometimes 18 sometimes 19 samples per seconde

I will prefer to wait for your scripts rather going with tackaddict app or Harry Laptimer.
It's too long to wait the app processing on smartphone for a "just ok" result.
I prefer make a pass on Adobe Premiere and then finish with Dashware  ;D

Thanks!

superwattage64

@StarGeek  Thanks for the tip on using -n or -c to let ExifTool do the conversion. I guess I shouldn't be surprised at this point that so much functionality is already built-in. Can it order me a pizza and buy the winning lotto ticket? Or are those features still in beta?  ;)

@Phil  Glad the tags were useful. I might reach out to the potential GoPro dev mentioned in the earlier post. He might be able to connect the dots on the remaining ones or would have better documentation on all of 'em. Who knows? Also this guy, Juan Irache https://github.com/JuanIrache/gopro-telemetry seems to have a firm grasp on unwinding the GPMF info, too. But boy is his app, Telemetry Extractor https://goprotelemetryextractor.com/free/ pricey! Lordy!  :o  The free version's decent, but I still prefer to roll my own...

@zoffty  Sounds like we're in the same boat. Like I said, please don't hold your breath waiting on me to put together a magic script. Gonna be a bit on that. I'm just doing this for fun and when I have time. But will def share whatever I come up with. While you're waiting, check out Race Render - https://racerender.com/RR3/Features.html  It's from the same team that built Track Addict. Much of the same functionality, but it runs on your computer. So you won't have to wait so long for the results. My friend and I tinkered around with it some. Pretty intuitive. And it's much more affordable than Telemetry Extractor. The free version will let you test out a 3 min clip - plenty to kick the tires. Enjoy!