Last active
July 22, 2021 05:38
-
-
Save jborbik/dc5e12ae73a8e769254a7803b2da7824 to your computer and use it in GitHub Desktop.
Speed up videos (x20)
This file contains hidden or 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
| ''' | |
| Files are saved in the same folder with suffix *_x<speedup_rate> and MP4 extension (this leads to faster processing) | |
| ''' | |
| import os | |
| import glob | |
| import subprocess | |
| from multiprocessing import Pool | |
| import sys | |
| speedup_rate = 20 | |
| path_pattern = os.path.expanduser(sys.argv[1] + "/**/*.webm") | |
| def speed_up_file(file_path): | |
| if f'x{speedup_rate}' in file_path: | |
| return | |
| file_name = os.path.basename(file_path) | |
| folder_name = os.path.dirname(file_path) | |
| new_file_path = os.path.join(folder_name, file_name.replace(".webm", f"_x{speedup_rate}.mp4")) | |
| print('new_file_path', new_file_path) | |
| subprocess.run(f"ffmpeg -i '{file_path}' -filter:v 'setpts={1/speedup_rate}*PTS' -filter:a 'atempo={speedup_rate}' '{new_file_path}'", shell=True, check=True) | |
| file_list = glob.glob(path_pattern, recursive=True) | |
| print(file_list) | |
| pool = Pool(os.cpu_count()) | |
| pool.map(speed_up_file, file_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment