Merging GoPro Segments Into a Single File

A 3 minute read, Posted on Thu, Mar 24, 2016 In Video
Tags video, tips, chocolatey, media, utility

If you have ever done a long recording with your GoPro you know that you will end up with several ~4GB files instead of a single video file. This can be very inconvenient if you just want to be able to watch the video start to finish, or if you want to apply effects (like de-shaker) across a file boundary.

If you are not familiar with file systems this may seem odd, but it is a well known limitation of the FAT file system which the GoPro, and many other small electronics, use for file storage. The FAT file system has been around for a long time and pretty much every OS out there can readily access the contents of a disk formatted with FAT, so it makes a good choice for a device that will be used by consumers. The downside is that FAT has a file size limit of about 4GB, this seemed huge back in the day when hard drives were not even half that size, but is a little lacking in todays world where we measure local storage often in terabytes rather than gigabytes. It is especially small in today’s world of HD (or 4k) video. Fortunately there is a solution once you get it on NTFS (or HFS on OS X) to make your video files all one again. The best part is there is no re-encoding, just re-wrapping of the existing encoded data into a new file, so it is quick and will not degrade your video.

First, you need to get ffmpeg, a free open source tool that handles a wide array of video encoding and decoding needs. It is very popular and the basis for many commercial video manipulation tools. Go over to their website to pick it up, or use a tool like chocolatey to install it in a breeze with the following command:

choco install ffmpeg

Second, make sure you have a little free space. you will essentially need double the size of your original files in free space for the process to complete.

Third, run the below series of commands to extract the original streams from your original file and then wrap them all together in a new file. I’ve included commands to cleanup the temporary extracted streams as part of the process.

ffmpeg -i "GOPR1234.MP4" -c copy -bsf h264_mp4toannexb a.ts
ffmpeg -i "GP011234.MP4" -c copy -bsf h264_mp4toannexb b.ts
ffmpeg -i "concat:a.ts|b.ts" -c copy -bsf aac_adtstoasc GoPro-1234-full.mp4
del a.ts
del b.ts

To add more files just add a new extraction line and add the new ts file to your final ffmpeg command

ffmpeg -i "GP021234.MP4" -c copy -bsf h264_mp4toannexb c.ts
ffmpeg -i "concat:a.ts|b.ts|c.ts" -c copy -bsf aac_adtstoasc GoPro-1234-full.mp4

You can add as many files as needed and playback will be as seamless as the contents of your video file are.

This has been very useful for me with my video editing to create a monolithic file that allows me to do video processing at any point without worrying about everything matching across file boundaries.

comments powered by Disqus