Road-trip time-lapse

 A while ago I bought my second action camera, this time I made sure it could do a time-lapse video (something the first one I bought was not capable of). Anyway, the camera sat on a shelf for more than a year. But during the summer holidays, I was doing a trip and I thought it would be cool to create a hyper-lapse of my drive.

As usual, things went wrong when I was about to fix the camera to my car's windshield: it was not possible to fix it properly oriented, so the camera did the recording upside-down. I was not sure I could easily rotate the recording but I was positive I could rotate images so I decided to record the time-lapse as a sequence of JPG pictures. I checked there was enough memory available on the SD card and I connected the USB cable from the camera to one of the car's USB power sockets. 

I stated the recoding and drove away. I could see the camera was doing its job and then I entirely forgot about it until we arrived at our destination four hours later.

Once I removed the camera I realized the camera was no longer on: Apparently, the USB socket only provided power to the power wires and the camera did not detect that as a suitable supply so it was running the whole time on battery power. Now I was expecting the recording to have stopped much sooner than our trip end, as the battery only lasts for less than one hour while recording. 

A quick check revealed that the SD card was in fact full of files. It seems the average size of the JPG was larger than expected and the picture files filled up the available memory only seconds before our trip was over. So nothing seemed to be lost, phew!

So the next part was to turn these picture files into a movie. For that purpose, I have used it in the past mencoder software. While it is not user-friendly and a command-line tool, it has always proved to be just a few google searches away to be useful and it has always served me well. 

But before using it, unless I wanted my video to be upside-down, I needed to rotate all the pictures. All the thirteen thousand of them! I was using a Mac and I looked for a tool to do that with thousands of pictures at once. That is something that Preview can do. But it can do that 90 degrees at a time. And there is where my troubles started. I rotated the images twice and that only worked for some of them. Now I have a set of untouched images, while some other images were rotated 180 degrees. Some new files, possibly temporary files did appear on my folder too. 

Now I panicked as the files on my computer were the only ones available as I had formated the SD card for a new project. 

The next day, I looked more carefully and realized that I could use the date of the files to tell apart those that have been rotated, and thus have a newer date, and those that were untouched and thus have a much older date. 

The next stop was to get a command-line tool, like ImageMagick, that can do the job of rotating the pictures one by one. It was a simple but time-consuming installation using Homebrew

Once I have it installed, I made a list of the files that were still pending of being rotated and I used a for loop to go through all of them with the command mogrify -rotate 180 $filename

And once I had all the picture files with the proper orientation I could create a video using mencoder mf://*.jpg -ovc lavc -o video.avi

But, as you may guess that will not render a good quality video, as the source is a collection of frames that are too far apart time-wise (frames are taken each second). So the defaults create a very poor but operational video. It is also quite small. But to get a better result, a bit more love is needed on the command-line.


You can watch it in 4K for the best image quality.



It turns out there is a built-in command in macOS for command-line processing called sips :-)

Comments

Popular posts from this blog

VFD control with Arduino using RS485 link

How to get sinusoidal s-curve for a stepper motor

Stepper motor step signal timing calculation