python - Moviepy zooming effects need tweaking -
i zoom clip dimension, stop further zooming. in other words, clip stop further increasing size after reaching size, , better if clip start zooming smaller of original size, , bigger version. using moviepy module. following code can progressively zoom clip, having hard time figuring out how grow clip small big, creating animated effect. feedback provide appreciated.
import os moviepy.editor import * screensize = (640,360) clip = (imageclip(img) .resize(height=screensize[1]*4) .resize(lambda t : 1+0.02*t) .set_position(('center', 'center')) .set_duration(10) )
i having hard time figuring out how write function in order create type-writing effect moviepy's txtclip, meaning letters within clip shown 1 after another, creating smooth type-writer animation text. moviepy got helpful classes such findobjects--which can detect individual letters out of clip:
txtclip = textclip('cool effect',color='white', font="amiri-bold", kerning = 5, fontsize=100) cvc = compositevideoclip( [txtclip.set_pos('center')], size=screensize, transparent=true) letters = findobjects(cvc) # list of imageclips here link: http://zulko.github.io/moviepy/examples/moving_letters.html
after finding letters(letter clips) join them in such way appear 1 after another, looks type writing.
the documentation got few examples of moving letters, might of great use, however. thank
this way of achieving want. key define resizing logic in named function instead of using lambda
.
import os 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('test.png') .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')
edit
the code follows answers second part of question (i don't know if it'd better make 2 separate questions).
from __future__ import division moviepy.editor import * moviepy.video.tools.segmenting import findobjects def clip_typewriter(text, duration_clip, duration_effect): # `duration_effect` time last letter appears. clip_text = textclip( text, color='white', font='consolas', fontsize=80, kerning=3, ) letters = findobjects(clip_text, preview=false) # select start time in seconds each letter found: n = len(letters) times_start = [duration_effect*i/(n-1) in range(n)] clips_letters = [] i, letter in enumerate(letters): clips_letters.append(letter .set_position(letter.screenpos) .set_start(times_start[i]) .set_end(duration_clip) # here can add key sounds using `set_audio`. ) return compositevideoclip(clips_letters, size=clip_text.size) if __name__ == '__main__': screensize = (320, 180) fps = 12 clip_1 = clip_typewriter('hello', 2, 1).set_start(1).set_position('center') clip_2 = clip_typewriter('world', 2, 1).set_start(4).set_position('center') clip_final = compositevideoclip([clip_1, clip_2], size=screensize) clip_final.write_gif('test_typewriter.gif', fps=fps)
result: