Creating interpolated GPX files for Mapillary

Posted by Nighto on 28 November 2015 in English (English)

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

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:

  1. Use my OSM ID -> Fusion Tables tool to get a KML line out of that way
  2. Wrap it around KML tags to create an actual valid KML file
  3. Convert the KML file to GPX (I used

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:

  1. Watch it, writing down (in the subway example) the time that the train arrives and departs from every station
  2. Split it, which I done with ffmpeg:

ffmpeg -i originalVideo.mp4 -ss 01:23:45.0 -c copy -t 123 newVideo.mp4

Where 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:

  1. Open it up the original file (I called it L4.gpx) on a text editor
  2. 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)
  3. Find it on the GPX file
  4. Write down the station name, as a comment (<!-- like this -->)
  5. 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:

excerpt of GPX file (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

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 L4-1-interpolated.gpx).

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:

print of OSM map

to this:

print of Mapillary

Now, all you have to do is [upload the videos and interpolated GPX files]( and after a few hours your tracks will be on the map:


Check São Paulo's Subway Line 4 on Mapillary.

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!

Location: Santo Amaro, São Paulo, Microrregião de São Paulo, RMSP, Mesorregião Metropolitana de São Paulo, São Paulo, Southeast Region, Brazil

Comment from tyr_asd on 30 November 2015 at 09:43

I suppose there are better ways to fetch a GPX file from a OSM way

You could also use overpass turbo ( to load the way and export it as GPX from there.

Hide this comment

Comment from Nighto on 30 November 2015 at 12:32

I knew that there had to be a better way to do that. Thanks!

Hide this comment

Comment from DaCor on 30 November 2015 at 18:25

That video is under the Standard Youtube License, Mapillary is under CC-BY-SA

Is there a conflict between those?

Hide this comment

Comment from Nighto on 30 November 2015 at 18:41

@DaCor: as the original author, I can (re)license the video as I want. Therefore there is no problem in uploading it to Mapillary.

Hide this comment

Comment from Alexandre Magno on 2 December 2015 at 11:14

Some people believe that this use of OSM data to generate the GPX implies license issues with the ODbL. Make sense. But I can be more specific only using portuguese.

Hide this comment

Comment from DaCor on 6 December 2015 at 00:34

@nighto, didnt realise that :)

Hide this comment

Comment from Nighto on 11 December 2015 at 18:52

Alexandre, só vi seu comentário agora. Escreva em português! :)

Hide this comment

Leave a comment

Parsed with Markdown

  • Headings

    # Heading
    ## Subheading

  • Unordered list

    * First item
    * Second item

  • Ordered list

    1. First item
    2. Second item

  • Link

  • Image

    ![Alt text](URL)

Login to leave a comment