I'm facing an issue while migrating from MoviePy v1 to MoviePy v2. In v1, I could apply a transparency mask to an ImageClip, making certain areas of the clip transparent. However, in MoviePy v2, the same approach doesn't seem to work.
Expected Behavior
The ImageClip should become transparent in areas defined by the mask.
Observed Behavior
In MoviePy v2, the mask is just overlayed on top of image.
Working Code (MoviePy v1)
This code works perfectly fine in MoviePy 1.0.3:
from moviepy.editor import ImageClip, CompositeVideoClip
image_clip = ImageClip("mask.png").set_duration(5)
mask_clip = ImageClip("blueDark.png", ismask=True).set_duration(5)
image_clip = image_clip.set_mask(mask_clip)
video = CompositeVideoClip([image_clip], bg_color=(90, 90, 90))
video.preview()
Non-Working Code (MoviePy v2)
Here’s the MoviePy v2 equivalent, where I updated the function and parameter names according to the new version:
import moviepy as mpy
image_clip = mpy.ImageClip("mask.png").with_duration(5)
mask_clip = mpy.ImageClip("blueDark.png", is_mask=True).with_duration(5)
image_clip = image_clip.with_mask(mask_clip)
video = mpy.CompositeVideoClip([image_clip], bg_color=(90, 90, 90))
video.preview()
Additional Details
Versions Installed:
MoviePy v1: pip install moviepy==1.0.3 pygame
MoviePy v2: pip install -U moviepy
I have attached both mask.png and blueDark.png in case someone wants to reproduce the issue.
Turns out it works when I use RGBA image instead of greyscale image for the mask. Even though MoviePy docs explicitly mention that mask should always be greyscale image, but it seems to work with RGBA images only.