I recently took a family vacation from St. Louis, MO to Branson, MO, and as it was the first time driving with my new Mobius Action Cam Mini dashcam installed on our Toyota Sienna (see a full writeup and review here), I wanted to see if I could quickly whip up a time lapse video of the entire drive.
A tiny snippet of the final time-lapse video of my STL to Branson drive.
While the Mobius has the ability to do time lapses built-in, doing so would require me to choose between either having a time lapse or recording continuous 30fps video. And for insurance purposes, a timelapse with only a frame every second or two would not be that helpful!
So, knowing that my Mac can do many powerful things, I thought it might be able to do the following:
- Take a folder of 3-minute 1080p video clips at 30 frames per second straight from the Mobius Action Cam
- Speed up the clips to turn them into a proper time lapse (~5x or ~10x speedup).
- Merge all the clips into one, much more compact, time lapse video of the entire trip.
As an experiment, I wanted to just grab two files, speed both up, and merge them—after success there, I'll go on to automate the batch process for an entire directory of videos!
Speeding up two videos
I grabbed the first two videos in a series of videos from our trip, and put them on my desktop. Then I did the following to get ready to speed up the videos:
- Open Terminal (in Applications > Utilities)
- Install ffmpeg (using Homebrew):
brew install ffmpeg
- Change directories to the Desktop:
cd ~/Desktop(where I have two videos,
For each video (MOV format, straight from the Mobius Action Cam, 1080p, mono audio), I ran the command:
ffmpeg -i REC_0007.MOV -vf "setpts=0.05*PTS" -an SPEEDY7.MOV
8 to speed up the second video.
What this command does is grabs the input file (
-i), sets the Presentation TimeStamp to
[value]*[current PTS], which is a fancy way of saying "make the video much faster—in this case 50x faster, with a value of
0.05, and then store the re-encoded file in the same directory, with a different name.
Merging two videos
With both videos considerably faster (50x) and smaller (~30 MB instead of ~400 MB), I wanted to merge the two to make one continuous video (since the Dash cam was configured to split clips in 3 minute increments, this is a necessary step if you want any kind of continuous viewing experience).
So, to merge the two clips, since they weren't in a format that allows direct 'concatenation' (e.g.
ffmpeg -i "concat:SPEEDY7.MOV|SPEEDY8.MOV" -codec copy compilation.mov), I had to first create a text file that included one line for each clip, with the filesystem path to the clip (I called the file
Note: If you don't use individual filenames (e.g. if you want to use a path like
/path/to/file.mov), then you will need to add the
-safe 0option before the
-iin the following command, otherwise you'll see an error like
Unsafe file name '~/Desktop/SPEEDY7.MOV' ... concat.txt: Operation not permitted.
Then I ran
ffmpeg's command to concatenate videos based on a text file:
ffmpeg -f concat -i concat.txt -c copy compilation.mov
After running this command, I ended up with one video, but there were a few frames of a gap between the two which didn't look that great. I realized that the Mobius Action Cam sticks about an extra second from the previous clip at the start of the next clip... so I need to remove the duplicate frames after the initial clip speedup process but before concatenation using the
-ss option ('seek' to position—thanks to this Super User answer for the tip!):
ffmpeg -i SPEEDY8.MOV -ss 00.12 -an SPEEDY8-fixed.MOV
I used a value of
00.12 because I wanted to remove the first three frames of the video after it had been sped up, and ffmpeg only accepts values in HH:MM:SS.SS (in this case, we have 30 fps, and want to remove two frames, so we need to seek to
00.12 seconds (.03 seconds per frame) after the sped up video is written to disk. I also tried using
-ss 01.03 to remove the first 31 frames of the video prior to speeding it up in the first command (e.g.
ffmpeg -ss 01.03 -i REC_0007.MOV -vf "setpts=0.05*PTS" -an SPEEDY7.MOV), but this resulted in a couple 'junk' frames at the beginning that made the concatenated video have a stutter where the two clips were joined.
Compare by viewing the following video files:
I ran that command over both files, then concatenated them again, and now I have a much nicer clip! Now that I've proven I can do this programmatically, the next step is to automate the process so I can process and combine hundreds of videos for a long trip (a 4 hour drive generated almost 100 3-minute clips!).
Batching the process
I'm an advocate for automating all the things, and mundane tasks like re-encoding and concatenating dozens or hundreds of clips is the perfect candidate for automation! I spent some time wrapping all of the above commands into a flexible
dashcam-time-lapse.sh shell script, which I've posted as a Gist on GitHub:
That gist will be updated over time as needed, and I may be able to spend a little more time working on the CLI UX—for now, pop in your dashcam's memory card, adjust the variables at the top of the file, then run the script, and some time later, you'll end up with a file of sped-up footage from a recent drive!