在 python 中的视频文件 (.mp4) 后面添加图像
Add an image behind a video file (.mp4) in python
我正在尝试使用 moviepy 在视频后面添加图像,但无法想出任何方法。我的图像尺寸是 (1080 x 720),我的视频尺寸是 (200 x 200)。我试图将视频文件放在图像文件的顶部,将其放在中间并导出具有图像尺寸的最终视频。这是我要实现的目标的直观表示:
View image
我尝试使用以下代码执行此操作,但无法使其正常工作。非常感谢任何帮助:)
import moviepy
import moviepy.editor as mp
video = mp.VideoFileClip("/media/pi/vid.mp4")
logo = (mp.ImageClip("/media/pi/pic.png"))
# Preferably I would want the image to be the same duration as the video file.
# The following was just for testing.
final = mp.CompositeVideoClip([video, logo.set_duration(3)])
final.write_videofile("test.mp4")
您好!
我现在无法测试,但是here它说
Note that by default the composition has the size of its first clip (as it is generally a background)
所以也许你应该试试这个(如果你不知道什么是“中心”,你应该看看docs):
import moviepy
import moviepy.editor as mp
video = mp.VideoFileClip("/media/pi/vid.mp4")
logo = (mp.ImageClip("/media/pi/pic.png"))
final = mp.CompositeVideoClip([logo, video.set_position("center")])
final.write_videofile("test.mp4")
旁注:您应该从 moviepy 1.0.1 降级到 moviepy 1.0.0,否则您将收到“对象没有属性标准输出”或类似错误。要降级:
pip install moviepy==1.0.0
或
pip3 install moviepy = 1.0.0
我正在尝试使用 moviepy 在视频后面添加图像,但无法想出任何方法。我的图像尺寸是 (1080 x 720),我的视频尺寸是 (200 x 200)。我试图将视频文件放在图像文件的顶部,将其放在中间并导出具有图像尺寸的最终视频。这是我要实现的目标的直观表示:
View image
我尝试使用以下代码执行此操作,但无法使其正常工作。非常感谢任何帮助:)
import moviepy
import moviepy.editor as mp
video = mp.VideoFileClip("/media/pi/vid.mp4")
logo = (mp.ImageClip("/media/pi/pic.png"))
# Preferably I would want the image to be the same duration as the video file.
# The following was just for testing.
final = mp.CompositeVideoClip([video, logo.set_duration(3)])
final.write_videofile("test.mp4")
您好!
我现在无法测试,但是here它说
Note that by default the composition has the size of its first clip (as it is generally a background)
所以也许你应该试试这个(如果你不知道什么是“中心”,你应该看看docs):
import moviepy
import moviepy.editor as mp
video = mp.VideoFileClip("/media/pi/vid.mp4")
logo = (mp.ImageClip("/media/pi/pic.png"))
final = mp.CompositeVideoClip([logo, video.set_position("center")])
final.write_videofile("test.mp4")
旁注:您应该从 moviepy 1.0.1 降级到 moviepy 1.0.0,否则您将收到“对象没有属性标准输出”或类似错误。要降级:
pip install moviepy==1.0.0
或
pip3 install moviepy = 1.0.0