Extracting GPS data from MP4 video file

Started by fakej, December 31, 2017, 11:58:10 AM

Previous topic - Next topic

fakej

Dear exiftool users,

Could you please advice how to extract GPS data from the MP4 video file like: http://206.142.243.145/test_drive/test_drive.MP4 to some well known format like kml or gpx?
If this can't be done with the exiftool would it be possible with some other tool/library?

A two examples of software that can read GPS data from such file are dashcam viewer https://dashcamviewer.com/ or nexbtase replay 3 https://www.nextbase.co.uk/wp-content/uploads/2017/09/Nextbase-Replay-3-Playback-Software.html (first one is MAC/Windows and the second Windows only tool if I'm correct)

Phil Harvey

I'll move this to the top of my to-do list and have another attempt at implementing this in ExifTool.  Check back in a couple of weeks.

- 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 ($).

fakej


Phil Harvey

I'm making real headway here, but unfortunately have no solution yet.

The good news:

  - I can now parse AVC video stream data in MP4 videos

The bad news:

  - The GPS doesn't seem to be stored in the AVC video stream in MP4 videos like it is in M2TS files.

More good news:

  - One of my MP4 samples stores telemetry information in a text track that I can now parse.

More bad news:

  - It seems that different cameras store GPS differently in MP4 videos.

So if you could send me a small sample video containing GPS information I will try to extract it for your particular camera model.  Upload a raw MP4 to a file sharing service and email me the link (philharvey66 at gmail.com).

Thanks.

- 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 ($).

StarGeek

I was looking around the net for info a few days ago and it seems that the places gps info gets stored varies wildly.  For example, this script indicates that some GoPros save it in a separate stream.  Another site (can't re-locate) says that another camera saved it in the subtitle stream, so you could see them just by turning a videos subtitles on.

But it's awesome that you're making some progress at least.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

Hi StarGeek,

Yes, exactly.

I am fairly confident I can extract this metadata from these various locations, but each will take some time, and I need sample videos of each (and it would help if I had approximate GPS coordinates to make sure I'm extracting these properly).

I did find one sample that stored telemetry in a text track, and am extracting that now.

- 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 ($).

fakej

Just for the reference I would like to make readers aware that on dashcamtalk forum exists related thread:
https://dashcamtalk.com/forum/threads/gps-track-missing.32440/ So the camera model which produced my particular video is Viofo A119S and their support is quite active on community forum, so I asked them for help with regards to the file format. Lets see if they could share this knowledge.

fakej

Hi Phil, StarGeek,

I don't know if you are following the thread above but it turned out that there is a python script (made by Sergei Franco) that can extract GPS data from my video file:
http://sergei.nz/files/nvtk_mp42gpx.py
I'm guessing it should work for all videos produced by cameras with Novatek NT96660 but I'm not 100% sure about that.

StarGeek

I actually must have hit that link at some point, as it shows up as an already viewed link.  I just didn't keep track of it.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

I'm making good progress on extracting GPS from the sample you provided.

I'll be working to output the information in GPX format if possible.

- 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 ($).

Phil Harvey

I now have ExifTool to the point where this command will produce the attached GPX file (using the gpx.fmt file included with the full distribution).

exiftool -p fmt_files/gpx.fmt -ee test_drive.MP4 > out.gpx

Does this look OK for you?

- 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 ($).

fakej

Hi Phil,

I think that looks good very promising. Just a two minor questions:

  • is there any exiftool version available where I could test this functionality? I can see the latest version on the homepage is 10.71 from 2nd of Jan
  • is there any exiftool syntax that could generate gpx files from all mp4 files in the directory, possibly to some other directory? If there is not, that's not a problem I'm far from requesting features that do something that exiftool is not intended to do. I can simply wrap it with the shell script but if it is possible would be also great not to have such script :))

fakej

oh, sorry I think I misinterpreted your question. If you are asking if the format of GPX file is OK, then - yes, it works well with my favorite dashcam player Registrator Viewer.

Phil Harvey

Great.  I've just released 10.72 with this new feature.

You can create gpx files for all videos in a directory like this:

exiftool -p gpx.fmt -ee -ext mp4 -w OUTDIR/%f.gpx DIR

You will need the gpx.fmt file from the fmt_files directory of the full .tar.gz distribution.  The command will generate lots of warnings about missing GPSLongitude from some embedded documents, but with any luck it should work OK.

Let me know how it goes.  This feature may need some tuning, and currently supports only 3 different formats of embedded GPS data.

- 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 ($).

StarGeek

This is just so very cool.  I just wish I had something that would actually create files I could use this with.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).