The Wayback Machine - https://web.archive.org/web/20241009175312/https://www.geeksforgeeks.org/moviepy-text-with-moving-letters/
Open In App

MoviePy – Text with moving Letters

Last Updated : 25 Oct, 2021
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

In this article we will see how we can move the letters of the text clip MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF’s. Video is formed by the frames, combination of frames creates a video each frame is an individual image. VideoClip is the base class for all the other video clips in MoviePy. Text with moving letters, is like letters are spreading and rearranging themselves, creating a moving effect.
 

In order to do so we have to do the following : 
1. Import the numpy and moviepy module 
2. Create a text clip and set its various properties 
3. From text clip create a composite video clip 
4. Create methods for moving letters effect 
5. Create clips using the methods one by one 
6. Combine the clips to obtain final video clip 
7. Set fps to the final clip 
8. Show the final clip 
 

Example: Below is the implementation 

Python3




# importing Numpy
import numpy as np
 
# importing moviepy module
from moviepy.editor import * from moviepy.video.tools.segmenting import findObjects
 
# screen size
screensize = (720, 460)
 
# creating a text clip of color green, font is Arial and size is 80
txtClip = TextClip('GeeksforGeeks', color = 'lightgreen', font = "Arial",
                   kerning = 5, fontsize = 80)
 
# creating a composite video of given size
cvc = CompositeVideoClip( [txtClip.set_pos('center')],
                        size = screensize)
 
# helper function
rotMatrix = lambda a: np.array( [[np.cos(a), np.sin(a)],
                                 [-np.sin(a), np.cos(a)]] )
 
 
# creating a effect 1 method
def effect1(screenpos, i, nletters):
     
    # damping
    d = lambda t : 1.0/(0.3 + t**8)
    # angle of the movement
    a = i * np.pi / nletters
     
    # using helper function
    v = rotMatrix(a).dot([-1, 0])
     
    if i % 2 : v[1] = -v[1]
         
    # returning the function
    return lambda t: screenpos + 400 * d(t)*rotMatrix(0.5 * d(t)*a).dot(v)
 
# method for effect 2
def effect2(screenpos, i, nletters):
     
    # numpy array
    v = np.array([0, -1])
     
    d = lambda t : 1 if t<0 else abs(np.sinc(t)/(1 + t**4))
     
    # returning the function
    return lambda t: screenpos + v * 400 * d(t-0.15 * i)
 
 
 
# a list of ImageClips
letters = findObjects(cvc)
 
 
# method to move letters
def moveLetters(letters, funcpos):
     
    return [ letter.set_pos(funcpos(letter.screenpos, i, len(letters)))
              for i, letter in enumerate(letters)]
 
# adding clips with specific effect
clips = [ CompositeVideoClip( moveLetters(letters, funcpos),
                              size = screensize).subclip(0, 5)
          for funcpos in [effect1, effect2] ]
 
# comping all the clips
final_clip = concatenate_videoclips(clips)
 
# setting fps of the final clip
final_clip.fps = 24
 
# showing video clip
final_clip.ipython_display()


Output : 
 

Moviepy - Building video __temp__.mp4.
Moviepy - Writing video __temp__.mp4

                                                                                                                       
Moviepy - Done !
Moviepy - video ready __temp__.mp4

 

Another example 
 

Python3




# importing Numpy
import numpy as np
 
# importing moviepy module
from moviepy.editor import * from moviepy.video.tools.segmenting import findObjects
 
# screen size
screensize = (1080, 720)
 
# creating a text clip of color red, font is Arial and size is 80
txtClip = TextClip('GeeksforGeeks', color = 'red', font = "Arial",
                   kerning = 5, fontsize = 80)
 
# creating a composite video of given size
cvc = CompositeVideoClip( [txtClip.set_pos('center')],
                        size = screensize)
 
# helper function
rotMatrix = lambda a: np.array( [[np.cos(a), np.sin(a)],
                                 [-np.sin(a), np.cos(a)]] )
 
 
 
# method for effect 3
def effect3(screenpos, i, nletters):
     
    v = np.array([-1, 0])
     
    d = lambda t : max(0, 3-3 * t)
     
    # returning the function
    return lambda t: screenpos-400 * v*d(t-0.2 * i)
 
