Moviepy - 将文本剪辑放置在相对位置
如何将文本剪辑放置在另一个文本剪辑的正下方?我需要在视频的左侧放置一张图像,在图像的右侧放置两行文本,一行一行地放置在另一行下面。
我尝试使用 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.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
希望这会帮助你
。set_position mother接受参数第一个是从左屏幕开始的位置,第二个是从顶部开始的位置
,所以你的代码就像一些东西
它将把文本放置在你想要的位置。
希望这会有所帮助。
快乐编码
Hopefully this will help you
.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
It will place the text in the position you want.
Hopefully, this will help.
Happy coding