Moviepy - 将文本剪辑放置在相对位置

发布于 2025-01-09 12:11:29 字数 939 浏览 1 评论 0原文

如何将文本剪辑放置在另一个文本剪辑的正下方?我需要在视频的左侧放置一张图像,在图像的右侧放置两行文本,一行一行地放置在另一行下面。

像这样的事情: 所需帧

我尝试使用 set_position,但对于不同的视频(不同分辨率)不能很好地缩放。通过调整 set_position 的参数,我能够将文本剪辑一个一个地放在另一个下面,在一种分辨率下没有间隙,但是当我转到更高分辨率的视频时,它会显示一个间隙(我理解为什么会出现间隙,但不确定如何产生间隙)为了防止它)

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)

我尝试在文本中插入一个新行字符,但这不适合我,因为第二行文本具有不同的字体属性。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小清晰的声音 2025-01-16 12:11:29

希望这会帮助你

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接受参数第一个是从左屏幕开始的位置,第二个是从顶部开始的位置

,所以你的代码就像一些东西

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

它将把文本放置在你想要的位置。

希望这会有所帮助。
快乐编码

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文