Skip to content

Video editing with Python

fix issue #334 (#336)

RaPoSpectre4c674c81361b
diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.py
index 20cdc70e..c5504cbf 100644
--- a/moviepy/video/VideoClip.py
+++ b/moviepy/video/VideoClip.py
@@ -530,6 +530,24 @@ class VideoClip(Clip):
# C O M P O S I T I N G
+ def fill_array(self, pre_array, shape=(0, 0)):
+ pre_shape = pre_array.shape
+ dx = shape[0] - pre_shape[0]
+ dy = shape[1] - pre_shape[1]
+ post_array = pre_array
+ if dx < 0:
+ post_array = pre_array[:shape[0]]
+ elif dx > 0:
+ x_1 = [[[1, 1, 1]] * pre_shape[1]] * dx
+ post_array = np.vstack((pre_array, x_1))
+ if dy < 0:
+ post_array = post_array[:, :shape[1]]
+ elif dy > 0:
+ x_1 = [[[1, 1, 1]] * dy] * post_array.shape[0]
+ post_array = np.hstack((post_array, x_1))
+ return post_array
+
+
def blit_on(self, picture, t):
"""
Returns the result of the blit of the clip's frame at time `t`
@@ -549,6 +567,9 @@ class VideoClip(Clip):
img = self.get_frame(ct)
mask = (None if (self.mask is None) else
self.mask.get_frame(ct))
+ if mask is not None:
+ if (img.shape[0] != mask.shape[0]) or (img.shape[1] != mask.shape[1]):
+ img = self.fill_array(img, mask.shape)
hi, wi = img.shape[:2]
# SET POSITION