Since YouTube provides effectively unlimited video uploads, I have been archiving all of my dash camera footage there. To prevent the chance of data corruption, dash cams often split long recordings into smaller files as they are recorded. This way, if a file is corrupted, it only affects a small chunk rather than the entire recording. My dash cam only supports chunks up to 10 minutes in size, far shorter than my typical drive. For the sake of organization, I want my segments combined into a full-length trips so that I have one trip per video upload. There are some solutions already available online, but none of the existing tools met my needs. Implementing the desired segment joining was simple enough, so I wrote my own script. At a broad level, it works by leveraging FFMPEG's concat feature. It is tested on Windows, but should work on any platform with FFMPEG and Python 3. I would have added YouTube upload API support as well, but a policy established several years ago to cut down on spam forces all videos uploaded through the API to always be private. The full script I wrote can be found below.
"""This simple Python script is designed to seamlessly concatenate dash camera
footage segments into a single clip via FFMPEG.
INPUT_FOLDER = "./raw/"
OUTPUT_FOLDER = "./concat/"
FFMPEG_PATH = "ffmpeg"
SEGMENT_LENGTH = 2 * 60
EXTENSION = "TS"
num_files = len(files_list)
if num_files == 0:
elif num_files == 1:
path = OUTPUT_FOLDER + os.path.splitext(files_list.name) + ".TS"
path = OUTPUT_FOLDER + os.path.splitext(files_list.name) + "-" \
+ os.path.splitext(files_list[-1].name) + ".TS"
file_contents = ""
for file in files_list:
file_contents += "file '" + file.path + "'\n"
with open("./mylist.txt", "w+") as f:
os.system(FFMPEG_PATH + " -f concat -safe 0 -i mylist.txt -c copy " + path)
with os.scandir(INPUT_FOLDER) as unsortedFiles:
files = 
for file in unsortedFiles:
if not file.path.endswith("." + EXTENSION):
files = sorted(files, key=lambda e: e.name)
time = 0
old_time = 0
files_list = 
for file in files:
old_time = time
time = os.stat(file, follow_symlinks=False).st_mtime
if time > old_time + SEGMENT_LENGTH:
if __name__ == "__main__":