Last active
March 5, 2025 05:33
-
-
Save tndoan/2d58a49bce56763b76662cbfad2c204b to your computer and use it in GitHub Desktop.
MoviePy example
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
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