Skip to content

Instantly share code, notes, and snippets.

@alex-petrenko
Created June 18, 2021 21:35
Show Gist options
  • Save alex-petrenko/4f5243feb26111977abe5fd7f435bdf2 to your computer and use it in GitHub Desktop.
Save alex-petrenko/4f5243feb26111977abe5fd7f435bdf2 to your computer and use it in GitHub Desktop.
ffmpeg_batch.py
import os
import sys
import argparse
import subprocess
from os import listdir
from os.path import isfile, join
def main():
parser = argparse.ArgumentParser(description='Batch ffmpeg.')
parser.add_argument('--input_dir', type=str, help='Input dir with video files')
parser.add_argument('--output_dir', type=str, help='Result dir')
args = parser.parse_args()
if not os.path.isdir(args.output_dir):
os.mkdir(args.output_dir)
onlyfiles = [f for f in listdir(args.input_dir) if isfile(join(args.input_dir, f))]
for speed in [1.5, 2, 3, 4]:
for f in onlyfiles:
in_f = join(args.input_dir, f)
out_f = join(args.output_dir, f'{f.replace(".mp4", "")}_x{str(speed).replace(".", "_")}.mp4')
cli = ['ffmpeg', '-i', in_f, '-filter:v', f'setpts={1.0/speed}*PTS', out_f]
print(cli)
subprocess.run(cli)
return 0
if __name__ == '__main__':
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment