SITUATION: I am trying to overlay an animation of a bouncing ball onto a background video. The bouncing ball video should be transparent except for the actual ball.
MY CODE:
My code to make the bouncing ball is:
def create_animation_video(output_path, duration, width=1920, height=1080):
radius = 25
color = (255, 0, 0) # Red color for the ball
def make_frame(t):
x = int(width / 2 + (width / 2 - radius - 10) * np.sin(2 * np.pi * t))
y = int(height / 2 + (height / 2 - radius - 10) * np.cos(2 * np.pi * t))
frame = np.zeros((height, width, 4), dtype='uint8')
for i in range(-radius, radius):
for j in range(-radius, radius):
if i**2 + j**2 <= radius**2:
frame[y + j, x + i, :3] = color
frame[y + j, x + i, 3] = 255
return frame
animation_clip = VideoClip(make_frame, duration=duration)
animation_clip.write_videofile(output_path, fps=24, codec='libvpx-vp9', audio=False)
PROBLEM: Running this animation code just results in an unplayable video and even the length of the video doesn’t line up with the duration given. What am I doing wrong? NOTE: I need the video to be transparent because I’m going to be overlaying it.