Skip to content

Instantly share code, notes, and snippets.

@ubershmekel
Created January 22, 2017 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ubershmekel/d20e9d386bf73d47987c43da9c6e870a to your computer and use it in GitHub Desktop.
Save ubershmekel/d20e9d386bf73d47987c43da9c6e870a to your computer and use it in GitHub Desktop.
Concatenate a few video files into one with ffmpeg
"""
Concatenate a few video files into one with ffmpeg
Use a wild card
"""
import subprocess
import glob
import re
to_concat = 'robocar*'
def natural_key(string_):
"""See http://www.codinghorror.com/blog/archives/001018.html"""
return [int(s) if s.isdigit() else s for s in re.split(r'(\d+)', string_)]
files = glob.glob(to_concat)
files = sorted(files, key=natural_key)
with open('tmplist.txt', 'w') as out_fh:
for fn in files:
line = "file '%s'\n" % fn
out_fh.write(line)
cmd = 'ffmpeg -f concat -safe 0 -i tmplist.txt -c copy output.mp4'
subprocess.check_call(cmd, shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment