Hello! I don't know if this may be an issue or bad coding from my side.
I was trying to concatenate some pictures with a slow zoom-in effect, but the results were not the expected. The resulting zoom effect was shaky at different speeds.
Here is an example code:
#!/usr/bin/env/ python
# -*- coding: utf-8 -*-
import os
from moviepy.editor import *
dir = os.path.split(os.path.realpath(__file__))[0]
img = os.path.join(dir, 'test.jpg')
out = os.path.join(dir, 'test-zoom.mp4')
screensize = (640,360)
clip1 = (ImageClip(img)
.resize(height=screensize[1]/2)
.resize(lambda t : 1+0.02*t)
.set_duration(7)
)
clip2 = (ImageClip(img)
.resize(height=screensize[1]/2)
.resize(lambda t : 1+0.2*t)
.set_duration(7)
)
vid = concatenate_videoclips([clip1, clip2])
vid = CompositeVideoClip([vid.set_position(('center', 'center'))],
size=screensize)
vid.write_videofile(out, fps=24)
OS: Win7 x32.
Here is the resulting video: https://vid.me/vdwW
Here, the picture used: http://oi61.tinypic.com/503979.jpg
How can this be corrected?
This module is amazing! Big thanks!
I think it's simply because you video is very low-resolution, in videos of higher resolution you don't see so much shaking.
One solution could be to work on super-sized clips:
Hopefully this will give you the same result with less trembling.
That solution worked perfectly! Here is a _mwe_:
#!/usr/bin/env/ python
# -*- coding: utf-8 -*-
import os
from moviepy.editor import *
dir = os.path.split(os.path.realpath(__file__))[0]
img = os.path.join(dir, 'test.jpg')
out = os.path.join(dir, 'test-zoom.mp4')
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)
)
clip = CompositeVideoClip([clip]).resize(width=screensize[0])
vid = CompositeVideoClip([clip.set_position(('center', 'center'))],
size=screensize)
vid.write_videofile(out, fps=24)
which led to the folowing result, without noticeable trembling: https://vid.me/A4dr
Thank you!
Great, closing this one.
Hi, this is a good solution but I need to scale it from a very small image at centre to full screen image. 4x scaling does not improve it much . If I do 10x scaling , memory requirement & rendering time is too much for HD video. Is there any another way , something like vector graphics ?
A minor change in lambda time will make your zoom effect smoother, try tweaking
at _.resize(lambda t : 1+0.1*t)_ try changing the number from 0.1 to 0.2 or 0.3
import os
from moviepy.editor import *
dir = os.path.split(os.path.realpath(__file__))[0]
img = os.path.join(dir, 'test.jpg')
out = os.path.join(dir, 'test-zoom.mp4')
screensize = (640,360)
clip = (ImageClip(img)
.resize(height=screensize[1]*4)
.resize(lambda t : 1+0.1*t)
.set_position(('center', 'center'))
.set_duration(10)
)
clip = CompositeVideoClip([clip]).resize(width=screensize[0])
vid = CompositeVideoClip([clip.set_position(('center', 'center'))],
size=screensize)
vid.write_videofile(out, fps=24)
Most helpful comment
That solution worked perfectly! Here is a _mwe_:
which led to the folowing result, without noticeable trembling: https://vid.me/A4dr
Thank you!