Sefi_k
Sefi_k

Reputation: 107

multiple lines of subtitles in Moviepy

I'm using MoviePy to create a video with subtitles. Here's the code to illustrate:

    generator = lambda txt: TextClip(txt, font='Arial', fontsize=48, color='Black')
    subtitles = SubtitlesClip("captions_cropped.srt", generator)
    video = VideoFileClip("my_video.mp4")
    result = CompositeVideoClip([video, subtitles.set_pos(('center',(0.885*1220)))])

I couldn't find anything on the documentation or Google about specifying the number of lines in the subtitles. Currently, when the subtitles are too long, they're just "cut" in the middle instead of starting a new line. I'd like the code to smart enough to start a new line of subtitles when needed.

Upvotes: 4

Views: 4027

Answers (1)

Bendemann
Bendemann

Reputation: 776

You should specify the method attribute for that purpose.

E.g.:

gen = lambda txt: mp.TextClip(
    txt, color='white', fontsize=20, font='Georgia-Regular',
    stroke_width=3, method='caption', align='south', size=video.size)

There's also some ongoing work for the upcoming v.2, issue.

Upvotes: 1

Related Questions