Overview

The Sony XR200 camera is able to include GPS location data in its video recordings. Normally, this information is only visible when playing back the video in the camera itself. Even then, its not possible to view it at the same time as the time of day data - you need to select one or the other.

If the camera video data is transferred to a computer via the USB port, the GPS data is "lost". Computer video players capable of replaying the .MTS video streams only show the time of day data; there is no way to view the GPS data.

Ideally we want to be able to display the time of day and GPS informations simultaneously with the video stream itself.

We describe here how to extract all the required data from an MTS format video stream file and then overlay the information over a replay of the of the video file.


Method

We assume the camera data has been transferred to computer via the camera's USB connector, resulting in a directory containing a number of video clip files with an .MTS suffix e.g. 00000.MTS, 00001.MTS, 00002.MTS etc.

The GPS and other data is extracted from a video clip file using Phil Harvey's exiftool application. Running  just:
     exiftool 00000.MTS

will return a wealth of data (including the GPS location and time of day) to the screen. However this is just for the first frame of the video stream; if the camera location moves during the clip, we need the new GPS location data as well as the time the change occurs. Also, the simple invocation of exiftool returns far more information than we want to deal with. Looking through the exiftool documentation, we find that we can extract all instances of the exif data throughout the video file, as well as restricting the visible output to particular fields we're interested in, with the command:
    exiftool -ee -p '$gpslatitude, $gpslongitude, $gpstimestamp, $DateTimeOriginal' 00000.MTS

Note: This can take a long time to run! On a 2GB video file (the maximum produced the Sony XR200 camera), the data extraction can take about an hour - the exact time taken will depend on the machine being used.

Since the data extraction can take so long and there may be so much of it that its lost from the screen, we change the command to write the data to a file as well as the screen:
    exiftool -ee -p '$gpslatitude, $gpslongitude, $gpstimestamp, $DateTimeOriginal' 00000.MTS 2>&1 | tee 00000.MTS.info

This command writes the relevant data from video file 00000.MTS into a data file 00000.MTS.info (the data filename can be anything you like but keeping it similar to the original video file will help later when we might like to script the whole procedure). Using the command above will result in a .info file containing lines something like:

27 deg 22' 28.31" S, 153 deg 9' 44.49" E, 21:23:02, 2011:02:05 07:22:18+10:00
27 deg 22' 28.39" S, 153 deg 9' 44.41" E, 21:23:03, 2011:02:05 07:22:18+10:00
27 deg 22' 28.39" S, 153 deg 9' 44.41" E, 21:23:03, 2011:02:05 07:22:19+10:00
27 deg 22' 28.46" S, 153 deg 9' 44.33" E, 21:23:04, 2011:02:05 07:22:19+10:00
27 deg 22' 28.46" S, 153 deg 9' 44.33" E, 21:23:04, 2011:02:05 07:22:20+10:00
27 deg 22' 28.53" S, 153 deg 9' 44.25" E, 21:23:05, 2011:02:05 07:22:20+10:00
27 deg 22' 28.53" S, 153 deg 9' 44.25" E, 21:23:05, 2011:02:05 07:22:21+10:00
27 deg 22' 28.58" S, 153 deg 9' 44.21" E, 21:23:06, 2011:02:05 07:22:21+10:00

This information could be used as is: look for the time of day of interest (the last field in each line) and therefore find the latitude and longitude (1st and 2nd fields) of the camera at that time.

However, it would be nice to view this information simultaneously with the video it relates to i.e. when we view the video, we also see the relevant data. To achieve this, we take advantage of the subtitling capability of the mplayer application.

To use mplayer's subtitling feature, we need to generate a subtitle file - we'll use mplayer's own mpsub format for this file. Other subtitle formats are also recognised by mplayer but the mpsub format is easy to generate from the .info file we have already generated. Apart from a generic header, the mpsub format subtitle file will need a series of lines of the data we want displayed (as per our .info file), with each line preceded by a timing field. Each entry of timing field + display data is separated from the next entry by a blank line.

Its apparent from the info file that the camera has produced new data twice per second. Thus, each line of data needs to be shown half a second after the previous line. The subtitle timing information for each line of display data will therefore be:
    0 0.5
i.e. without delay ("0"), show the next line for half a second ("0.5)

Therefore we can create a subtitle file 00000.MTS.sub from the 00000.MTS.info file as follows:
# copy generic header from somewhere:
    cat /location/of/generic/header/mpheader.sub > 00000.MTS.sub

# run 00000.MTS.info through sed to introduce blank lines and timing, appending the result to 00000.MTS.sub file:
    sed -e 's/^/\n0 0.5\n/' 00000.MTS.info >> 00000.MTS.sub

The 00000.MTS.sub could now be used to subtitle a replay of the 00000.MTS video file. However, we'll just change the display of the data so that the GPS latitude and logitude are displayed on one line, the remaining data on a second line:
# run 00000.MTS.sub through sed in place (-i option), ignoring first 19lines of header, to display data as 2 lines (splitting original data line after second comma)
    sed -i '19,$s/,\ /\n/2' 00000.MTS.sub

To display the subtitle data over the video, run:
    mplayer -demuxer lavc -sub 00000.MTS.sub 00000.MTS


Issues
    The sed expressions are somewhat prone to typos ....
    Here's an example script which incorporates all the steps above - just give it a video filename e.g.
       make_sub_file 00000.MTS



Contact
    Please send any questions, comments, advice etc., to Chris Willing <c.willing _at_ uq.edu.au>