Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Python 3 MoviePy Script to Increase or Decrease Speed of MP4 Video File in Command Line

Posted on February 12, 2023

 

 

Welcome folks today in this blog post we will be using the moviepy library to increase or decrease the speed of mp4 video file in command line. All the full source code of the application is shown below.

 

 

Get Started

 

 

First of all we need to install the below moviepylibrary using the pip command as shown below

 

 

pip install moviepy

 

 

In order to get started you need to make an app.py file and copy paste the following code

 

 

app.py

 

 

Decreasing the Speed of Video

 

 

First of all we will see how to decrease the speed of video.

 

 

Python
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.mp4")
 
# getting only first 5 seconds
clip = clip.subclip(0, 5)
 
# applying speed effect
final = clip.fx(vfx.speedx, 0.2)
 
# showing final clip
final.ipython_display()

 

 

As you can see at the very top we are importing the moviepy library and then we are using the VideoFileClip class to load the input video and then we are using the subclip method to cut the video into 5 seconds and then we are applying the speed filter into these 5 seconds using the fx method and inside the argument we are passing the speed constant which is 0.2.This means lower the value simply means we are decreasing the speed of the video. And lastly we are saving the output video in the same directory.

 

 

Increasing the Speed of Video

 

 

For increasing the speed you need to follow the same steps that are illustrated above but you just need to increase the speed value that you pass to the fx method.

 

 

Python
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.mp4")
 
# getting only first 5 seconds
clip = clip.subclip(0, 5)
 
# applying speed effect
final = clip.fx(vfx.speedx, 2.2)
 
# showing final clip
final.ipython_display()

Recent Posts

  • Android Java Project to Store,Read & Delete Data Using SharedPreferences Example
  • Android Java Project to Download Multiple Images From URL With Progressbar & Save it inside Gallery
  • Android Java Project to Capture Image From Camera & Save it inside Gallery
  • Android Java Project to Crop,Scale & Rotate Images Selected From Gallery and Save it inside SD Card
  • Android Kotlin Project to Load Image From URL into ImageView Widget
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme