moviepy.video.tools.subtitles.SubtitlesClip#
- class moviepy.video.tools.subtitles.SubtitlesClip(subtitles, font=None, make_textclip=None, encoding=None)[source]#
A Clip that serves as “subtitle track” in videos.
One particularity of this class is that the images of the subtitle texts are not generated beforehand, but only if needed.
- Parameters:
subtitles – Either the name of a file as a string or path-like object, or a list
font – Path to a font file to be used. Optional if make_textclip is provided.
make_textclip –
A custom function to use for text clip generation. If None, a TextClip will be generated.
The function must take a text as argument and return a VideoClip to be used as caption
encoding – Optional, specifies srt file encoding. Any standard Python encoding is allowed (listed at https://docs.python.org/3.8/library/codecs.html#standard-encodings)
Examples
from moviepy.video.tools.subtitles import SubtitlesClip from moviepy.video.io.VideoFileClip import VideoFileClip generator = lambda text: TextClip(text, font='./path/to/font.ttf', font_size=24, color='white') sub = SubtitlesClip("subtitles.srt", make_textclip=generator, encoding='utf-8') myvideo = VideoFileClip("myvideo.avi") final = CompositeVideoClip([clip, subtitles]) final.write_videofile("final.mp4", fps=myvideo.fps)