Created
January 22, 2017 23:06
-
-
Save ubershmekel/d20e9d386bf73d47987c43da9c6e870a to your computer and use it in GitHub Desktop.
Concatenate a few video files into one with ffmpeg
This file contains 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
""" | |
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