I'm trying to create a zoom in and out effect for an image using moviepy. I found this solution:
Moviepy zooming effects need tweaking
import os
from moviepy.editor import *
def resize_func(t):
if t < 4:
return 1 + 0.2*t # Zoom-in.
elif 4 <= t <= 6:
return 1 + 0.2*4 # Stay.
else: # 6 < t
return 1 + 0.2*(duration-t) # Zoom-out.
duration = 10
screensize = (640,360)
clip_img = (
ImageClip('img.jpg')
.resize(screensize)
.resize(resize_func)
.set_position(('center', 'center'))
.set_duration(duration)
.set_fps(25)
)
clip = CompositeVideoClip([clip_img], size=screensize)
clip.write_videofile('test.mp4')
Unfortunately, the video starts to twitch slightly. How can I fix the problem?