Timelapse: 3. Video Production

Tuesday, December 29, 2015

This is the final blog in the series on producing an inset map for a timelapse video (see also Geocoding and Map Production).

OK, so we now have all the photos time synced and geotagged, and produced the actual overlay of the route and current position on an inset map. The last stage is to render each photo with timestamps and location map and then produce the video.

Software

NConvert (as a command line programme you can use it in batch files)
XNConvert
Mencoder

1. Resize PNG

Resize the inset map PNGs so that they are the right size for the video you are producing. My photos were 500×666 (near DVD quality), and so I resized the inset map to 150×150 using NConvert:

nconvert -out png -resize 150 150 -overwrite *.png

2. Time Stamp Overlay

NConvert is meant to be able to do this step, but after several queries in the support forums it looks like the functionality hasn’t been added. Whilst in my earlier blog post I used XNView to add the metadata overlay, this can be performed used XNConvert which is just easier and more flexible for batch processing files. You can happily save the process you have created to reload it later on and also convert the process to an NConvert command (although it doesn’t support all commands yet).

I added the “Durness to Dover” strap line as one action and then the time stamp as another action. The formatting for the latter is of the form:

Day 01: {EXIF:Date [H:M]}

which ensures that only the hour and minute display. The font and position is fully configurable so experiment a little to make sure it’s what you want. XNConvert (helpfully) has a preview panel so you can see what it will render like.

3. Inset Map Overlay

The final set of photos takes the output produced in step 2 (the time stamp) and overlays the map on to it. For this I used NConvert again, however in this instance the command is more complex because for each input photo I want the matching inset map (which has the same name). NConvert doesn’t allow you to do this (it assumes just one overlay image) so some DOS batch processing was needed. I blogged about this a few weeks back (read that post to understand the command) and this easily solves the problem:

for /f %a IN (’dir /b *.jpg’) do ..\..\nconvert -out jpeg -wmflag bottom-right -wmfile overlay\%~na.png -o final\%~na.jpg %~na.jpg

The actual NConvert command is very simple, just placing the listed image in the bottom right corner and then outputting a new file.

3. Render MJPEG

This now uses Mencoder to produce the final MJPEG and is uploaded to YouTube to produce the mp4. You can then download this file for distributing to people. Just as a reminder (from this blog) the command is:

mencoder “mf://@list.txt” -mf fps=3 -o test.avi -ovc lavc -lavcopts vcodec=mjpeg:vbitrate=1600 vqmin=3

Remember that you will need to create the list.txt file to feed the input files in to Mencoder. Also remember to change the “fps” setting as this is the frames per second so depending what rate your camera was set at, this will need to change.

Below is a reminder of the final product. Phew!! All of this, bar the use of XNConvert could be batch processed making it a rapid process.

Universal Naked Driver

Monday, December 28, 2015

The first stage in replacing your stock Android phone, with a new ROM (for example CyanogenMod) is to replace the recovery partition on your device - for example here are the full instructions for my aging Moto e. When you attach your phone normally to a computer you need USB drivers to recognise it - and for the purposes of installing a new ROM you want to begin by using ADB to reboot your device to the bootloader. This is a pre-boot mode and gives you a number of limited menu options for your device. At this point you can change the recovery partition on your device using fastboot which can then be used to change the ROM (and so version of Android).

I was looking to put an unofficial port of CyanogenMod 11 (aka Android 4.4) doing this for my son’s ZTE Kis3 (cheap and chearful but extremely serviceable ZTE phone), however whenever I rebooted it to the bootloader it wasn’t recognised by my Windows PC. After a fair amount of searching I discovered two things:

1. the ZTE drivers clearly don’t support USB when rebooted to the bootloader
2. the drivers for fastboot should be *generic*

The latter is really helpful for this and potentially in the future - and led me to the Universal Naked Drivers which do what they say on the tin. *However* one big caveat is that they are unsigned and Microsoft (understandably) has made it very difficult to install unsigned drivers. So…. watch this YouTube demo that explains how to install them.

