Instantly share code, notes, and snippets.

Embed
What would you like to do?
A quick and clunky way to make one of those videos where it speeds up every time something happens. Uses MoviePy.
#/usr/bin/python
# use this script to make one of those videos where it speeds up
# every time something happens
# this has only been tested on a Mac with Python 2.7
# Also, moviepy is picky about codecs. What I have here seems to work
# (libxvid) but you may need to try something else
# Your mileage may vary
import re
import os
import glob
from moviepy.editor import *
# wherever you're working
basepath = "./Videos/friday/"
# initial speed
speed = 1
# what to change
# positive gets faster, negative gets slower
factor = .1 # .1 == 10% faster
# get all of the clip points
# I did this manually for Friday, but you could also use a transcription file
marks = ['00:00:00','00:00:45.0','00:00:46.0','00:00:48.5','00:00:53.5','00:00:54.3','00:00:57.0','00:01:38.8 ','00:01:39.8','00:01:42','00:01:47.1','00:01:48.2','00:01:50.6','00:02:10.5','00:02:11.5','00:02:45.5','00:02:49.8','00:02:50.6','00:02:52.5','00:02:58','00:02:59','00:03:02','00:03:15','00:03:16','00:03:19','00:03:23','00:03:24','00:03:27','00:03:42']
# make a temporary folder
if not os.path.exists(basepath+"tmp"):
os.makedirs(basepath+"tmp")
# cut it up and speed up the chunks proportionally with moviepy
if (len(marks) > 0):
for m in (range(len(marks) - 1)):
if (marks[m + 1]):
video = VideoFileClip(basepath+"friday.mp4").subclip(marks[m],marks[m + 1])
mod = video.speedx(speed)
mod.write_videofile(basepath+"tmp/friday."+str(m).zfill(3) +".mov",codec="libxvid")
speed += factor
# stick them back together
files = glob.glob(basepath+"tmp/*.mov")
clips = []
for f in range(len(files)):
video = VideoFileClip(files[f])
clips.append(video)
# write a new video file called "output.mov" in the basepath directory
final = concatenate_videoclips(clips)
final.write_videofile(basepath+"output.mov",codec="libxvid")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment