Timelapse: 3. Video Production

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 500x666 (near DVD quality), and so I resized the inset map to 150x150 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

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

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

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

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

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.

Pre-Requisites
GPS tracklog
photos

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

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]

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

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

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!!

EA LIDAR DEM Coverage

A little while back I blogged about the release of the EA LiDAR DEMs for the UK - well a nice pickup from GoGeo for a coverage map of the data.

Pippity Pip

I was using the CLustre code recently for analysing some lineaments and it reminded me to update to the latest version of WinPython (which I covered at the AGI). currently at 2.7.10.2. This necessitated reinstalling the libraries needed for CLustre which include numpy, scipy, matplotlib and gdal (which includes ogr). All bar the last are now part of the distribution, so that meant just an install of that.

And that has got a whole lot easier as pip (Python package installer) is now included by default. So just issue this command:

pip install gdal

And if that doesn’t work for some reason (possibly because it has to compile the code), then you can download the pre-compiled binaries from the Unofficial Binaries site (and remember to select either 64 or 32 bit version and the cp27 version if you are running Python 2.x). Then use this command:

pip install GDAL‑1.11.3‑cp27‑none‑win_amd64.whl

Life just gets easier and WinPython is great in that it’s portable.

Space Placements in INdustry (SPIN)

I missed this last year, but it’s well worth flagging to all undergraduates as a fantastic way to get industry experience - Space Placements in INdustry (SPIN). As they say on their webpage:

“The Space Placements in INdustry scheme (SPIN) has been designed to provide an introductory link for undergraduate students considering employment in the space sector and space sector organisations looking to find the most talented and enthusiastic people to ensure the future success of their businesses.”

The programme takes students in their 2/3 or 3/4 year of an undergraduate degree and work over an 8 week duration, being paid on the job. The 2016 round will open shortly so keep your eyes on the website.

DOS file listing

Need to get a plain and simple file listing from the command line in DOS to pipe in to a programme??

As ever a good starting point is to get help for the command. So:

dir /?

If you peruse through this you’ll eventually work out that this is the command you want:

dir /a-d /b > ..\list.txt

The “>” symbol sends the output and stores it in a file. Make sure to specify “.." before the filename so the file is saved in the directory above the existing one otherwise that file will be listed as well. And if you want to sort on (for example) filename then you add the “\on” switch:

dir /a-d /b /on > ....\list.txt

This will now save me looking that command up everytime!

Visualisation Update

Following on from my neogeography/big data blog Edoardo L’Astorina at Blu Frame (web designers) contact me to note a review he’s recently completed on 20 online visualisation tools. And it’s a useful review and worth a look to see where things are at.

Repost: Cartographer’s Toolkit

A really nice blog translating and re-posting visual thresholds when viewing graphical features (for cartography). Useful.

Journal of Maps Best Map 2015 (FREE to view)

It is with great pleasure that I am able to announce the award of the 2015 “Best Map” to Vít Pászto, Alžbeta Brychtová, Pavel Tucek, LukᚠMarek and Jaroslav Burian (Palacký University) for their map using fuzzy logic to delimit rural and urban areas in the Czech Republic. Traditional Boolean approaches to municipality classification do not reflect reality and so the authors used seven indicators to compute the final fuzzy membership in terms of urbanity/rurality.

The awards committee noted the unique method of classification, effective choice of colours and good symbolization. For these reasons it is a deserving winner of this year’s award and will be available through the Journal of Maps website as a limited print run.

FREE EPRINT: Editorial: summary of activities 2015

Smith, M.J. (2016)
Journal of Maps


What is a map? A seemingly innocuous question that is deftly handled by the International Cartographic Association (ICA, 2015) as

“a symbolised representation of geographical reality, representing selected features or characteristics, resulting from the creative effort of its author’s execution of choices, and is designed for use when spatial relationships are of primary relevance.”“

Timelapse: timeshift your timestamp!!

AS I noted in my previous blog entry, if you forget to set your time/date on your camera and its wrong, you need to reset it in order to get XnView to pull our this metadata and overprint it on your JPGs. If you’ve got more than 1 or 2 to do (I had about 4000!) then you need an alternative…

And here the amazingly complete ExifTool does a brilliant job. For all things EXIF look no further. It’s power is fully opened up in the command line version (rather than the drag and drop). And yes- it supports a timeshift facility.

For the images I had, the camera had been dead for several months so when a battery was put back in it reset the time/date to a default value. All subsequent images were therefore out by the same offset. I ignored the days as I wanted a time overstamp. Running the command:

exiftool -AllDates+=12:18:28 .

worked perfectly. This instructs exiftool to shift forward all time fields by 12 hrs 19 min 28s. More details here. Job sorted.

Timelapse Update

A little while back I blogged about producing a timelapse. That sorted out all of the main issues I had with setting a camera up and leaving it to record a timelapse of a scene.

However I was recently reminded that my daughter had taken a series of daily photos back in in 2010 over an 8 week period whilst a new canteen was built at her school. It was a camera project and something we could use to look back on. All the photos were hand held (and under a range of different times of day and lighting conditions) which created a challenge to producing a timelapse. Most particularly frames were not aligned so I filed the photos under “must do someday”.

Well that day arrived last week!! I realised that the excellent PTGUI which we used on the Studio of Objects project to produce the 360 panoramas has a module that performs image alignment. Now obviously I didn’t want to stitch those photos together (because they would all sit on top of each other!!), but I did want to align them. PTGUI puts the images in to layers and looks for high contrast points between layers to match them. This it did (bar one which I handled manually) and you can then export each layer separately.

Voila a set of aligned images! What this showed was that some of the images were only partially overlapping. Back to the excellent XnView where I specified the crop I wanted and batch processed the images. I now had an aligned timelapse.

I finally did a little bit of experimentation…

1. Colour Toning: I tried “auto-levels” and “auto-contrast” in XnView to try to help colour balance/tone the images. This kinda worked a little bit, but colour toning is complex and doing it across such a diverse range of images very difficult.

2. Overlay: I also wanted to overlay the date and an logo on to the timelapse. XnView has a fabulous overlay facility (“add text”!) which allows you to pull in information from the image itself. The EXIF data in the JPEG had the date and time of exposure, so I changed the font and then added the date to the lower left corner of the frame. After batch processing the images I then realised about 8 images had the wrong date - a friend took photos whilst we were away on holiday and had replaced the batteries in the camera but not reset the date. I thought changing the date in the EXIF header would be easy - but XnView doesn’t do it. That led me to the portable Geosetter which allows you to change a range of image headers including the date. The final step was to add the school logo (“watermark”) and we were done.

Not going to set Hollywood on fire, but satisfying!