Timelapse: 3. Video Production

Tuesday, 29 December, 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.


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

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, 28 December, 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, 24 December, 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, 23 December, 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, 22 December, 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!!

Timelapse: 1. Geocoding

Monday, 21 December, 2015

Following on from last week’s blog, the first stage in putting together the timelapse video with inset map is to geocode the photos. This post entirely uses the quite remarkable ExifTool for manipulating photo EXIF data that’s embedded within images. It’s fast, has extensive capabilities and is very well supported. it’s command-line only although there are numerous front-end GUIs for it, including both Geosetter (which I’ve mentioned before) and ExifToolGUI. That said, for processing the large number of images for a timelapse it’s much easier to use the command line.

GPS tracklog

1. Timeshift

Step 1 is to timeshift your images. All location information is stored in the GPS tracklog, however because GPS uses the extremely accurate clocks on board the individual satellites to calculate position, the log also stores time. They are usually supplied as GPX (GPS Exchange Format) files which are standardised XML files for GPS data transfer. Most GPSs natively support this now, but if you have an older device you may need to convert to GPX. GPSBabel should be able to handle this for you.

This stage is critical in order to synchronise the time tagged in the EXIF data of the photos to the GPS. The GPX files often record speed as well, so I scan through the GPX file (its text) looking at the start of the data when speed goes above 0 mph. That’s the start of the ride and, within a few seconds, your first photo. Write that down! Now load the first photo and look at the EXIF data (I use Xnview) “Date Modified” tag (in fact several dates can be recorded in the EXIF data, but we’ll be setting them all the same) and write it down. Now check whether those two dates are the same - if they’re not then you need to timeshift your photos. My GoPro had reset itself to the default firmware date of 1 January 2009.

You now need to calculate the time between two dates. I’ve used this website although Excel can do it as well. My images were 866 days, 18 hours, 26 minutes and 25 seconds out!!! The ExifTool command to timeshift this is

exiftool -AllDates+=”0:0:866 18:26:25” .

(the period tells it to process all files in the current directory). If you are doing a multi-day event then all your photos may or may not be consistently out. It turned out the camera reset its clock again halfway through so I then needed to use a different timeshift value. And, then, on two further days there were sections were the clock was wrong. Not sure why but it needed fixing.

2. Geocode

With the photos now correctly timestamped you can geocode the images. ExifTool is pretty clever here in that it reads the time, scans the entire GPX file finding the nearest times before and after the photo and then linearly interpolates between the two GPS locations based upon the time offset. It then writes this information back in to the EXIF data. It also has the option (geosync) to cater for timezones (as GPS uses UTC). The command here is:

exiftool -geosync=+01:00:00 -geotag ..\18_raw.gpx .

3. CSV Output

With all the photos geocoded the final stage, ready for creating the inset maps, is to produce a file listing with all photo coordinates. ExifTool can again do this:

exiftool -csv -n -filename -imagesize -gpslatitude -gpslongitude ./ > coords.csv

Later this week I’ll cover creating the inset maps and then combining all the elements together to produce the final video.

Timelapse: Creating an Inset Map

Friday, 18 December, 2015

Last month I blogged about an update to my workflow for creating a timelapse and particularly adding overlays (both graphics and text from EXIF data) and solving problems with dates being out-of-sync by timeshifting them.

Well that flurry of activity made me think about the data I collected for my Durness-to_Dover bike ride. For that I used a GoPro attached to the front of my bike and took a photo every 30s along the entire ~800 mile route. I turned those in to straight timelapse videos and thought nothing more of it until recently. In tandem with the photography my biking partner had a cycle satnav with our route planned on it that also kept a tracklog of the route we actually took. What struck me was that the GPS tracklog would have had the correct times stored in it and that I now knew how to timeshift the images. A further look at ExifTool showed that it could not only write coordinates in to the EXIF headers of the photos, but also read the tracklogs straight out of the GPS, find the nearest points based upon time and interpolate between them to give a very good estimate of actual position.

Critically then I was now able to use the tracklog to timesync the photos and geocorrect them. What I thought would could now do was:

1. Time Overlay: insert the time of the photo, having that increment through the video
2. Inset Map: create an inset map with a point showing the position of the photo. This would then animate over the video, moving as day progressed.

Over the next few posts I’ll outline how I built this up (with a little help!), but below is the end product, so you can see what the final result was!

[The Urban Age Project]

Wednesday, 16 December, 2015

Wanted to point people in the direction of a friend of mine back from the dim distant days of my PhD in Sheffield - Paulo was on a funded PhD from Brazil and I distinctly remember working long hours in the remote sensing lab, with “After 8” breaks in the afternoon.

Anyway, enough nostalgia!! Paulo works as an engineering geologist in the government, but has reduced the number of hours to allow him to work more as a musician. The soundcloud embedded player below links to his latest EP, URBANA IDADE. If you like Satana, then this is very much in that style. I particularly like tracks 1 and 4, with some cracking guitar riffs. Great for an evening of mellow chill.

Getting FATter

Tuesday, 15 December, 2015

Three years ago I blogged about using FAT32 beyond the 32Gb limit to format large external drives. The rationale for this was to have an disk file system that worked across operating systems and didn’t run in to the complete drag that is NTFS file permissions.

Well step forward three years and my 500Gb drive is starting to be (very) full and needed upping to 1Tb. That and my increasing need for security meant going in search of something more secure for my external drive - the iStorage diskAshur fitted the bill perfectly with a keypad locked drive, real-time Hardware encryption (256-bit AES) and some shock protection. Great bit of kit and only a little pricier. But…. what file system to have??

Well the reason for moving on from FAT32 was the limit to maximum filesize (4Gb) which is easily exceeded with satellite imagery or virtual machines. NTFS, as I note above, is just painful for file permissions and isn’t really needed for an external drive which has hardware encryption. Well, as it turns out the answer was staring me in the face - exFAT which is essentially FAT64. OK, so its a proprietary Microsoft file system, but solves the filesize limit, is relatively simple and fast, ideally suited to external media and particularly flash drives, but perfectly suited to this use. Compatible with add-ons to Windows XP and MacOS, whilst there appears to be driver support for Linux. Given 99.9% of the time I move between Windows systems that suits me.

So, 500Gb of data transfer later I now have an operational drive. Just got to move the other backup disk from 500Gb to 1Tb…

DOS For loop for iterating

Sunday, 13 December, 2015

I’m currently working on a pet project doing some timelapse (if you hadn’t guessed!) involved geocoding the photos (and a much longer blog on this process at a later date once it’s complete). However as part of this I needed to iterate over a series of files using the excellent nconvert. DOS batch files let you do this but the syntax (for me at least!) is a little confusing. So, in all it’s glory here’s the solution I rustled up after looking at various websites:

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

As ever, much useful information can be gleaned by typing

for /?

The /f parses a list of files (denotes by the variable %%a) and this is fed to it by the ‘dir /b *.jpg’ command. In this case a “bare” directory listing of all JPG files. Once that is complete it runs the nconvert command inserting the variable at the %%a locations.

Crucially the statement is then finished with \%%~na.jpg which strips the file*name* from the 3-letter filetype (suffix). This is needed in the nconvert command.

One line of code, 1000 files processed very rapidly! Love it when this stuff works!!