MoviePy – Inserting Text in the Video
Last Updated :
30 Aug, 2020
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 MoviePy. In order to do this we need to have ImageMagick installed else it will not work. Adding text to a video is similar to creating composite video.
In order to do so we have to do the following :
1. Import the moviepy module
2. Load the video file
3. Create a text clip and set its position and duration
4. Create a composite video clip using video file and the text clip.
5. Show the final video.
Below is the implementation
from moviepy.editor import *
clip = VideoFileClip( "dsa_geek.mp4" )
clip = clip.subclip( 0 , 10 )
clip = clip.volumex( 0.8 )
txt_clip = TextClip( "GeeksforGeeks" , fontsize = 75 , color = 'black' )
txt_clip = txt_clip.set_pos( 'center' ).set_duration( 10 )
video = CompositeVideoClip([clip, txt_clip])
video.ipython_display(width = 280 )
|
Moviepy - Building video __temp__.mp4.
Moviepy - Writing video __temp__.mp4
Moviepy - Done !
Moviepy - video ready __temp__.mp4
Another example
from moviepy.editor import *
clip = VideoFileClip( "geeks.mp4" )
clip = clip.subclip( 0 , 5 )
clip = clip.volumex( 0.5 )
txt_clip = TextClip( "GfG-MoviePy" , fontsize = 75 , color = 'green' )
txt_clip = txt_clip.set_pos( 'bottom' ).set_duration( 5 )
video = CompositeVideoClip([clip, txt_clip])
video.ipython_display(width = 280 )
|
Moviepy - Building video __temp__.mp4.
Moviepy - Writing video __temp__.mp4
Moviepy - Done !
Moviepy - video ready __temp__.mp4
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...