# method for effect 4
def effect4(screenpos, i, nletters):
     
    # damping
    d = lambda t : max(0, t)
     
     # angle of the movement
    a = i * np.pi / nletters
     
    v = rotMatrix(a).dot([-1, 0])
     
    if i % 2 : v[1] = -v[1]
         
    # returning the function
    return lambda t: screenpos + 400 * d(t-0.1 * i)*rotMatrix(-0.2 * d(t)*a).dot(v)
 
 
 
# a list of ImageClips
letters = findObjects(cvc)
 
 
# method to move letters
def moveLetters(letters, funcpos):
     
    return [ letter.set_pos(funcpos(letter.screenpos, i, len(letters)))
              for i, letter in enumerate(letters)]
 
# adding clips with specific effect
clips = [ CompositeVideoClip( moveLetters(letters, funcpos),
                              size = screensize).subclip(0, 5)
          for funcpos in [effect3, effect4] ]
 
# comping all the clips
final_clip = concatenate_videoclips(clips)
 
# setting fps of the final clip
final_clip.fps = 24
 
# showing video clip
final_clip.ipython_display()


Output : 
 

Moviepy - Building video __temp__.mp4.
Moviepy - Writing video __temp__.mp4

                                                                                                                       
Moviepy - Done !
Moviepy - video ready __temp__.mp4

 



Similar Reads