Worked for the ZTE Kis3 and the subsequent install of CM11.

Timelapse: 2. Map Production

Thursday, December 24, 2015

This is the second in the series on creating map overlays for timelapse videos from a series of photos. With all the photos now time synced and geotagged, the next step was to produce the actual overlay. And the end result was going to be this:

1. Base Map Preparation

Initial processing and map preparation was undertaken using QGIS. I needed a donor outline of the UK so went for the relatively lightweight worldborders. I then created a new shapefile, digitized around the UK and used this to clip the UK out of the world dataset. This dataset was then projected to British National Grid and finally converted in to a GeoTIFF.

2. Moving marker

Generating the moving marker was the bespoke part and Python the solution! With my Python being a little rusty I asked my colleague Niels Anders if he could rustle up some code to handle this. First things first, what were the Python settings??

Well we used WinPython 2.7.6 (great because it runs as a portable app) with the following libraries: Gpxpy, Pyproj and gdal (which includes ogr). As I noted earlier this month, the latest version of WinPython has Pip integrated which makes installing extra libraries a breeze. Just type “pip install ‘library’”. The only one that didnt work for me was pyproj. In this case you can download the pre-compiled Gohlke binaries. Download the cp27 version (Python 2.7) for either 32 or 64-bit. Then type:

pip install pyproj-1.9.4-cp27-none-win_amd64.whl

You should now be in a position to run the Python script (which we’ve called “timelapse”) which you can download below.

This accepts three inputs: the basemap as a GeoTIFF, a shapefile of the route and a CSV of the image names/coordinates (as exported from ExifTool). So it would look like:

python timelapse.py ‘tif’ ’shp’ ‘csv’

Such as

python timelapse.py uk.tif route_new.shp coords_master.csv

This outputs as directory of images with the same name as the photos to a “png” subdirectory. The basic workflow is as follows:

1. Check if png folder exists and if not, create it.

2. Load basemap geotiff (assumed to be in BNG)

3.Read SHP route tracklog (as WGS84) and convert to BNG

4.Read CSV that contains WGS84 coordinates for the photos

5.Iterate over each photo coordinate:
a. Project lon/lat to BNG and add to route arrays (x, y)
b. Extract of GOPRO image
c. Create axes and plot:
- basemap (masking out UK to create a transparent backgroun) - entire route (in gray)
- route finished so far (in red)
- current location with a marker
- optimze axes (force equal scale of x,y axes, remove outer box, set extent to min/max x,y)
d. Save as ‘filename’.PNG in the png folder
e. Clear axes for next iteration

This gives us a black map with transparent background, a grey route, a red dot for the current location and then a red route for amount completed so far.

The final installment will taken all these elements to produce the final timelapse.

FAT32 Redux

Wednesday, December 23, 2015

My earlier blog on exFAT reminded me that, as a general principle, Android devices can’t access that filesystem (although there are some devices that have OEM support for it and some third party add-ons). That’s why microSD cards are formatted to FAT32 - Android, Windows and Mac can all access them. Of course, we then hit the 32Gb limit which is of course why all devices are listed as having this as the maximum external storage. But this is a FAT32 limit, not one imposed by the hardware. The simple solution is to use fat32format which gives a much higher limit. In fact, to quote from the page:

“Note that the 32GB limit is a limit of the formatter in Windows XP. FAT32 itselft should be OK to 2TB.”

hard to believe that the format command is the root of so much misinformation. Anyway, buy yourself a cheap microSD (£12!) and voila you have 64Gb of external storage. Something that Apple charges a premium for if you have it is internal storage.

SpaceX Successful Landing

Tuesday, December 22, 2015

I blogged earlier this year about SpaceX’s nearly successful (or failed, depending upon your point of view!) attempted at a vertical landing of the first stage of their Falcon 9 rocket. This time they were successful and, to boot, launched 11 satellites in to space as well. Makes for a great party piece!!