Skip to content

Video editing with Python

Working mask memoization for composite video clip

osaajani811ae9252784
diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.py
index 58d5eadc..b17bb4d9 100644
--- a/moviepy/video/VideoClip.py
+++ b/moviepy/video/VideoClip.py
@@ -896,7 +896,7 @@ class VideoClip(Clip):
safe_alpha = np.where(final_alpha == 0, 1.0, final_alpha)
result = (frame * alpha_clip + bg * alpha_bg * (1 - alpha_clip)) / safe_alpha
- bg_copy[y1_bg:y2_bg, x1_bg:x2_bg] = result.astype(np.uint8)
+ bg_copy[y1_bg:y2_bg, x1_bg:x2_bg] = np.round(result).astype(np.uint8)
bg_mask_copy[y1_bg:y2_bg, x1_bg:x2_bg] = final_alpha.squeeze()
return (bg_copy, bg_mask_copy)
diff --git a/moviepy/video/compositing/CompositeVideoClip.py b/moviepy/video/compositing/CompositeVideoClip.py
index 79786e04..64e8dc93 100644
--- a/moviepy/video/compositing/CompositeVideoClip.py
+++ b/moviepy/video/compositing/CompositeVideoClip.py
@@ -199,7 +199,7 @@ class CompositeVideoClip(VideoClip):
current_frame, current_mask = clip.compose_on(
current_frame, t, current_mask
)
- if self.mask and self.memoize_mask and t not in self.mask.precomputed:
+ if self.mask and self.memoize_mask:
self.mask.precomputed[t] = current_mask
return current_frame