From 4c674c81361bb7e21ddd349e7c1c8bf8643ef5b2 Mon Sep 17 00:00:00 2001 From: RaPoSpectre Date: Tue, 11 Apr 2017 10:53:14 -0500 Subject: [PATCH] fix issue #334 (#336) fix resize video when time changed trigger a error --- moviepy/video/VideoClip.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.py index 20cdc70e3..c5504cbfd 100644 --- a/moviepy/video/VideoClip.py +++ b/moviepy/video/VideoClip.py @@ -530,6 +530,24 @@ def fl_image(self, image_func, apply_to=[]): # 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 @@ def blit_on(self, picture, t): 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