Skip to content
Advertisement

MoviePy: How to move an image across a video with multiple steps?

I want to move an image in multiple steps, where the background is a video. Currently this is my code:

JavaScript

Its a watermark that displays at the top left of the video, which quickly slides away to the left in a smooth fashion.

However, I want it to “pop” out towards the right, before sliding all the way to the left. So I think I would need 2 steps, the first one moving the image towards the right, and the second moving it all the way to the left (which the code above does)

How would I do this?

Thanks!

EDIT:

Here is all my code:

JavaScript

And here is what it currently looks like:

Advertisement

Answer

I am not sure that I got it exactly as you indented…

The main concept is dividing the movement to two stages:

  • Moving to the left:

    JavaScript
  • Moving to the right (most_left_col = -image.size[0]):

    JavaScript

The lambda may be as follows:

JavaScript

end_t is computed in such way that np.exp(10*(end_t - first))*(-1) = most_left_col.

The result is that end_t = np.log(-most_left_col)/10 + first

That way when the entire watermark is out of the image, it starts moving to the other direction.


Cone sample:

JavaScript

For testing we may create original_video.mp4 and watermark.png using FFmpeg CLI:

ffmpeg -y -f lavfi -i color=black:size=720x1280:rate=10:duration=10 -vcodec libx264 original_video.mp4
ffmpeg -y -f lavfi -i testsrc=size=720x1280:rate=1:duration=1 -frames 1 -update 1 watermark.png

Sample output:
enter image description here

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement