I have two video clips and want to overlay them. The overlay_clip has a transparent background and is shifted downwards relative to the video_clip. This works good. My Code:
from moviepy.editor import VideoFileClip, CompositeVideoClip
output_path = "output_2.mp4"
video_clip = VideoFileClip("welt.mp4", target_resolution=(1080, 1920))
overlay_clip = VideoFileClip("Transparent_Version (1).mov", has_mask=True, target_resolution=(1080, 1920))
# Verschieben des Clips 200 Pixel nach unten und 200 Pixel von der linken Seite des Videos
overlay_clip = overlay_clip.set_position((0, video_clip.h - overlay_clip.h + 300))
final_video = CompositeVideoClip([video_clip, overlay_clip])
final_video.write_videofile(output_path, fps=30, remove_temp=True, codec="libx264", audio_codec="aac", threads=6)
However, video_clip is 30 seconds long and overlay_clip is about 4 seconds long. I want to take the last frame of overlay_clip and extend overlay_clip to the exact length of video_clip. How can I do that? For example, I have tried the following code and get the following error message:
from moviepy.editor import VideoFileClip, CompositeVideoClip
output_path = "output_2_test.mp4"
video_clip = VideoFileClip("welt.mp4", target_resolution=(1080, 1920))
overlay_clip = VideoFileClip("Transparent_Version (1).mov", has_mask=True, target_resolution=(1080, 1920))
# Extrahieren des letzten Frames
last_frame = overlay_clip.get_frame(overlay_clip.duration - 1)
# Verlängern des Clips durch Wiederholen des letzten Frames
overlay_clip = overlay_clip.subclip(0, video_clip.duration).loop(duration=video_clip.duration)
# Hinzufügen des letzten Frames
overlay_clip = overlay_clip.set_make_frame(lambda t: last_frame if t >= overlay_clip.duration else overlay_clip.get_frame(t))
overlay_clip.write_videofile(output_path, fps=30, remove_temp=True, codec="libx264", audio_codec="aac", threads=6)
#Verschieben des Clips 200 Pixel nach unten und 200 Pixel von der linken Seite des Videos
overlay_clip = overlay_clip.set_position((0, video_clip.h - overlay_clip.h + 300))
final_video = CompositeVideoClip([video_clip, overlay_clip])
final_video.write_videofile(output_path, fps=30, remove_temp=True, codec="libx264", audio_codec="aac", threads=6)
Error:
OSError: Error in file Transparent_Version (1).mov, Accessing time t=4.53-4.57 seconds, with clip duration=4 seconds,
Any ideas?