}

Moviepy: example script with subtitles

Created:

In our script we add subtitles from the file subtitles.srt using Arial font with white color. Then, with VideoFileClip("video-to-add-subtitles.mp4") we open the video for adding the subtitles. When the video is already loaded into the clip variables, we then use CompositeVideoClip for adding the subtitles at the center position. Finally we use write_videofile for saving the final video.

from moviepy.editor import *
from moviepy.video.tools.subtitles import SubtitlesClip

generator = lambda txt: TextClip(txt, font='Arial', fontsize=16, color='white')
subtitles = SubtitlesClip("subtitles.srt", generator)

video = VideoFileClip("video-to-add-subtitles.mp4")
result = CompositeVideoClip([video, subtitles.set\_pos(('center','bottom'))])

result.write\_videofile("subtitles-test.mp4", fps=video.fps, temp\_audiofile="tmp-audio.m4a", remove\_temp=True, codec="libx264", audio\_codec="aac")

if(typeof \_\_ez\_fad\_position != 'undefined'){\_\_ez\_fad\_position('div-gpt-ad-tutorials\_technology-medrectangle-3-0')};

Please leave comments if you have any problems with our solution!