Skip to content

Instantly share code, notes, and snippets.

@Zulko
Last active December 10, 2022 07:03
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zulko/f90674b2e64c5600370e to your computer and use it in GitHub Desktop.
Save Zulko/f90674b2e64c5600370e to your computer and use it in GitHub Desktop.
Motion blur in MoviePy.
import numpy as np
def supersample(clip, d, nframes):
""" Replaces each frame at time t by the mean of `nframes` equally spaced frames
taken in the interval [t-d, t+d]. This results in motion blur."""
def fl(gf, t):
tt = np.linspace(t-d, t+d, nframes)
avg = np.mean(1.0*np.array([gf(t_) for t_ in tt]),axis=0)
return avg.astype("uint8")
return clip.fl(fl)
#usage:
some_videoclip = #... make the clip
new_clip = supersample(some_videoclip, d=0.05, nframes=5)
new_clip.write_gif("test.gif", fps=15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment