Skip to content

Commit

Permalink
Merge branch 'master' into rewrite-CompositeAudioClip
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja authored Jan 19, 2021
2 parents 1990716 + 7183eaa commit 7a63f1e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed calling `audio_normalize` on a clip with no sound causing `ZeroDivisionError` [\#1401](https://github.com/Zulko/moviepy/pull/1401)
- Fixed `freeze` FX was freezing at time minus 1 second as the end [\#1461](https://github.com/Zulko/moviepy/pull/1461)
- `AudioClip.max_volume(stereo=True)` now can return more than 2 channels [\#1464](https://github.com/Zulko/moviepy/pull/1464)
- Fixed `Clip.cutout` transformation not being applied to audio [\#1468](https://github.com/Zulko/moviepy/pull/1468)
- Fixed arguments inconsistency in `video.tools.drawing.color_gradient` [\#1467](https://github.com/Zulko/moviepy/pull/1467)
- Fixed `fps` not defined in `CompositeAudioClip` at initialization [\#1462](https://github.com/Zulko/moviepy/pull/1462)


Expand Down
8 changes: 2 additions & 6 deletions moviepy/Clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,6 @@ def subclip(self, start_time=0, end_time=None):

return new_clip

@apply_to_mask
@apply_to_audio
@convert_parameter_to_seconds(["start_time", "end_time"])
def cutout(self, start_time, end_time):
"""
Expand All @@ -429,15 +427,13 @@ def cutout(self, start_time, end_time):
"""

new_clip = self.time_transform(
lambda t: t + (t >= start_time) * (end_time - start_time)
lambda t: t + (t >= start_time) * (end_time - start_time),
apply_to=["audio", "mask"],
)

if self.duration is not None:

return new_clip.with_duration(self.duration - (end_time - start_time))

else:

return new_clip

@requires_duration
Expand Down
26 changes: 12 additions & 14 deletions moviepy/video/tools/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ def color_gradient(

if shape == "bilinear":
if vector is None:
if p2 is None:
raise ValueError("You must provide either 'p2' or 'vector'")
vector = np.array(p2) - np.array(p1)

m1, m2 = [
Expand All @@ -124,20 +126,18 @@ def color_gradient(

p1 = np.array(p1[::-1]).astype(float)

if vector is None and p2:
p2 = np.array(p2[::-1])
vector = p2 - p1
else:
vector = np.array(vector[::-1])
p2 = p1 + vector

if vector is not None:
norm = np.linalg.norm(vector)

M = np.dstack(np.meshgrid(range(w), range(h))[::-1]).astype(float)

if shape == "linear":
if vector is None:
if p2 is not None:
vector = np.array(p2[::-1]) - p1
else:
raise ValueError("You must provide either 'p2' or 'vector'")
else:
vector = np.array(vector[::-1])

norm = np.linalg.norm(vector)
n_vec = vector / norm ** 2 # norm 1/norm(vector)

p1 = p1 + offset * vector
Expand All @@ -148,10 +148,7 @@ def color_gradient(
return arr * color_1 + (1 - arr) * color_2

elif shape == "radial":
if radius is None:
radius = norm

if radius == 0:
if (radius or 0) == 0:
arr = np.ones((h, w))
else:
arr = (np.sqrt(((M - p1) ** 2).sum(axis=2))) - offset * radius
Expand All @@ -161,6 +158,7 @@ def color_gradient(
if color_1.size > 1:
arr = np.dstack(3 * [arr])
return (1 - arr) * color_1 + arr * color_2
raise ValueError("Invalid shape, should be either 'radial', 'linear' or 'bilinear'")


def color_split(
Expand Down

0 comments on commit 7a63f1e

Please sign in to comment.