Possible to extract GPS from Sony Video?

Started by dougransom, September 03, 2013, 01:52:16 PM

Previous topic - Next topic

dougransom

Hi,

I have a Sony HX-9V which I have recorded some geotagged video in mp4 format.  Is it possible to use ExifTool to find the GPS metadata?  Sony does something weird, since just running exiftool on the file doesn't load any gps metadata (though it works fine on stills from the same camera).  I suspect more than one GPS coordinate is stored the stream.

If exiftool can't do this out of the box, is it likely the API could be used to extract this information?  Is there a place where we can find documentation on how Sony stores the GPS info in video files?

Kudos to Sony for making a GPS enabled camera which records GPS metadata  in Videos nobody can seem access. 

Phil Harvey

ExifTool should extract the GPS from MTS files if you record in this format, but doesn't yet have the ability to extract GPS from MP4 files (although this is high on the to-do list).  If you have a small MP4 sample handy, it would be useful to add to my test files for when I get around to adding this feature.  If you could mail to philharvey66 at gmail.com That would be great.

Yes, it would have been nice if Sony wrote the GPS to the MP4 metadata like they should have done.

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

dougransom

I did send an email, if anyone else wants a sample geotagged MP4 from Sony HX-9V they can grab it (for now) at https://www.dropbox.com/s/z9zxgx3fb5eop5i/MAH01268.MP4


dougransom

Hi,  was any progress made on this?  I installed the latest exiftool, but I wouldn't know to set the command line to check.


Doug


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

Update:

I couldn't get much done on this over the holidays because most of the work so far has been in searching for a format specification for the contents of the MOV mdat atom, which is hard to do from home over dialup.  But I have worked on this over the last two days from my office.  The QuickTime file format specification is good for most metadata, but I can't find where it describes the structure of the mdat atom contents, which is where the streamed GPS will be found.  For lack of appropriate documentation, I have also tried to reverse engineer the ffmpeg code, but haven't had much success with this either.  This is frustrating because I can decode both ends (the high-level QuickTime container, and the low-level H264 compressed video stream which should contain the GPS), but I haven't yet managed to figure out how this is packed (along with the other streams) in the MOV mdat atom.

I haven't given up, but right now it isn't looking good for having this feature in the next release.

I should point out that this is a systemic problem with video formats.  Many of the video format specifications are imprisoned by the ISO, and far too expensive for small, independent software developers like me.  I fear that the mdat video data may fall into this category.

- 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

#6
Bad news.  I haven't been able to make any progress on this feature, so it won't be appearing in the next release.

- Phil

Edit: If there is anyone out there who knows where to find the documentation on the video stream data format in MOV and/or MP4 files and how the GPS is stored, please let me know.
...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 ($).

dvazquez

Hi Phil,

I think that this link could be hepfull for you:
http://www.registratorviewer.com/index_en.html

They have a program that can extract the GPS information from .mov videos and save it in a text file. I have send him a mail asking something and he replyed me fast. Maybe he could give you some tips about how to do it.

Good luck!!

Phil Harvey

Quote from: dvazquez on January 15, 2014, 09:20:52 AM
They have a program that can extract the GPS information from .mov videos and save it in a text file. I have send him a mail asking something and he replyed me fast. Maybe he could give you some tips about how to do it.

You're right, Vadim is fast at responding, but it doesn't seem as if he can help.  This was his response:

       "There are several tens of GSP format inside MOV,
        I have supported. Every China developer trying
        to invent its own way how to pack GPS with video.
        And yes - no any documentation exists...

        My project is not opensource, so I cannot get you
        any sources, sorry. I have no format docs too."


(When he says "China developer", I think he is talking about the makes of popular dashcams in Russia.)

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

postsoup

Quote from: Phil Harvey on January 10, 2014, 11:21:00 AM
Bad news.  I haven't been able to make any progress on this feature, so it won't be appearing in the next release.

- Phil

Edit: If there is anyone out there who knows where to find the documentation on the video stream data format in MOV and/or MP4 files and how the GPS is stored, please let me know.

The mdat atom is used to store RAW essence. This can be almost *anything* and is defined by the sample descriptions in the track.  The Sample Descriptions will say what the media is (for example raw DV essence).   The track also lists all the samples, which are generally offsets into the essence stored in the mdat.   So the mdat has no defined structure, although you will quite often find a series of video frames one after the other - but the boundaries of these are defined in the sample table, which is sort of your table of contents for the mdat

So, its not expected to read the mdat directly as such, but to read the sample descriptions and the sample table, then read the raw data out of the mdat according to the sample table offset, and interpret that data according to the sample description.

So, you would need the raw media essence specification for any types you are interested in.  Some of these things are ISO specifications (like DV100 format), but others are probably more freely available.

its probably the same for mp4 - the above information is drawn from experience with quicktime .mov files.

Hope this helps.

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

gfields

Hi

I was following this thread for a while as I have 2 cameras from which I have been attempting to retrieve GPS data. Interestingly, I came here for information about how to deal with the exif data from the still images.

