Add autocat.py.

This commit is contained in:
voussoir 2020-01-19 10:56:43 -08:00
parent 725a91f1cc
commit 3e5e421484

24
autocat.py Normal file
View file

@ -0,0 +1,24 @@
import glob
import os
import sys
import tempfile
import time
if len(sys.argv) < 3:
raise ValueError()
output_filename = sys.argv.pop(-1)
patterns = sys.argv[1:]
names = [name for pattern in patterns for name in glob.glob(pattern)]
names = [os.path.abspath(x) for x in names]
cat_lines = [f'file \'{x}\'' for x in names]
cat_text = '\n'.join(cat_lines)
cat_file = tempfile.TemporaryFile('w', encoding='utf-8', delete=False)
cat_file.write(cat_text)
cat_file.close()
cmd = f'ffmpeg -f concat -safe 0 -i {cat_file.name} -c copy "{output_filename}"'
os.system(cmd)
os.remove(cat_file.name)