Skip to content

Instantly share code, notes, and snippets.

@tndoan
Last active April 9, 2017 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tndoan/2d58a49bce56763b76662cbfad2c204b to your computer and use it in GitHub Desktop.
Save tndoan/2d58a49bce56763b76662cbfad2c204b to your computer and use it in GitHub Desktop.
MoviePy example
from moviepy.editor import *
import moviepy.video.fx.all as vfx
clip = VideoFileClip('fname.mp4')
mclip = clip.fx(vfx.mirror_x) # all frame in clip will be mirrored in x-axis
mclip.write_videofile('mirror_fname.mp4')
##################################################
clip = VideoFileClip('fname.mp4')
rclip = clip.resize(0.8).without_audio()
comp = CompositeVideoClip([clip, rclip.set_pos('center')])
comp.write_videofile('resize_fname.mp4')
###############
from pydub import AudioSegment
sound1 = AudioSegment.from_file("/path/to/my_sound.mp3")
sound2 = AudioSegment.from_file("/path/to/background_music.mp3")
sound2 = sound2 - 50 # reduce the volumn of background sound
combined = sound1.overlay(sound2)
combined.export("/path/to/combined.mp3", format='mp3')
###############
fl = lambda gf, t : gf(t) + np.random.uniform(0, 1) # filter: every frame is added a value randomly drawing from 0 and 1
newclip = clip.fl(fl, apply_to='mask') # apply the filter to clip
newclip.write_videofile('new_f.mp4')
###############
# make clip backward
import moviepy.video.fx.all as vfx
backwardClip = clip.fx(vfx.time_mirror)
backwardClip.write_videofile('backwardClip.mp4')
#############
#
clip = VideoFileClip('clip.mp4')
newClip = clip.fx(vfx.speedx, 0.7).fx(vfx.colorx, 0.8) # make clip slower 0.7 and darken the video
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment