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

Change speed of clip based on a curve? #46

Closed
cnelsonsic opened this issue Jun 16, 2014 · 8 comments
Closed

Change speed of clip based on a curve? #46

cnelsonsic opened this issue Jun 16, 2014 · 8 comments

Comments

@cnelsonsic
Copy link

Does anyone have any ideas as to how to change the speed of a clip gradually over a bezier curve?

Is there any demand for this feature?
Am I the only one who wants this?

@Zulko
Copy link
Owner

Zulko commented Jun 19, 2014

I am not sure that I understand exactly what you want, but you can change the timeline of a clip very freely with clip.fl_time(some_time_warping_function). Here is an example in which the timeline is replaced by t+sin(t), so that the clip will gradually be sped up and slowed down, with a period of 2Pi seconds (this applies to the audio and the video):

clip = VideoFileClip("my_video.mp4")
clip2 = clip.fl_time( lambda t: t+ sin(t) )
clip2.to_videofile("my_time_warped_video.mp4")

To slow down a clip progressively a clip of N seconds you would write something like

clip.fl_time(lambda t: N*t/(N+t)).set_duration(2*N)

Now if you have a profile of the speed over time, you could integrate this profile to get the profile of a timeline, which you can tranform into a function timeline(t) and then clip.fl_time(timeline) would do the trick.

I don't know if there is a proper Bezier curve library in Python. That would certainly be a job for Scipy.

@cnelsonsic
Copy link
Author

That sounds like what I'm after. I'll give it a shot.
Thanks!

@Zulko
Copy link
Owner

Zulko commented Jun 19, 2014

Cool. Note that 'going back in time' (i.e. negative speed) is possible for the video but not fully tested with the audio (you might run into a bug).

@Zulko Zulko closed this as completed Jul 28, 2014
@SreeniASU
Copy link

Hi Zulko,
I tried this and it seems that the speed of the video clip changes, whereas the accompanying audio doesn't speed up. The file format is mp4. Can you please help?

@Zulko
Copy link
Owner

Zulko commented Mar 21, 2015

Try this, with apply_to=['audio'] in fl_time:

clip = VideoFileClip("my_video.mp4")
clip2 = clip.fl_time( lambda t: t+ sin(t), apply_to=['audio'] )
# maybe indicate a new duration for the clip:
clip2 = clip2.set_duration(some_new_duration)
clip2.write_videofile("my_time_warped_video.mp4")

@SreeniASU
Copy link

Thanks Zulko for your quick response. It worked like a charm. But, I have one more concern. On changing the playback rate of the video the voice of the person in it also changes. That is, if I double or halve the speed of video, the dialogues are clear, but the voice becomes annoyingly unpleasant. This doesn't happen if I play the original video in a video player with 2x or 0.5x speed. Is there any way to avoid that?

@isdito
Copy link

isdito commented Jan 19, 2023

hello,
I'm looking for a way to slow down a point in the video but then x time later it returns to normal speed.

Imagine recording it at 50 fps or 100 fps per second while its playback is constant at 1/25, when the car is close then use those frames. Typical of after effects programs is a retime curve.

Slow down a point of the video and then continue normal

any help please

@keikoro
Copy link
Collaborator

keikoro commented Feb 6, 2023

Please note that you are commenting on old, closed issues meaning only very few people will see your comments.

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

5 participants