Building geotagged video (or a simple technology for GPS video overlay)

You may have already noticed that I have these cool videos on my YouTube channel - they include lots of information about the road we travel, including live timing and odometer, and those are pretty accurate. I do receive questions as to how does one include these data onto his own video and decided to make a post about it.

In my setup video is being captured by Chinese CarCam Q2 DVR, it does not contain GPS chip at all, so there has to be some other device to record geodata, be it a GPS software of on your smartphone, or a standalone GPS tracker. I have tried different devices of these kind and they all suck, as applications tend to crash taking track data with them; standalone GPS trackers are just black boxes -  you'll find out they ran out of space when you'll connect it to your laptop in the evening.

So in my setup I've ended with GPS GPRS tracker that collects track points and sends them out to some online service at regular intervals. I've bought V-Sun TLT-2H tracker off DX and used it with my own home-brewed online tracking system I had to make another post/github about. Once a minute it uploads four track points spaced 15 seconds apart, and the web service adds them to standard GPX track log. With this setup, you can just point your browser to the web page and instantly see if your position data is accurately submitted or not.

Now, in the end, I have some 250+ Gigabytes of H.264 compressed video that I need to pair with a bunch of GPX track files to make a neat video with GPS data overlay. As you might imagine there's a bunch of programs that promise they do this job for you with a few clicks of your mouse, but unfortunately all of them are tailored for short video clips - i.e. onboard lap with a racer. And what's more important - they all believe your video length matches your track time. That's not the case, as one's rarely spends precious gigabytes on SD-card to capture the parking lot for an hour and a half..

So I had to abandon these cool looking programs that either crashed when fed with 6k points track, or produced the video that was completely out of sync with GPS track. There had to be some other way, and then I had this idea - what if we build subtitles out of GPS track and then overlay these subtitles on the video?

Mind you, GPX track is just an XML file, and common subtitle format (SRT) is just a text file with blocks similar to:

84
02:15:48,000 --> 02:16:03,000

585km


whereas 84 is an item index, timestamps specify when item has to appear and dissolve on the screen (measured from the video beginning) and the last line is the subtitle text itself.

One can easily generate such a text file with some simple script - quick and dirty PHP in my case, although I believe this could be done completely in XSLT 2.0.. The only caveat is that you should trim your track file's starting point to match the beginning of your video before you convert your track to SRT file. That will make your further life a little easier, believe me.

You could build separate subtitle files for as many items you need onscreen - be it time, distance, speed, elevation, etc. Please note that all the formatting - commas, spaces, units of measure, etc - should be done in these subtitle files, as you can't alter them later.

Next, you grab your favorite video editor and install a good plugin that is capable of importing subtitles onto the timeline - in my case, as I use Sony Vegas, this is a mighty Vegasaur - and I honestly believe this app is worth every dime of its price, but you could go about with a 30 day trial as well.

In Vegasaur you just select Text Generation Wizard and then Import Subtitles, select your SRT file for a particular item, assign it a preset that would give its visual appearance (font, size and screen position) and click Ok. Repeat this for all the items you want to appear onscreen. What you end up with will be a number of tracks that contains a bunch of video events, and these tracks will be longer than your existing video track, as these subtitles are realtime and have no pauses in them. Next, you have to sync these tracks with the video.

For syncing, I prefer a simple approach - you know, and usually can tell just by looking at the video track on the timeline, where your video recorder was paused/turned off. You can also tell when your car started moving just by looking at the track with generated subtitles - speed/distance/elevation will start to change. So for the pauses in the video recording, I just move the rest of the video to the right, creating gaps in the original video track, so that change in subtitles aligns with the moment video recording was resumed.

If you are careful enough, in the end you'll have two tracks - one with subtitles and one with the original video, having the same length (with some 10-20 seconds difference) and your video track will have spaces in it that correspond to pauses in your original recording. You can then ripple delete those portions of the timeline where you have no video, and you're done.

Comments

Popular posts from this blog

HP DL380 G7 won't power up after a power cord removal/power loss

ESXi 7.0/6.7 and MegaRaid on Alder Lake Asrock Z690M-ITX/ax

Accessing MegaRAID BIOS (WebBIOS, Ctrl-H) on consumer motherboards