Welcome folks today in this post we will be seeing how to increase
or decrease
the speed of video inside python using the moviepy
library. All the full source code of the application is shown below.
Get Started
In order to get started you need to install the following library using the pip
command as shown below
pip install moviepy
After installing this library we will apply video effects
to the video as shown below
Increasing Speed of Video
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# Import everything needed to edit video clips from moviepy.editor import * # loading video dsa gfg intro video clip = VideoFileClip("video.mkv") # getting only first 20 seconds clip = clip.subclip(0, 20) # applying speed effect final = clip.fx( vfx.speedx, 2) # showing final clip final.ipython_display() |
Here we are extracting subclip
of the original video on which we will be applying the filter
so we are extracting the first 20
seconds and increasing the speed of it
Decreasing Video Speed
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# Import everything needed to edit video clips from moviepy.editor import * # loading video dsa gfg intro video clip = VideoFileClip("video.mkv") # getting only first 20 seconds clip = clip.subclip(0, 20) # applying speed effect final = clip.fx( vfx.speedx, 0.5) # showing final clip final.ipython_display() |
So here we are passing the value very small such as 0.5
. So higher the value means we are increasing the speed and lower the value means we are decreasing the speed of the video
Now you can run this app.py
script by typing the below command as shown below
python app.py