Skip to content

Instantly share code, notes, and snippets.

@aimerneige
Last active October 8, 2023 06:11
Show Gist options
  • Save aimerneige/473b74bb346f51d557513272e0ccb4b7 to your computer and use it in GitHub Desktop.
Save aimerneige/473b74bb346f51d557513272e0ccb4b7 to your computer and use it in GitHub Desktop.
Speed Up Video 2x faster
import os
from os import listdir
from os.path import isfile, join
current_dir = os.getcwd()
output_dir = os.path.join(current_dir, "out")
try:
os.makedirs(output_dir)
except:
pass
only_files = [f for f in listdir(current_dir) if isfile(join(current_dir, f))]
for file in only_files:
if file[-3:] == "mp4":
mp4_file_path = join(current_dir, file)
speedup_file_name = f'2x_{file}'
speedup_file_path = join(output_dir, speedup_file_name)
# ffmpeg -i input.mp4 -filter:v "setpts=0.5*PTS" -filter:a "atempo=2.0" output.mp4
convert_command = f'ffmpeg -i {mp4_file_path} -filter:v "setpts=0.5*PTS" -filter:a "atempo=2.0" {speedup_file_path}'
os.system(convert_command)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment