[英]Overlay video on video in MoviePy
I am using python MoviePy library to overlay video with transparent background in .mov format on video in .mp4.我正在使用 python MoviePy 库在 .mp4 中的视频上覆盖具有 .mov 格式的透明背景的视频。 Here is the code I have so far.这是我到目前为止的代码。
from moviepy.editor import VideoFileClip, CompositeVideoClip
zm_video_path = "1.mov"
def add_zm(fg_in_bg_avi):
clip1 = VideoFileClip(fg_in_bg_avi)
clip3 = VideoFileClip(zm_video_path, has_mask=True)
video = CompositeVideoClip([clip1, clip3])
name = 'New_video'
video.write_videofile(name, audio=False) # No audio first
video.close()
return name
if __name__ == '__main__':
video_have_zm = add_zm("background.mp4")
This code worked when I was overlaying a GIF on the same video.当我在同一视频上叠加 GIF 时,此代码有效。 I see the following error:我看到以下错误:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xce in position 1806: invalid continuation byte UnicodeDecodeError:“utf-8”编解码器无法解码位置 1806 中的字节 0xce:无效的继续字节
Thanks in advance.提前致谢。 Maybe you know how to do it on ffmpeg?也许你知道如何在 ffmpeg 上做到这一点?
output_path="output.mp4" output_path="输出.mp4"
video_clip = VideoFileClip((video_view), target_resolution=(1080, 1920)) #b .mp4 file video_clip = VideoFileClip((video_view), target_resolution=(1080, 1920)) #b .mp4 文件
overlay_clip = VideoFileClip((animeeer), has_mask=True, target_resolution=(1080, 1920)) #.mov file with alpha channel overlay_clip = VideoFileClip((animeeer), has_mask=True, target_resolution=(1080, 1920)) #.mov 带有 alpha 通道的文件
final_video = mp.CompositeVideoClip([video_clip, overlay_clip]) final_video = mp.CompositeVideoClip([video_clip, overlay_clip])
final_video.write_videofile( output_path, fps=30, remove_temp=True, codec="libx264", audio_codec="aac", threads = 6, ) final_video.write_videofile( output_path, fps=30, remove_temp=True, codec="libx264", audio_codec="aac", threads = 6, )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.