Skip to content

Video editing with Python

Revert "Merge pull request #2426 from KimigaiiWuyi/master"

osaajanie57ce3e54173
diff --git a/moviepy/Clip.py b/moviepy/Clip.py
index 0493c4dd..2b636177 100644
--- a/moviepy/Clip.py
+++ b/moviepy/Clip.py
@@ -206,10 +206,10 @@ class Clip:
return new_clip
- @outplace
@apply_to_mask
@apply_to_audio
@convert_parameter_to_seconds(["t"])
+ @outplace
def with_start(self, t, change_end=True):
"""Returns a copy of the clip, with the ``start`` attribute set
to ``t``, which can be expressed in seconds (15.35), in (min, sec),
@@ -247,10 +247,10 @@ class Clip:
elif self.end is not None:
self.duration = self.end - self.start
- @outplace
@apply_to_mask
@apply_to_audio
@convert_parameter_to_seconds(["t"])
+ @outplace
def with_end(self, t):
"""Returns a copy of the clip, with the ``end`` attribute set to ``t``,
which can be expressed in seconds (15.35), in (min, sec), in
@@ -281,10 +281,10 @@ class Clip:
else:
self.duration = self.end - self.start
- @outplace
@apply_to_mask
@apply_to_audio
@convert_parameter_to_seconds(["duration"])
+ @outplace
def with_duration(self, duration, change_end=True):
"""Returns a copy of the clip, with the ``duration`` attribute set to
``t``, which can be expressed in seconds (15.35), in (min, sec), in
diff --git a/moviepy/audio/AudioClip.py b/moviepy/audio/AudioClip.py
index 293445f3..3a04b40e 100644
--- a/moviepy/audio/AudioClip.py
+++ b/moviepy/audio/AudioClip.py
@@ -6,7 +6,6 @@
import numbers
import os
-from typing import List
import numpy as np
import proglog
@@ -421,7 +420,7 @@ class CompositeAudioClip(AudioClip):
return zero + sum(sounds)
-def concatenate_audioclips(clips: List[AudioClip]):
+def concatenate_audioclips(clips):
"""Concatenates one AudioClip after another, in the order that are passed
to ``clips`` parameter.
diff --git a/moviepy/decorators.py b/moviepy/decorators.py
index edf16d41..3bdd13db 100644
--- a/moviepy/decorators.py
+++ b/moviepy/decorators.py
@@ -1,31 +1,19 @@
"""Decorators used by moviepy."""
-import functools
import inspect
import os
-from typing import Callable, Concatenate, ParamSpec, TypeVar
import decorator
from moviepy.tools import convert_to_seconds
-T = TypeVar('T')
-P = ParamSpec('P')
-
-
-def outplace(func: Callable[Concatenate[T, P], None]) -> Callable[Concatenate[T, P], T]:
- @functools.wraps(func)
- def wrapper(obj: T, *args: P.args, **kwargs: P.kwargs) -> T:
- if not hasattr(obj, 'copy') or not callable(getattr(obj, 'copy')):
- raise TypeError(
- f"Object of type {type(obj).__name__} must have a callable copy() method for @outplace"
- )
- new_obj: T = obj.copy()
- func(new_obj, *args, **kwargs)
- return new_obj
-
- return wrapper
+def outplace(func, clip, *args, **kwargs):
+ """Applies ``func(clip.copy(), *args, **kwargs)`` and returns ``clip.copy()``."""
+ new_clip = clip.copy()
+ func(new_clip, *args, **kwargs)
+ return new_clip
@decorator.decorator
diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.py
index e018610c..280af56c 100644
--- a/moviepy/video/VideoClip.py
+++ b/moviepy/video/VideoClip.py
@@ -965,8 +965,8 @@ class VideoClip(Clip):
"""Remove the clip's mask."""
self.mask = None
- @outplace
@add_mask_if_none
+ @outplace
def with_opacity(self, opacity):
"""Set the opacity/transparency level of the clip.
@@ -975,8 +975,8 @@ class VideoClip(Clip):
"""
self.mask = self.mask.image_transform(lambda pic: opacity * pic)
- @outplace
@apply_to_mask
+ @outplace
def with_position(self, pos, relative=False):
"""Set the clip's position in compositions.
@@ -1009,8 +1009,8 @@ class VideoClip(Clip):
else:
self.pos = lambda t: pos
- @outplace
@apply_to_mask
+ @outplace
def with_layer_index(self, index):
"""Set the clip's layer in compositions. Clips with a greater ``layer``
attribute will be displayed on top of others.