Skip to content

Instantly share code, notes, and snippets.

@codewings
Last active October 14, 2022 13:47
Show Gist options
  • Save codewings/d813d8ed1b556d2be4f206c7abfc56b6 to your computer and use it in GitHub Desktop.
Save codewings/d813d8ed1b556d2be4f206c7abfc56b6 to your computer and use it in GitHub Desktop.
ffmpeg_concat.py
import os
import re
def sorted_alphanumeric(data):
convert = lambda text: int(text) if text.isdigit() else text.lower()
alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ]
return sorted(data, key=alphanum_key)
cwd = os.path.dirname(os.path.realpath(__file__))
os.chdir(cwd)
videos = []
for f in os.listdir(cwd):
fname, extname = os.path.splitext(f)
if extname == ".mp4":
videos.append(f)
videos = sorted_alphanumeric(videos)
index = os.path.join(cwd, "list.txt")
with open(index, 'w') as fwriter:
for v in videos:
fwriter.write("file '{}'\n".format(v))
name = os.path.basename(cwd)
os.system("/path/to/ffmpeg -f concat -safe 0 -i {} -c copy {}.mp4".format(index, name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment