Change text properties frame by frame efficiently in MoviePy?

Viewed 443

I'm trying to be able to change arbitrary parts of a clip object on a frame by frame basis to make custom effects. I can achieve this with the following code, but it is extremely inefficient.

def make_text(clip, text=''):
    duration = clip.duration
    fps = clip.fps
    frame_duration = math.floor(duration * fps)

    text_frames = []
    print(duration, fps, math.floor(duration * fps))
    for t in range(frame_duration):
        text_frame = TextClip(text, font='Arial', color='green', fontsize=120)
        text_frame = text_frame.set_duration(t/ fps)
        text_frame = text_frame.set_position(50 + t**2.67, 'center')
        text_frames.append(text_frame)

    text = concatenate(text_frames)
    clip_text = CompositeVideoClip([clip, text])
    return clip_text

I understand I can change the position of the text more efficiently by simply giving it a function for t - the code above is meant to be a proof of concept for arbitrary properties of any clip (like kerning of text, size of text) there are some example in the docs for custom effects, but even those seem limited to certain classes. I can't seem to find a way write good code for any part of any object without slowing down the program by a massive factor - is there any way to achieve this efficiently?

0 Answers
Related