Moviepy - Place textclips at relative position

Viewed 400

How do I place a textclip, right below the other? I require to place an image at the left of the video and two lines of text to the right of image, that are placed one below the other.

Something like this: Desired frame

I tried to use set_position, but doesn't scale well for different videos (of different resolutions). By adjusting the arguments of set_position, I am able to place the textclips one below the other without gap in one resolution, but when I go to a higher resolution video, it shows a gap (I understand why the gap comes, but not sure how to prevent it)

txt_clip1 = TextClip("This is line 1 of text", fontsize = 12, color = 'white', bg_color='black') txt_clip1 = txt_clip1.set_duration(7).set_start(0).set_end(7) txt_clip1 = txt_clip1.set_position((0.1,0.90), relative=True).set_opacity(0.6)

txt_clip2 = TextClip("This is line 2 of the text, smaller font", fontsize = 8, color = 'white', bg_color='black') txt_clip2 = txt_clip2.set_duration(7).set_start(0).set_end(7) txt_clip2 = txt_clip2.set_position((0.1,0.93), relative=True).set_opacity(0.6)

I tried to insert a new line character in the text, but that doesn't suit me because the second line of text has different font properties.

1 Answers

Hopefully this will help you

txt_clip1 = TextClip(
    "Cool effect 2nd line", color="black", bg_color="red", font="Amiri-Bold", kerning=5, fontsize=20
)
cvc = CompositeVideoClip([txt_clip1.set_position("East")], size=screensize)
txt_clip1 = txt_clip1.set_position((5,35))

.set_position mother take to arguments 1st is the position from the left screen and second is the position from the top

so your code is like something

txt_clip1 = txt_clip1.set_position((5,500))
txt_clip2 = txt_clip2.set_position((5,535))

It will place the text in the position you want.

Hopefully, this will help. Happy coding

Related