0

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?

  • Is `t` measured in... seconds? Frames? What are the units here? `0.2*t` is a pretty huge change if it's frames, and it makes perfect sense that that would be jerky. The `0.02*t` from the original is a lot more reasonable in that case. – Charles Duffy Feb 24 '23 at 19:28

0 Answers0