In case you are still interested in this, from my experience the GPS data stored with video files is not related to exif metadata, as of course the data applies to the whole file. GPS data must apply to the moment, so is stored as timed text.

Our first camera was a Contour+. The GPS data is embedded in a timed text subtiltle stream in the .mov file which can be seen if subtitles are turned on in the video display. This is not supported by Windows Media Player, but can be seen in VLC or the like. I use a program by the name of CGPS TrackXtracT to extract the stream. It was developed by a Contour user and is free to use, but I don't think this is supported any more since the Contour forum no longer exists.
http://kjh.ca/contour_mods/doku.php?id=gps_extract:start
Other programs can do it, but many (including MP4Box) do not read apple text well.

XMediaRecode is also good but does not specifically support GPS data. http://www.xmedia-recode.de/en/index.html

The other camera is a Sony HDR-AS30V which we bought because of the unreliablity of the Contours. The GPS data is not embedded in the .mp4 video stream, but stored as a timed text log file which is buried in the file structure on the SD card. Of course the video file must be matched to the log file by date/time as the names are not the same.
I have had some success at formatting the raw GPS data and embedding the text stream back to the mp4 file, but as WMP does not support subtitles in mp4 or mov files it is not much help in our corporate environment, so a new interface was required to display our proprietory location data.

No doubt there are as many other ways to store GPS data as there are devices to record it, but I hope this helps somebody.

Phil Harvey

Thanks, this is useful information.

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

tadej

Quote from: Phil Harvey on September 03, 2013, 01:56:06 PM
ExifTool should extract the GPS from MTS files if you record in this format,
- Phil
Hi Phil,
I did some test with MTS format and EXIF shows gps position for a file.
I suppose this a position of the first frame.
Is there a way to get gps positions for each frame for example.
regards
Dusan

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

saltmakrell

Sorry for opening up this topic but I'm quite interested in extracting GPS data from .mov files generated by dashcams.

I have a DOD LS460W camera and I've been able to extract the sections of the .mov file which contains the GPS track (quite sure).

I've saved all these sections here: http://osm.beebeetle.com/sections/    Please open with a hex-viewer.
One file per section - and each of the sections seems to correspond to one position-recording in the .gpx file exported from Registrator. Every section ends with a huge number of zeros.

The problem now is that I'm not able to find out the encoding of the data within each section. I'm just wondering if anyone here are able to recognise something from these dumps.

Regards,
Ruben

Phil Harvey

Hi Ruben,

I took a quick look, but didn't see anything I recognized.

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

saltmakrell

Thanks Phil,

I will continue investigating.

Ruben

saltmakrell

Hi,

I've come a bit further with it, but now I'm stuck again. What I know for sure is that these sections do contain the GPS track. I've tried to copy these section only from one MOV file to another and programs such as Registrator is then tricked to believe the GPS track comes from the other file.

I've also tried to manipulate each of the bytes in the array and then I've found out exactly which bytes that influence the latitude, longitude, the velocity and the heading (course).

See the attached image. The first 40 bytes contain the string   "GPS  P "  then  "x xx" and then "00000"

Then there are sequences of 52 bytes where byte 22-24 contain the letters "ATC",  30-32 contains the letter "001",  manipulating either of byte 18-20 influences the latitude, 26-28 influences the longitude, 36-38 the velocity and 40 the heading. (See the last line on the image)

The letters S M L corresponds to small influence (few hundred meters), medium influence (few 10s of kilometers), large influence (several 1000 kilometers).

Still, for every new line on the image, the values seem to change rather randomly, so I'm quite confused.

Can someone recognise something here?

Regards,
Ruben

saltmakrell

I should also add that for each file (in my first posting) there are 30 such 52 bytes segments. For each new file, only 5 of the segments change.

So for instance:
First file:
A1
A2
A3
A4
A5
B1
B2
B3
B4
B5
C1
C2
C3
C4
C5
D1
D2
D3
D4
D5
E1
E2
E3
E4
E5
F1
F2
F3
F4
F5

Second file:
G1
G2
G3
G4
G5
B1
B2
B3
B4
B5
C1
C2
C3
C4
C5
D1
D2
D3
D4
D5
E1
E2
E3
E4
E5
F1
F2
F3
F4
F5

Third file:
G1
G2
G3
G4
G5
H1
H2
H3
H4
H5
C1
C2
C3
C4
C5
D1
D2
D3
D4
D5
E1
E2
E3
E4
E5
F1
F2
F3
F4
F5

etc.


(sorry for long post..)

Phil Harvey

ExifTool 10.72 (just released) has the ability to extract GPS from MOV/MP4 videos using the -ee option, but unfortunately there are many ways that this information may be stored, and I am currently working on supporting as many as possible.  Please send me a sample if it doesn't extract it for your camera (philharvey66 at gmail.com).

- 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've just released ExifTool 10.84 with the ability to read timed GPS from a few more dashcam models, including (finally!) the format that Ruben described here.

Use the -ee option when running ExifTool on a video file to see the embedded GPS.

This version of ExifTool extracts 6 different types of GPS stored in MOV, MP4 and M2TS videos.

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