MoviePy is a Python module for video editing, which can be used for basic operations (like cuts, concatenations, title insertions), video compositing (a.k.a. non-linear editing), video processing, or to create advanced effects. It can read and write the most common video formats, including GIF.
Installation
To install the Movie Editor Library, open terminal and write :
pip install moviepy
Note: This module automatically installs FFmpeg. However, you might prompt to install in some cases.
Even after installing MoviePy there will be some features that can't be used unless ImageMagick is installed, features like adding text on the video or on GIFs.
Installation of ImageMagick
ImageMagick is not strictly required, only if user want to write texts. It can also be used as a back-end for GIFs although user can do GIFs with MoviePy without ImageMagick. Below is the link for downloading ImageMagick
https://imagemagick.org/script/download.php
Once it is installed, ImageMagick will be automatically detected by MoviePy, except on Windows. Windows users have to go into the moviepy/config_defaults.py file and provide the path to the ImageMagick binary called magick.
IMAGEMAGICK_BINARY = "C:\\Program Files\\ImageMagick_VERSION\\magick.exe"
or for some older versions of ImageMagick it will be
IMAGEMAGICK_BINARY = "C:\\Program Files\\ImageMagick_VERSION\\convert.exe"
Example 1
We will load the video, and we will cut a clip from the whole video then the video will be rotated upside down, in this example, there is no need for ImageMagick installation.
Below is the implementation
Python3
# Import everything needed to edit video clips
from moviepy.editor import *
# loading video dsa gfg intro video
clip = VideoFileClip("dsa_geek.webm")
# clipping of the video
# getting video for only starting 10 seconds
clip = clip.subclip(0, 10)
# rotating video by 180 degree
clip = clip.rotate(180)
# Reduce the audio volume (volume x 0.5)
clip = clip.volumex(0.5)
# showing clip
clip.ipython_display(width = 280)
Output :
Moviepy - Building video __temp__.mp4.
Moviepy - Writing video __temp__.mp4
Moviepy - Done !
Moviepy - video ready __temp__.mp4
Example 2:
We will load the video and we will cut a clip from the whole video then we will add text in the video, in this example we have to install ImageMagick otherwise it will not work.
Below is the implementation
Python3
# Import everything needed to edit video clips
from moviepy.editor import *
# loading video dsa gfg intro video
clip = VideoFileClip("dsa_geek.webm")
# clipping of the video
# getting video for only starting 10 seconds
clip = clip.subclip(0, 10)
# Reduce the audio volume (volume x 0.8)
clip = clip.volumex(0.8)
# Generate a text clip
txt_clip = TextClip("GeeksforGeeks", fontsize = 70, color = 'white')
# setting position of text in the center and duration will be 10 seconds
txt_clip = txt_clip.set_pos('center').set_duration(10)
# Overlay the text clip on the first video clip
video = CompositeVideoClip([clip, txt_clip])
# showing video
video.ipython_display(width = 280)
Output :
Moviepy - Building video __temp__.mp4.
Moviepy - Writing video __temp__.mp4
Moviepy - Done !
Moviepy - video ready __temp__.mp4
Exporting Video files:
You need function write_videofile(arg1, arg2), If you do not, it won't reflect on the hard-disk file as the file was loaded in RAM.
Python3
import moviepy.editor as me
# Our focus is on how to export video file,
# you can use any code, or just refer following code
'''
vid= me.VideoFileClip('Video_1.mp4')
# Grabbing Object from storage
# Creating a page with 'My Title' text in red
colour with given size and background colour
white and fontsize 30
'''
SYNTAX:
obj=me.TextClip("Text That you want",
color='{as string}',
size=(as,tuple),
bg_color='as string',
fontsize=int )
'''
title=me.TextClip('My Title',color='red',size=(1920,1000),bg_color='white',fontsize=30)
# title.set_duration(int seconds)
title_clip_ = title.set_duration(3)
#For 3 seconds My Title willbe shown in video
render=me.concatenate_videoclips([title_clip_,vid])
# Combining our manually created Video i.e My Title of 3 sec with grabbed video
'''
me.write_videofile("Name you want".mp4,endcoding)
# If successfully executor there will be file.mp4 or at path
# If you have explicitly mentioned else in same folder as program
print("Done")
Output:

