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

More posts in my blog ElBruno.com.

More info in https://beacons.ai/elbruno



¿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:

One response to “#Python 🐍 – concatenate video and add blur effect 🎦 using moviepy and scikit-image”

  1. This is awesome! I made a similar script using moviepy where I convert a vertical recorded video into horizontal using the same method: overlaying it over a blurred image. This has inspired me to make a post about it.

    Like

Leave a reply to Evan Mann Cancel reply

Discover more from El Bruno

Subscribe now to keep reading and get access to the full archive.

Continue reading