GoPro cameras have a tendency to split large video files into multiple parts. I wanted to find a way to losslessly merge these video files into one file. I found a guide by Jeff Geerling that shows how to perform this operation using ffmpeg. While his commands do achieve the desired file merging behavior, I found that the rotation metadata that GoPro stores in the files was getting lost. This meant that after the merge, my video file would not be properly flipped/rotated according to how I had the camera orientated.
Here’s a quick example of how I extending upon his commands to correct for the metadata lose.
# create temporary stream files to help with concatenation
ffmpeg -i GH010045.MP4 -c copy -bsf:v h264_mp4toannexb temp0.ts
ffmpeg -i GH020045.MP4 -c copy -bsf:v h264_mp4toannexb temp0.ts
# concatenate (merge) video files into one
ffmpeg -i "concat:temp0.ts:temp1.ts" -c copy -bsf:a aac_adtstoasc merged.mp4
# save & restore metadata to preserve rotation and other info
exiftool -args -G1 --filename --filesize --directory --duration GH010045.MP4 > metadata.txt
exiftool -@ metadata.txt -sep ', ' -api largefilesupport=1 -overwrite_original merged.mp4
I made gopro_merge.sh to help automate the above steps. In a terminal, simply run ./gopro_merge.sh part1.mp4 part2.mp4 part3.mp4
and it will spit out the merged file automagically!
-Dan
Load Comments