Merging Video files -
We can merge 2 video files to a single file in order of our requirement
Python3
import moviepy.editor
'''
Grabbing The video's from storage
syntax:
variable_holding_video_name= moviepy.editor.VideoFileCLip("{{Filename}}.{{extension}}")
'''
clip_1= moviepy.editor.VideoFileClip("Video_1.mp4")
clip_2= moviepy.editor.VideoFileClip("Video_2.mp4")
'''
TO join the video's i.e. concatenate the videos'
use function concatenate_videoclips(list_of_clips_to_mearged)
syntax:
variable_to_hold_mearged_video= moviepy.editor.concatenate_videclips([video_1,Video_2,. . .])
'''
Mearged_video=moviepy.editor.concatenate_videoclips([clip_1,clip_2])
# Saving File as output.mp4 in same folder
# libx264 is encoding lib for creating video stream(H.264)
Mearged_video.write_videofile("Output.mp4",codec='libx264')
print("Done")
Output:

To know the length of the video:
Python3
import moviepy.editor as me
# Grabbing file
vid= me.VideoFileClip("Video_1.mp4")
print(str(vid.duration))
Output:
9.04
Advantages of MoviePy
- Simple: Basic operations can be done in one line, code is easy to learn and easy to understand for newcomers.
- Flexible: Users have total control over the frames of the video and audio, and creating their own effects is easy as Py.
- Portable: The code uses very common software such as Numpy and FFMPEG. And can run on almost any machine with almost any version of Python.
Disadvantages of MoviePy :
- MoviePy cannot yet stream videos (read from a webcam, or render a video live on a distant machine)
- It is not really designed for video processing involving many successive frames of a movie (like video stabilization, you’ll need another software for that)
- Memory problems can arise if the user use many video, audio, and image sources at the same time (>100)
Similar Reads
Python Tutorial - Learn Python Programming Language Python is one of the most popular programming languages. Itâs simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly. It'sA high-level language, used in web development, data science, automation, AI and more.Known fo
10 min read
Python Interview Questions and Answers Python is the most used language in top companies such as Intel, IBM, NASA, Pixar, Netflix, Facebook, JP Morgan Chase, Spotify and many more because of its simplicity and powerful libraries. To crack their Online Assessment and Interview Rounds as a Python developer, we need to master important Pyth
15+ min read
Python OOPs Concepts Object Oriented Programming is a fundamental concept in Python, empowering developers to build modular, maintainable, and scalable applications. OOPs is a way of organizing code that uses objects and classes to represent real-world entities and their behavior. In OOPs, object has attributes thing th
11 min read
Python Projects - Beginner to Advanced Python is one of the most popular programming languages due to its simplicity, versatility, and supportive community. Whether youâre a beginner eager to learn the basics or an experienced programmer looking to challenge your skills, there are countless Python projects to help you grow.Hereâs a list
10 min read
Python Exercise with Practice Questions and Solutions Python Exercise for Beginner: Practice makes perfect in everything, and this is especially true when learning Python. If you're a beginner, regularly practicing Python exercises will build your confidence and sharpen your skills. To help you improve, try these Python exercises with solutions to test
9 min read
Python Programs Practice with Python program examples is always a good choice to scale up your logical understanding and programming skills and this article will provide you with the best sets of Python code examples.The below Python section contains a wide collection of Python programming examples. These Python co
11 min read
Python Introduction Python was created by Guido van Rossum in 1991 and further developed by the Python Software Foundation. It was designed with focus on code readability and its syntax allows us to express concepts in fewer lines of code.Key Features of PythonPythonâs simple and readable syntax makes it beginner-frien
3 min read
Python Data Types Python Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, Python data types are classes and variables are instances (objects) of thes
9 min read
Input and Output in Python Understanding input and output operations is fundamental to Python programming. With the print() function, we can display output in various formats, while the input() function enables interaction with users by gathering input during program execution. Taking input in PythonPython's input() function
7 min read
Enumerate() in Python enumerate() function adds a counter to each item in a list or other iterable. It turns the iterable into something we can loop through, where each item comes with its number (starting from 0 by default). We can also turn it into a list of (number, item) pairs using list().Let's look at a simple exam
3 min read