#Python 🐍 – concatenate video and add blur effect 🎦 using moviepy and scikit-image

Buy Me A Coffee

Hi !

Today I’ll share another cool sample using moviepy, and I’ll also use scikit-image to add some extra effects.

This one is again based on the cat videos, and perform this steps:

  • Using the cat video, open 3 video objects with different segments: 1-2 seconds, 2-4 seconds, 4-6 seconds
  • Resize each video to be smaller
  • Apply a blur effect to the 2nd video
  • Concatenate the 3 videos
  • Export the output to Gif

The code is super simple:

from moviepy.video.compositing.concatenate import concatenate_videoclips
from skimage.filters import gaussian
from moviepy.editor import VideoFileClip, clips_array, concatenate_videoclips
def blur(image):
""" Returns a blurred (radius=4 pixels) version of the image """
return gaussian(image.astype(float), sigma=4)
# open video and resize to 460
clip1 = VideoFileClip("cat1.mp4").subclip(1,2).resize(width=200)
clip2 = VideoFileClip("cat1.mp4").subclip(2,4).resize(width=200)
clip3 = VideoFileClip("cat1.mp4").subclip(4,6).resize(width=200)
# blur clip 2
clip2_blurred = clip2.fl_image( blur )
# final
final_clip = concatenate_videoclips([clip1, clip2_blurred, clip3])
final_clip.write_gif("blurdemo.gif")

Super, easy. It and the output is a 2MB gif file.

Source video, the full version is here.

Happy coding!

Greetings

El Bruno



¿Con ganas de ponerte al día?

En Lemoncode te ofrecemos formación online impartida por profesionales que se baten el cobre en consultoría:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.