Creating interpolated GPX files for Mapillary
So you got a nice video from an underground train, perhaps a drive from a YouTube video (that you arranged to get use authorization from the uploader) or some other video source that you don't have a GPX track. These steps will guide you through the manipulation you need to do to craft a interpolated GPX track with timestamps.
Basically, we want to upload to Mapillary this video:
And to do so we need to create a valid GPX file, with timestamps.
Get the video
You will probably want to do that with your own videos, but just in case you happen to do it with an online video (such as this one, I shot this video, but I don't have the original anymore), you will have to download it to your computer. I used clipconverter.cc.
Get a track
The first step is to get a GPX file with the route that you want to take. The easiest way is to get a OSM way and get the points from it. Let's say you want to craft a GPX based on this subway line:
I suppose there are better ways to fetch a GPX file from a OSM way, but what I did was:
- Use my OSM ID -> Fusion Tables tool to get a KML line out of that way
- Wrap it around KML tags to create an actual valid KML file
- Convert the KML file to GPX (I used kml2gpx.com)
Now that you have a GPX file with the route you want to take, it's time to...
Split the video
This method will generate a GPX file with a constant difference of distance between points, which means it will be like you're moving in a constant speed. This is not what happens in the video, as the train stop on the stations. Therefore, you would need to split the video, a file for every segment of two stations.
In order to split the video, you'll have to:
- Watch it, writing down (in the subway example) the time that the train arrives and departs from every station
- Split it, which I done with ffmpeg:
ffmpeg -i originalVideo.mp4 -ss 01:23:45.0 -c copy -t 123 newVideo.mp4
01:23:45.0 is the timestamp of when you want to start the trim and
123 is how many seconds the trimmed part should have. For instance, if the train starts moving at 30 seconds and stops at 1 minute and 20 seconds, you would enter "00:00:30.0" on the first parameter and "50" on the second.
As the this subway line is "Line 4", I saved the original file as "L4.mp4" and every trimmed part as "L4-1.mp4", "L4-2.mp4" and so on.
After splitting the video, you also have to...
Split the GPX file
You could do so opening it on a text file and editing it. My workflow was:
- Open it up the original file (I called it L4.gpx) on a text editor
- For every station, search it's coordinates on OpenStreetMap (go on Layers > Map Data and click on the station (if part of the way) or the closest point on the way)
- Find it on the GPX file
- Write down the station name, as a comment (
<!-- like this -->)
- After doing it with every station, writing the time of arrival and departure, as well the name of the next station on the comment
So basically my GPX file became like this:
(Sorry, couldn't handle the markdown for codeblock)
After you write every segment, copy and paste the whole GPX file into new files, erasing everything that is not in the segment that you're interested. You'll end up with one file for every video splitted, and I saved that as "L4-1.gpx", "L4-2.gpx" and so on.
Now that you have a GPX file for every segment, it's time to...
Craft a interpolated GPX file
I made a tool for this, check it out on nighto.github.io/gpxcrafttime.
Basically, you have to select one of the GPX files (L4-1.gpx, for instance), enter the date that the video was took (in this example, 2012-01-16) and a timestamp for the start and the end of the video. Note that the time itself does not have to correspond do the time that the video was actually recorded, so I chose to start at midday (12:00:00). The first video segment goes from 00:10 until 01:25 of the original video (L4.mp4), so I entered 12:00:10 to start time and 12:01:25 to the end time. When you click convert, your browser will export ("download") a
file.gpx. Do it for every segment, and save it with a meaningful name (such as
What this tool does is to create a GPX file with a bunch of points - one for every second of the video - placing them following the line created by the points on the original GPX file. Basically, going from this:
Now, all you have to do is [upload the videos and interpolated GPX files](www.mapillary.com/map/upload/vi) and after a few hours your tracks will be on the map:
If you have any questions, or want to suggest improvements to my workflow (there are probably better ways to do this!), please do so on the comment box below. Thanks!