larigira-scripts/audiobanner/bannerizza.py
2017-05-10 00:48:42 +02:00

42 lines
1.1 KiB
Python

#!/usr/bin/env python3
import argparse
import subprocess
import tempfile
import os
def mix(args):
interval = '%d.%d' % (args.interval / 60, args.interval % 60)
with tempfile.TemporaryDirectory(prefix='audiobanner') as tempdir:
subprocess.check_call(['mp3splt', '-d', tempdir,
'-o', 'orig_@n_@m.mp3',
'-t', interval,
args.original])
ffmpegconcat = 'concat:%s' % args.banner
for part in sorted(os.listdir(tempdir)):
ffmpegconcat += '|%s|%s' % (os.path.join(tempdir, part),
args.banner)
cmd = ['ffmpeg', '-i', ffmpegconcat,
'-loglevel', 'error', '-n',
args.destination]
subprocess.check_call(cmd)
def get_parser():
p = argparse.ArgumentParser("audiobanner")
p.add_argument("--interval", help='In seconds', default=60, type=int)
p.add_argument("original")
p.add_argument("banner")
p.add_argument("destination")
return p
def main():
args = get_parser().parse_args()
mix(args)
if __name__ == '__main__':
main()