Use FFmpeg to Combine GoPro Clips, Generate Time-Lapse Movies
My wife gave me a GoPro Hero last Christmas and I love it more than I thought I would. I don't love GoPro's editing software as much and I'm not alone when I say that GoPro Quik doesn't live up to the hype. Most of what I want to do is combine clips and post them to Facebook, Instagram, and YouTube. I'd also like more control over time-lapse quality and settings. Fortunately, FFmpeg provides all the tools needed to accomplish this, and more.
You'll need to be comfortable working from the command line to install and use FFmpeg. On macOS and OS X this means getting familiar with the command line using Apple's Terminal.app.
If you're new to the command line, check out these tutorials:
- Beginner's guide to the Mac OS X Command Line (Terminal) - Free course from Udemy (includes video)
- Mac OS X Basic Command Line Tutorial - YouTube - Nice video overview
- Introduction to the Mac OS X Command Line - Excellent article with screenshots
- Getting to Know the Command Line - Nice beginner-level article
Important Note! Heed warnings in these tutorials, especially those regarding the rm (remove) command!
Once comfortable with the command line, here are a few FFmpeg installation tutorials. Both use the de facto OS X package manager, Homebrew, to install and configure FFmpeg.
- Install FFmpeg on Mac OSX - Simple three-step Homebrew installation tutorial
- How to install FFmpeg on Mac - More in-depth installation video
A Word About These Commands
FFmpeg has a lot functions and features, most of which I'll likely never use or fully understand. Many of the commands included in this article are provided as is. I don't explain what every option used is or what it does and encourage you to Google those parameters your don't understand or don't work quite as you expect. FFmpeg's documentation is pretty good and there are always others who go into more depth about how to use FFmpeg's features.
Combine Individual Clips Into One Movie
GoPros split longer videos into multiple clips that need you'll need to combine into a single movie. The settings on my Hero 4 produce 1080p clips up to 12 minutes long and 2 GB in size. Why? Partly to minimize the impact of data corruption and partly due to SD card file system limitations. David Coleman provides a more in-depth explanation about this and lots of other GoPro-related topics on his web site.
I recently captured a motorcycle ride which was saved to four movie files. To combine them with FFmpeg fire up Terminal.app and
Changed directory to where my clips are saved.
cd /Users/username/Movies/GoPro/YYYY-MM-DD/HERO4 Session 1
Generated a text file containing a list of the files.
printf "file '%s'\n" * > clips.txt
The generated file clips.txt contains a list of of the files, from oldest to newest:
file 'GOPR2185.MP4' file 'GP012185.MP4' file 'GP022185.MP4' file 'GP032185.MP4'
Ran FFmpeg with the 'concat' option to combine the clips into a new movie file.
ffmpeg -f concat -i clips.txt -c copy ReddingtionFromAZTrail_combined.mp4
I decided that I wanted to trim the combined video to cut everything after the 34:30 mark. The following command copies the first 34:30, or 2,070 seconds, to a new file maintaining the original movies video and audio codecs.
ffmpeg -i ReddingtonFromAZTrail_combined.mp4 -t 2070 -codec copy ReddingtonToAZTrail_trimmed.mp4
Running something like the following will extract a clip from a movie. The following command will pull a 48 second excerpt from the 51 minute mark of a movie.
ffmpeg -ss 00:51:00 -t 48.0 -i Movie.mp4 -c copy MovieExcerpt.mp4
Doug Mahugh goes into more detail with FFmpeg's trim capabilities on his web site.
Convert a Movie to a Time-Lapse Movie
The final thing I'd like to do is generate a time-lapse to post to YouTube. The following command generated a 13 minute and 11 second long time-lapse movie from the trimmed 34:30 file. The lower the presentation timestamp (PTS) value, the shorter the time-lapse movie. I believe the 0.5 setting here is equal to the GoPro's default time-lapse setting a frame every half second. Although I haven't done exhaustive comparisons, the FFmpeg time-lapse movies I've made from regular GoPro movies seem smoother than GoPro's generated time-lapse movies.
ffmpeg -i ReddingtionToAZTrail_trimmed.mp4 -filter:v "setpts=0.5*PTS" -an ReddingtonToAZTrail_timelapse.mp4
Here's the final time-lapse clip of my motorcycle ride.
Combine GoPro Time-Lapse Stills Into a Movie
FFmpeg can also combine individual JPEG files from GoPro time-lapse captures to generate a movie. From the terminal, change directory to where your GoPro time-lapse photos are and run the following to generate an MP4 timelapse.
ffmpeg -r 15 -pattern_type glob -i '*.JPG' -vf "scale=1920:-1" -vcodec libx264 -preset veryslow -crf 15 -pix_fmt yuv420p Timelapse1.mp4
Micscellaneous FFmpeg Tasks and Commands
As I think of additional things I want to do with FFmpeg, I'll add the commands I've used here.
Convert an AVI to an MP4
I have trail cam that saves movies to AVI format. Instagram doesn't accept AVI so I use the following to convert them to MP4.
ffmpeg -i IMAG1118.AVI -c:v libx264 -crf 19 -preset slow -c:a aac -b:a 192k -ac 2 IMAG1118.mp4
If that doesn't work, try the following:
ffmpeg -i IMAG1118.AVI -c:v libx264 -crf 19 -preset slow -c:a libfdk_aac -b:a 192k -ac 2 IMAG1118.mp4