MoviePy – Creating Text Clip
In this article we will see how we can create a text clip in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF’s. Video is formed by the frames, combination of frames creates a video each frame is an individual image. Text clip is basically a clip here we can say it as image containing t
2 min read
MoviePy – Inserting Text in the Video
In this article we will see how we can insert text to a video clip in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF’s. Video is formed by the frames, combination of frames creates a video each frame is an individual image. VideoClip is the base class for all the other video clips in
2 min read
MoviePy – Checking Mask of Video File Clip
In this article we will see how we can check if the video file clip in MoviePy is a mask video or not. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF’s. IsMask property tells that if the given video clip is mask or not, mask is basically that video which is used as mask for the another video.
2 min read
MoviePy - Loading Video File Clip
In this article we will see how we can load a video file clip in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Visual multimedia source that combines a sequence of images to form a moving picture. The video transmits a signal to a screen and processes the order in which the screen
2 min read
MoviePy – Showing Video File Clip
In this article we will see how we can show a video file clip in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Visual multimedia source that combines a sequence of images to form a moving picture. The video transmits a signal to a screen and processes the order in which the screen
2 min read
MoviePy – Getting Sub Clip
In this article we will see how we can show a video file clip in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. A subclip is a section of a master (source) clip that you want to edit and manage separately in your project. You can use subclips to organize long media files. You work
2 min read
MoviePy –Saving Video File Clip
In this article we will see how we can save a video file clip in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Visual multimedia source that combines a sequence of images to form a moving picture. The video transmits a signal to a screen and processes the order in which the screen
2 min read
MoviePy Composite Video - Setting starting time of single clip
In this article we will see how we can set starting time of single clip in composite video file in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Meaning of composite is combining different elements, composite video is the combination of different video clips unlike stacking and co
2 min read
MoviePy – Adding Margin to Video File Clip
In this article we will see how we can add margin to the video file clip in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. In typography, a margin is the area between the main content of a page and the page edges. The margin helps to define where a line of text begins and ends. Whe
2 min read
MoviePy – Mirroring Video File Clip for x-axis
In this article we will see how we can mirror the video file clip to the x-axis in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Mirroring video according to the x-axis, a mirror video (in a plane mirror) is a reflected duplication of an object that appears almost identical, but i
2 min read
MoviePy – Mirroring Video File Clip for y-axis
In this article we will see how we can mirror the video file clip to the y-axis in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Mirroring video according to the y-axis, a mirror video (in a plane mirror) is a reflected duplication of an object that appears almost identical, but i
2 min read
MoviePy - Creating Composite Video Clips
In this article, we will see how we can composite video file in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Meaning of composite is combining different elements, composite video is the combination of different video clips unlike stacking and concatenation of video files composit
2 min read
MoviePy – Rotating Video File
In this article we will see how we can rotate a video file clip in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Rotation is the act or process of moving or turning around a video to its central point. Rotation of 360 degree will be a complete turn around a central point. We can r
2 min read
MoviePy – Concatenating multiple Video Files
In this article, we will see how we can concatenate multiple video file clips in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. In formal language theory and computer programming, string concatenation is the operation of joining character strings end-to-end. For example, the concat
2 min read
MoviePy – Stacking multiple Video Files
In this article we will see how we can stack multiple video file clips in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Unlike concatenating of multiple videos clips in stacking all the video files get played at the same time like images in the collage.Note : The clips do not need
2 min read
MoviePy – Resizing Video File
In this article, we will see how we can resize video file clips in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Resizing video files means. Image/frame interpolation occurs when you resize or distort your frame of video from one-pixel grid to another. Video resizing is necessary
3 min read
MoviePy – Getting Width of Video File Clip
In this article we will see how we can get the width of the video file in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Width is the part of the dimensions of the video, width is basically the base of the video. We can load the video file clip with the help of command given below
2 min read
MoviePy – Getting Height of Video File Clip
In this article we will see how we can get the height of the video file in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Height is the part of the dimensions of the video, height is basically the tall the length of video. We can load the video file clip with the help of command gi
2 min read
MoviePy – Getting Original File Name of Video File Clip
In this article we will see how we can get the original file name of the video file in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Original file name is the name of the original video that existed in the first place i.e which was loaded, even after altering and editing of the vi
2 min read
MoviePy – FPS of Video File Clip
In this article we will see how we can get the fps i.e frame per second(frame rate) of the video file in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Frame rate is the speed at which those images are shown, or how fast you “flip” through the book and it's usually expressed as “fr
2 min read
MoviePy Composite Video - Adding Cross Fade in Effect
In this article we will see how we can add cross fade in effect in composite video file in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Meaning of composite is combining different elements, composite video is the combination of different video clips unlike stacking and concatenat
2 min read
MoviePy Composite Video - Setting Position of Clip
In this article we will see how we can set position of clip in composite video file in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Meaning of composite is combining different elements, composite video is the combination of different video clips unlike stacking and concatenation
2 min read
MoviePy – Applying Resize effect on Video Clip
In this article we will see how we can apply resize effect on the video file clip in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. We can resize the video with the help of resize method to resize the video clip, resize filter is the type of filter applied on it. In order to do thi
2 min read
MoviePy – Changing Image and Time at same time of Video Clip
In this article we will see how we can change display frames and time line of the video file clip in MoviePy at a same time. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. We use fl_image method to alter the display frames and fl_time method to alter the time, although we can do these task
2 min read
MoviePy – Getting Duration of Video File Clip
In this article we will see how we can get the duration of the video file clip in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Duration is basically length of the video i.e how long the video is, it is in seconds. In order to do this we will use duration method with the VideoFile
2 min read
MoviePy – Changing Display Frame of Video Clip
In this article we will see how we can change display frames of the video file clip in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Display frames are the single image i.e single frame of the video, video consist of many frames, we can change the display frames using moviepy. In
2 min read
MoviePy – Changing Time Line of Video Clip
In this article we will see how we can change time line of the video file clip in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. In video editing, timeline is a commonly used interface found in most video editing programs. This interface enables authors to lay a video project out i
2 min read
MoviePy – Applying Color effect on Video Clip
In this article we will see how we can apply color effect on the video file clip in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Color effect is used to increase or decrease the color strength, when we lower the strength color looks more dark where as by increasing the strength i
2 min read
MoviePy – Applying Speed effect on Video Clip
In this article we will see how we can apply speed effect on the video file clip in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Speed up video or slow down also known as fast motion/slow-motion effects in video production, which makes the video clips play faster or slower than o
2 min read
MoviePy – Adding Mask to Video File Clip
In this article we will see how we can add mask to the video file clip in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF’s. IsMask property tells that if the given video clip is mask or not, mask is basically that video which is used as mask for the another video. We can make a video
2 min read
Article Tags :
Practice Tags :