Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoom effect trembling #183

Closed
feqwix opened this issue Jul 9, 2015 · 5 comments
Closed

Zoom effect trembling #183

feqwix opened this issue Jul 9, 2015 · 5 comments

Comments

@feqwix
Copy link

feqwix commented Jul 9, 2015

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!

@Zulko
Copy link
Owner

Zulko commented Jul 9, 2015

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.

@feqwix
Copy link
Author

feqwix commented Jul 9, 2015

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!

@Zulko
Copy link
Owner

Zulko commented Jul 14, 2015

Great, closing this one.

@Zulko Zulko closed this as completed Jul 14, 2015
@rahulbagal
Copy link

rahulbagal commented May 25, 2017

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 ?

@kiranbeethoju
Copy link

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)



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants