Skip to content

Video editing with Python

harmonize usage of with_ for any modificating method who return a copy

osaajanif16b197634ec
diff --git a/moviepy/decorators.py b/moviepy/decorators.py
index 621e3585..78beaef4 100644
--- a/moviepy/decorators.py
+++ b/moviepy/decorators.py
@@ -110,7 +110,7 @@ def convert_path_to_string(varnames):
def add_mask_if_none(func, clip, *args, **kwargs):
"""Add a mask to the clip if there is none."""
if clip.mask is None:
- clip = clip.add_mask()
+ clip = clip.with_add_mask()
return func(clip, *args, **kwargs)
diff --git a/moviepy/video/compositing/CompositeVideoClip.py b/moviepy/video/compositing/CompositeVideoClip.py
index fec0b0d2..14e032a0 100644
--- a/moviepy/video/compositing/CompositeVideoClip.py
+++ b/moviepy/video/compositing/CompositeVideoClip.py
@@ -102,7 +102,7 @@ class CompositeVideoClip(VideoClip):
# compute mask if necessary
if transparent:
maskclips = [
- (clip.mask if (clip.mask is not None) else clip.add_mask().mask)
+ (clip.mask if (clip.mask is not None) else clip.with_add_mask().mask)
.with_position(clip.pos)
.with_end(clip.end)
.with_start(clip.start, change_end=False)
diff --git a/moviepy/video/fx/margin.py b/moviepy/video/fx/margin.py
index 3c618693..bacba5b2 100644
--- a/moviepy/video/fx/margin.py
+++ b/moviepy/video/fx/margin.py
@@ -44,7 +44,7 @@ def margin(
Opacity of the margin. Setting this value to 0 yields transparent margins.
"""
if (opacity != 1.0) and (clip.mask is None) and not (clip.is_mask):
- clip = clip.add_mask()
+ clip = clip.with_add_mask()
if margin_size is not None:
left = right = top = bottom = margin_size
diff --git a/moviepy/video/fx/rotate.py b/moviepy/video/fx/rotate.py
index 592553cf..f6190ab8 100644
--- a/moviepy/video/fx/rotate.py
+++ b/moviepy/video/fx/rotate.py
@@ -46,7 +46,7 @@ def rotate(
and ``bg_color`` are not ``None``, the package ``pillow`` must be installed,
and there will be black borders. You can make them transparent with:
- >>> new_clip = clip.add_mask().rotate(72)
+ >>> new_clip = clip.with_add_mask().rotate(72)
Parameters
----------
diff --git a/moviepy/video/tools/segmenting.py b/moviepy/video/tools/segmenting.py
index 96c53f9d..5d281a29 100644
--- a/moviepy/video/tools/segmenting.py
+++ b/moviepy/video/tools/segmenting.py
@@ -37,7 +37,7 @@ def find_objects(clip, size_threshold=500, preview=False):
"""
image = clip.get_frame(0)
if not clip.mask: # pragma: no cover
- clip = clip.add_mask()
+ clip = clip.with_add_mask()
mask = clip.mask.get_frame(0)
labelled, num_features = ndi.measurements.label(image[:, :, 0])