简体   繁体   English

Moviepy:用黑色边框调整图像大小

[英]Moviepy: Resize image with black borders

I have a problem with resizing videos in moviepy.我在调整 moviepy 中的视频大小时遇到​​问题。 When I use the clip.resize(1920,1080) function, it stretches the image.当我使用clip.resize(1920,1080)函数时,它会拉伸图像。 I want it to stretch the image, keep the aspect ratio, but add black borders to it (to fill the aspect ratio).我希望它拉伸图像,保持纵横比,但为其添加黑色边框(以填充纵横比)。

This is the source image/video (resolution: 670 x 844)这是源图像/视频(分辨率:670 x 844)

This is how I want it to look (resolution: 1920 x 1080)这就是我想要的样子(分辨率:1920 x 1080)

Mix it with some black image in resolution you whish:将它与一些您希望的分辨率的黑色图像混合:

video = mp.VideoFileClip("/media/pi/video.mp4")
black_image = (mp.ImageClip("black_picture_1920x1080.jpg"))
mp.CompositeVideoClip([black_image, video.set_position("center")])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM