Video editing with Python
make flake8 happier
Valentin Zulkower0db382dfbe6c
diff --git a/moviepy/Effect.py b/moviepy/Effect.pyindex 7f1fdb3d..6f8bdf77 100644--- a/moviepy/Effect.py+++ b/moviepy/Effect.py@@ -1,3 +1,5 @@+"""Defines the base class for all effects in MoviePy."""+import copy as _copyfrom abc import ABCMeta, abstractmethod@@ -5,7 +7,7 @@ from moviepy.Clip import Clipclass Effect(metaclass=ABCMeta):- """Base abastract class for all effects in MoviePy.+ """Base abstract class for all effects in MoviePy.Any new effect have to extend this base class."""@@ -22,7 +24,8 @@ class Effect(metaclass=ABCMeta):By using copy, we ensure we can use the same effect object multiple times whilemaintaining the same behavior/result.- In a way, copy make the effect himself beeing kind of indempotent."""+ In a way, copy makes the effect himself being kind of idempotent.+ """return _copy.copy(self)@abstractmethoddiff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.pyindex fc76fbd0..e262ef69 100644--- a/moviepy/video/VideoClip.py+++ b/moviepy/video/VideoClip.py@@ -523,8 +523,7 @@ class VideoClip(Clip):@convert_masks_to_RGB@convert_parameter_to_seconds(["t"])def show(self, t=0, with_mask=True):- """- Splashes the frame of clip corresponding to time ``t``.+ """Splashes the frame of clip corresponding to time ``t``.Parameters----------@@ -565,9 +564,9 @@ class VideoClip(Clip):def preview(self, fps=15, audio=True, audio_fps=22050, audio_buffersize=3000, audio_nbytes=2):- """- Displays the clip in a window, at the given frames per second (of movie)- rate. It will avoid that the clip be played faster than normal, but it+ """Displays the clip in a window, at the given frames per second.++ It will avoid that the clip be played faster than normal, but itcannot avoid the clip to be played slower than normal if the computationsare complex. In this case, try reducing the ``fps``.@@ -594,11 +593,9 @@ class VideoClip(Clip):-------->>> from moviepy import *- >>>>>> clip = VideoFileClip("media/chaplin.mp4")>>> clip.preview(fps=10, audio=False)"""-audio = audio and (self.audio is not None)audio_flag = Nonevideo_flag = None@@ -690,7 +687,6 @@ class VideoClip(Clip):shape (tuple)The desired shape of the resulting array.-"""pre_shape = pre_array.shapedx = shape[0] - pre_shape[0]@@ -1463,9 +1459,7 @@ class TextClip(ImageClip):def break_text(width, text, font, font_size, stroke_width, align, spacing) -> List[str]:- """- Break text to never overflow a width- """+ """Break text to never overflow a width"""img = Image.new("RGB", (1, 1))font_pil = ImageFont.truetype(font, font_size)draw = ImageDraw.Draw(img)@@ -1506,10 +1500,7 @@ class TextClip(ImageClip):max_width=None,allow_break=False,) -> tuple[int, int]:- """- Find dimensions a text will occupy- return a tuple (width, height)- """+ """Find dimensions a text will occupy, return a tuple (width, height)"""img = Image.new("RGB", (1, 1))font_pil = ImageFont.truetype(font, font_size)draw = ImageDraw.Draw(img)@@ -1559,9 +1550,7 @@ class TextClip(ImageClip):height=None,allow_break=False,):- """- Find the best font size to fit as optimally as possible- """+ """Find the best font size to fit as optimally as possible"""max_font_size = widthmin_font_size = 1diff --git a/moviepy/video/fx/AccelDecel.py b/moviepy/video/fx/AccelDecel.pyindex a8b14698..982daa8d 100644--- a/moviepy/video/fx/AccelDecel.py+++ b/moviepy/video/fx/AccelDecel.py@@ -65,6 +65,7 @@ class AccelDecel(Effect):return old_duration * _f((t / new_duration) ** soonness)def apply(self, clip):+ """Apply the effect to the clip."""if self.new_duration is None:self.new_duration = clip.durationdiff --git a/moviepy/video/fx/BlackAndWhite.py b/moviepy/video/fx/BlackAndWhite.pyindex 604b778e..bf15ad35 100644--- a/moviepy/video/fx/BlackAndWhite.py+++ b/moviepy/video/fx/BlackAndWhite.py@@ -18,6 +18,7 @@ class BlackAndWhite(Effect):preserve_luminosity: bool = Truedef apply(self, clip):+ """Apply the effect to the clip."""if self.RGB is None:self.RGB = [1, 1, 1]diff --git a/moviepy/video/fx/Blink.py b/moviepy/video/fx/Blink.pyindex 726ce087..2274c02d 100644--- a/moviepy/video/fx/Blink.py+++ b/moviepy/video/fx/Blink.py@@ -15,6 +15,7 @@ class Blink(Effect):duration_off: floatdef apply(self, clip):+ """Apply the effect to the clip."""if clip.mask is None:clip = clip.with_add_mask()diff --git a/moviepy/video/fx/Crop.py b/moviepy/video/fx/Crop.pyindex cb564acd..81e7f502 100644--- a/moviepy/video/fx/Crop.py+++ b/moviepy/video/fx/Crop.py@@ -45,6 +45,7 @@ class Crop(Effect):"""def apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""if self.width and self.x1 is not None:self.x2 = self.x1 + self.widthelif self.width and self.x2 is not None:diff --git a/moviepy/video/fx/CrossFadeIn.py b/moviepy/video/fx/CrossFadeIn.pyindex d8881bd6..09d179c6 100644--- a/moviepy/video/fx/CrossFadeIn.py+++ b/moviepy/video/fx/CrossFadeIn.py@@ -14,6 +14,7 @@ class CrossFadeIn(Effect):duration: floatdef apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""if clip.duration is None:raise ValueError("Attribute 'duration' not set")diff --git a/moviepy/video/fx/CrossFadeOut.py b/moviepy/video/fx/CrossFadeOut.pyindex 03841309..5076240a 100644--- a/moviepy/video/fx/CrossFadeOut.py+++ b/moviepy/video/fx/CrossFadeOut.py@@ -14,6 +14,7 @@ class CrossFadeOut(Effect):duration: floatdef apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""if clip.duration is None:raise ValueError("Attribute 'duration' not set")diff --git a/moviepy/video/fx/EvenSize.py b/moviepy/video/fx/EvenSize.pyindex e024c831..bea2a559 100644--- a/moviepy/video/fx/EvenSize.py+++ b/moviepy/video/fx/EvenSize.py@@ -9,6 +9,7 @@ class EvenSize(Effect):"""Crops the clip to make dimensions even."""def apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""w, h = clip.sizew_even = w % 2 == 0h_even = h % 2 == 0diff --git a/moviepy/video/fx/FadeIn.py b/moviepy/video/fx/FadeIn.pyindex 9a5746b4..2078fcbc 100644--- a/moviepy/video/fx/FadeIn.py+++ b/moviepy/video/fx/FadeIn.py@@ -20,6 +20,7 @@ class FadeIn(Effect):initial_color: list = Nonedef apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""if self.initial_color is None:self.initial_color = 0 if clip.is_mask else [0, 0, 0]diff --git a/moviepy/video/fx/FadeOut.py b/moviepy/video/fx/FadeOut.pyindex 75b47ee8..c0f3dcbf 100644--- a/moviepy/video/fx/FadeOut.py+++ b/moviepy/video/fx/FadeOut.py@@ -20,6 +20,7 @@ class FadeOut(Effect):final_color: list = Nonedef apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""if clip.duration is None:raise ValueError("Attribute 'duration' not set")diff --git a/moviepy/video/fx/Freeze.py b/moviepy/video/fx/Freeze.pyindex ebaf7552..40dc3c9f 100644--- a/moviepy/video/fx/Freeze.py+++ b/moviepy/video/fx/Freeze.py@@ -23,6 +23,7 @@ class Freeze(Effect):padding_end: float = 0def apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""if clip.duration is None:raise ValueError("Attribute 'duration' not set")diff --git a/moviepy/video/fx/FreezeRegion.py b/moviepy/video/fx/FreezeRegion.pyindex 62c6112f..dd9b7173 100644--- a/moviepy/video/fx/FreezeRegion.py+++ b/moviepy/video/fx/FreezeRegion.py@@ -40,6 +40,7 @@ class FreezeRegion(Effect):mask: Clip = Nonedef apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""if self.region is not None:x1, y1, _x2, _y2 = self.regionfreeze = (diff --git a/moviepy/video/fx/GammaCorrection.py b/moviepy/video/fx/GammaCorrection.pyindex df81a4f5..1582e26b 100644--- a/moviepy/video/fx/GammaCorrection.py+++ b/moviepy/video/fx/GammaCorrection.py@@ -11,6 +11,8 @@ class GammaCorrection(Effect):gamma: floatdef apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""+def filter(im):corrected = 255 * (1.0 * im / 255) ** self.gammareturn corrected.astype("uint8")diff --git a/moviepy/video/fx/HeadBlur.py b/moviepy/video/fx/HeadBlur.pyindex f22fc399..83aec1a7 100644--- a/moviepy/video/fx/HeadBlur.py+++ b/moviepy/video/fx/HeadBlur.py@@ -21,6 +21,7 @@ class HeadBlur(Effect):intensity: float = Nonedef apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""if self.intensity is None:self.intensity = int(2 * self.radius / 3)diff --git a/moviepy/video/fx/InvertColors.py b/moviepy/video/fx/InvertColors.pyindex 3df536fe..cf12a72b 100644--- a/moviepy/video/fx/InvertColors.py+++ b/moviepy/video/fx/InvertColors.py@@ -13,5 +13,6 @@ class InvertColors(Effect):"""def apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""maxi = 1.0 if clip.is_mask else 255return clip.image_transform(lambda f: maxi - f)diff --git a/moviepy/video/fx/Loop.py b/moviepy/video/fx/Loop.pyindex e283569f..c8c8c779 100644--- a/moviepy/video/fx/Loop.py+++ b/moviepy/video/fx/Loop.py@@ -25,6 +25,7 @@ class Loop(Effect):duration: float = Nonedef apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""if clip.duration is None:raise ValueError("Attribute 'duration' not set")diff --git a/moviepy/video/fx/LumContrast.py b/moviepy/video/fx/LumContrast.pyindex 4ada93b8..cfba9a60 100644--- a/moviepy/video/fx/LumContrast.py+++ b/moviepy/video/fx/LumContrast.py@@ -13,6 +13,8 @@ class LumContrast(Effect):contrast_threshold: float = 127def apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""+def image_filter(im):im = 1.0 * im # float conversioncorrected = (diff --git a/moviepy/video/fx/MakeLoopable.py b/moviepy/video/fx/MakeLoopable.pyindex c8ada834..5632b7c1 100644--- a/moviepy/video/fx/MakeLoopable.py+++ b/moviepy/video/fx/MakeLoopable.py@@ -21,6 +21,7 @@ class MakeLoopable(Effect):overlap_duration: floatdef apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""clip2 = clip.with_effects([CrossFadeIn(self.overlap_duration)]).with_start(clip.duration - self.overlap_duration)diff --git a/moviepy/video/fx/Margin.py b/moviepy/video/fx/Margin.pyindex 91f46328..77c5389c 100644--- a/moviepy/video/fx/Margin.py+++ b/moviepy/video/fx/Margin.py@@ -46,6 +46,7 @@ class Margin(Effect):opacity: float = 1.0def add_margin(self, clip: Clip):+ """Add margins to the clip."""if (self.opacity != 1.0) and (clip.mask is None) and not (clip.is_mask):clip = clip.with_add_mask()@@ -79,6 +80,7 @@ class Margin(Effect):return clip.transform(filter)def apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""# We apply once on clip and once on mask if we have oneclip = self.add_margin(clip=clip)diff --git a/moviepy/video/fx/MaskColor.py b/moviepy/video/fx/MaskColor.pyindex cdd24aec..2cb92bd4 100644--- a/moviepy/video/fx/MaskColor.py+++ b/moviepy/video/fx/MaskColor.py@@ -26,6 +26,7 @@ class MaskColor(Effect):stiffness: float = 1def apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""color = np.array(self.color)def hill(x):diff --git a/moviepy/video/fx/MasksAnd.py b/moviepy/video/fx/MasksAnd.pyindex bd7b4e3b..a67d8d27 100644--- a/moviepy/video/fx/MasksAnd.py+++ b/moviepy/video/fx/MasksAnd.py@@ -33,6 +33,7 @@ class MasksAnd(Effect):other_clip: Union[Clip, np.ndarray]def apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""# to ensure that 'and' of two ImageClips will be an ImageClipif isinstance(self.other_clip, ImageClip):self.other_clip = self.other_clip.imgdiff --git a/moviepy/video/fx/MasksOr.py b/moviepy/video/fx/MasksOr.pyindex d1ce74ab..7d215c4e 100644--- a/moviepy/video/fx/MasksOr.py+++ b/moviepy/video/fx/MasksOr.py@@ -33,6 +33,7 @@ class MasksOr(Effect):other_clip: Union[Clip, np.ndarray]def apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""# to ensure that 'or' of two ImageClips will be an ImageClipif isinstance(self.other_clip, ImageClip):self.other_clip = self.other_clip.imgdiff --git a/moviepy/video/fx/MirrorX.py b/moviepy/video/fx/MirrorX.pyindex becbe179..d623610d 100644--- a/moviepy/video/fx/MirrorX.py+++ b/moviepy/video/fx/MirrorX.py@@ -12,4 +12,5 @@ class MirrorX(Effect):apply_to: Union[List, str] = "mask"def apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""return clip.image_transform(lambda img: img[:, ::-1], apply_to=self.apply_to)diff --git a/moviepy/video/fx/MirrorY.py b/moviepy/video/fx/MirrorY.pyindex e96c9b77..8d8d5b0d 100644--- a/moviepy/video/fx/MirrorY.py+++ b/moviepy/video/fx/MirrorY.py@@ -12,4 +12,5 @@ class MirrorY(Effect):apply_to: Union[List, str] = "mask"def apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""return clip.image_transform(lambda img: img[::-1], apply_to=self.apply_to)diff --git a/moviepy/video/fx/MultiplyColor.py b/moviepy/video/fx/MultiplyColor.pyindex 4976f8db..6a3e1b70 100644--- a/moviepy/video/fx/MultiplyColor.py+++ b/moviepy/video/fx/MultiplyColor.py@@ -17,6 +17,7 @@ class MultiplyColor(Effect):factor: floatdef apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""return clip.image_transform(lambda frame: np.minimum(255, (self.factor * frame)).astype("uint8"))diff --git a/moviepy/video/fx/MultiplySpeed.py b/moviepy/video/fx/MultiplySpeed.pyindex 72c9558e..68a99b31 100644--- a/moviepy/video/fx/MultiplySpeed.py+++ b/moviepy/video/fx/MultiplySpeed.py@@ -17,6 +17,7 @@ class MultiplySpeed(Effect):final_duration: float = Nonedef apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""if self.final_duration:self.factor = 1.0 * clip.duration / self.final_durationdiff --git a/moviepy/video/fx/Painting.py b/moviepy/video/fx/Painting.pyindex 66801662..30484c6f 100644--- a/moviepy/video/fx/Painting.py+++ b/moviepy/video/fx/Painting.py@@ -57,6 +57,7 @@ class Painting(Effect):return paintingdef apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""return clip.image_transform(lambda im: self.to_painting(im, self.saturation, self.black))diff --git a/moviepy/video/fx/Resize.py b/moviepy/video/fx/Resize.pyindex 67ca0a7e..a7baa5d1 100644--- a/moviepy/video/fx/Resize.py+++ b/moviepy/video/fx/Resize.py@@ -50,6 +50,7 @@ class Resize(Effect):return np.array(resized_pil)def apply(self, clip):+ """Apply the effect to the clip."""w, h = clip.sizeif self.new_size is not None:diff --git a/moviepy/video/fx/Rotate.py b/moviepy/video/fx/Rotate.pyindex e6c9f2af..b19c5e4e 100644--- a/moviepy/video/fx/Rotate.py+++ b/moviepy/video/fx/Rotate.py@@ -58,6 +58,7 @@ class Rotate(Effect):bg_color: tuple = Nonedef apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""try:resample = {"bilinear": Image.BILINEAR,diff --git a/moviepy/video/fx/Scroll.py b/moviepy/video/fx/Scroll.pyindex 555c15a0..e7b17e2f 100644--- a/moviepy/video/fx/Scroll.py+++ b/moviepy/video/fx/Scroll.py@@ -38,6 +38,7 @@ class Scroll(Effect):self.apply_to = apply_todef apply(self, clip):+ """Apply the effect to the clip."""if self.h is None:self.h = clip.hdiff --git a/moviepy/video/fx/SlideIn.py b/moviepy/video/fx/SlideIn.pyindex 0462c70a..56277e09 100644--- a/moviepy/video/fx/SlideIn.py+++ b/moviepy/video/fx/SlideIn.py@@ -46,6 +46,7 @@ class SlideIn(Effect):side: strdef apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""w, h = clip.sizepos_dict = {"left": lambda t: (min(0, w * (t / self.duration - 1)), "center"),diff --git a/moviepy/video/fx/SlideOut.py b/moviepy/video/fx/SlideOut.pyindex d0030879..49e4c2a4 100644--- a/moviepy/video/fx/SlideOut.py+++ b/moviepy/video/fx/SlideOut.py@@ -46,6 +46,7 @@ class SlideOut(Effect):side: strdef apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""if clip.duration is None:raise ValueError("Attribute 'duration' not set")diff --git a/moviepy/video/fx/SuperSample.py b/moviepy/video/fx/SuperSample.pyindex f3b64213..9c18d81c 100644--- a/moviepy/video/fx/SuperSample.py+++ b/moviepy/video/fx/SuperSample.py@@ -16,6 +16,8 @@ class SuperSample(Effect):n_frames: intdef apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""+def filter(get_frame, t):timings = np.linspace(t - self.d, t + self.d, self.n_frames)frame_average = np.mean(diff --git a/moviepy/video/fx/TimeMirror.py b/moviepy/video/fx/TimeMirror.pyindex 6ea27785..d90238e9 100644--- a/moviepy/video/fx/TimeMirror.py+++ b/moviepy/video/fx/TimeMirror.py@@ -13,6 +13,7 @@ class TimeMirror(Effect):"""def apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""if clip.duration is None:raise ValueError("Attribute 'duration' not set")diff --git a/moviepy/video/fx/TimeSymmetrize.py b/moviepy/video/fx/TimeSymmetrize.pyindex adf9be9d..c85f4f8a 100644--- a/moviepy/video/fx/TimeSymmetrize.py+++ b/moviepy/video/fx/TimeSymmetrize.py@@ -15,6 +15,7 @@ class TimeSymmetrize(Effect):"""def apply(self, clip: Clip) -> Clip:+ """Apply the effect to the clip."""if clip.duration is None:raise ValueError("Attribute 'duration' not set")diff --git a/moviepy/video/io/ffplay_previewer.py b/moviepy/video/io/ffplay_previewer.pyindex 23bfb685..28f3569a 100644--- a/moviepy/video/io/ffplay_previewer.py+++ b/moviepy/video/io/ffplay_previewer.py@@ -120,7 +120,6 @@ def ffplay_preview_video(A thread event that video will set after first frame has been shown. If notprovided, we simply ignore"""-with FFPLAY_VideoPreviewer(clip.size, fps, pixel_format) as previewer:first_frame = Truefor t, frame in clip.iter_frames(with_times=True, fps=fps, dtype="uint8"):diff --git a/moviepy/video/io/gif_writers.py b/moviepy/video/io/gif_writers.pyindex 57a69a33..ceb913d7 100644--- a/moviepy/video/io/gif_writers.py+++ b/moviepy/video/io/gif_writers.py@@ -9,9 +9,7 @@ from moviepy.decorators import requires_duration, use_clip_fps_by_default@requires_duration@use_clip_fps_by_defaultdef write_gif_with_imageio(clip, filename, fps=None, loop=0, logger="bar"):- """- Writes the gif with the Python library ImageIO (calls FreeImage).- """+ """Writes the gif with the Python library ImageIO (calls FreeImage)."""logger = proglog.default_bar_logger(logger)with iio.imopen(filename, "w", plugin="pillow") as writer:diff --git a/tests/test_doc_examples.py b/tests/test_doc_examples.pyindex bd77317f..2e5ac5c2 100644--- a/tests/test_doc_examples.py+++ b/tests/test_doc_examples.py@@ -1,5 +1,6 @@"""Try to run all the documentation examples with runpy and check they dont raise-exception"""+exceptions.+"""import osimport pathlib