Moviepy: Zoom effect trembling

Created on 9 Jul 2015  路  5Comments  路  Source: Zulko/moviepy

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!

Most helpful comment

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!

All 5 comments

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:

  • resize all your clips 4x when you load them
  • Make the zoom with exactly the same code that you have
  • downsize the final result x0.25

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)



Was this page helpful?
0 / 5 - 0 ratings

Related issues

tburrows13 picture tburrows13  路  3Comments

bilel picture bilel  路  4Comments

PyB1l picture PyB1l  路  3Comments

Netherdrake picture Netherdrake  路  5Comments

Swiffers picture Swiffers  路  4Comments