Last active
December 6, 2021 16:08
-
-
Save dougboutwell/d8d340151b8a2b63a730d24ba8cc1e5a to your computer and use it in GitHub Desktop.
Join 4GB GoPro chapter video files into a single file with ffmpeg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script to join GoPro video files, which are split at 4GB boundaries, into a single file | |
import os | |
import glob | |
import subprocess | |
# sleazy case-insensitive list of mp4 files in this dir | |
filepaths = glob.iglob("*.[mM][pP]4") | |
filenames = list(filter(lambda f: os.path.split(f)[1], filepaths)) | |
# extract unique clip numbers from list of all files in this dir | |
clip_numbers = set() | |
for f in filenames: | |
f_no_ext = os.path.splitext(f)[0] | |
clip_numbers.add(f_no_ext[-4:]) | |
for clip in clip_numbers: | |
# create a text file listing the video files for each clip, in sorted order | |
clip_files = sorted(list(filter(lambda f: clip in f, filenames))) | |
with open("video_list.txt", "w") as vf: | |
for f in clip_files: | |
vf.write("file " + f + "\n") | |
# execute fmpeg based on https://askubuntu.com/q/1342540 to join | |
cmd = ["ffmpeg", | |
"-f", "concat", | |
"-safe", "0", | |
"-i", "video_list.txt", | |
"-c", "copy", | |
"GoPro" + clip + ".mp4" | |
] | |
subprocess.check_call(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment