Skip to content

Video editing with Python

Continue transition of effect from function to method. All audio effect done.

osaajanic0c2f6bd7dec
diff --git a/moviepy/audio/fx/audio_delay.py b/moviepy/audio/fx/AudioDelay.py
similarity index 54%
rename from moviepy/audio/fx/audio_delay.py
rename to moviepy/audio/fx/AudioDelay.py
index 845ce21c..0cb346e8 100644
--- a/moviepy/audio/fx/audio_delay.py
+++ b/moviepy/audio/fx/AudioDelay.py
@@ -1,12 +1,15 @@
import numpy as np
from moviepy.audio.AudioClip import CompositeAudioClip
-from moviepy.audio.fx.multiply_volume import multiply_volume
-from moviepy.decorators import audio_video_fx
+from moviepy.audio.fx.MultiplyVolume import MultiplyVolume
+from moviepy.decorators import audio_video_effect
+from moviepy.Clip import Clip
+from moviepy.Effect import Effect
+from dataclasses import dataclass
-@audio_video_fx
-def audio_delay(clip, offset=0.2, n_repeats=8, decay=1):
+@dataclass
+class AudioDelay(Effect) :
"""Repeats audio certain number of times at constant intervals multiplying
their volume levels using a linear space in the range 1 to ``decay`` argument
value.
@@ -31,8 +34,8 @@ def audio_delay(clip, offset=0.2, n_repeats=8, decay=1):
--------
>>> from moviepy import *
- >>> videoclip = AudioFileClip('myaudio.wav').fx(
- ... audio_delay, offset=.2, n_repeats=10, decayment=.2
+ >>> videoclip = AudioFileClip('myaudio.wav').with_effect(
+ ... afx.AudioDelay(offset=.2, n_repeats=10, decayment=.2)
... )
>>> # stereo A note
@@ -40,17 +43,22 @@ def audio_delay(clip, offset=0.2, n_repeats=8, decay=1):
... [np.sin(440 * 2 * np.pi * t), np.sin(880 * 2 * np.pi * t)]
... ).T
... clip = AudioClip(make_frame=make_frame, duration=0.1, fps=44100)
- ... clip = audio_delay(clip, offset=.2, n_repeats=11, decay=0)
+ ... clip = clip.with_effect(afx.AudioDelay(offset=.2, n_repeats=11, decay=0))
"""
- decayments = np.linspace(1, max(0, decay), n_repeats + 1)
- return CompositeAudioClip(
- [
- clip.copy(),
- *[
- multiply_volume(
- clip.with_start((rep + 1) * offset), decayments[rep + 1]
- )
- for rep in range(n_repeats)
- ],
- ]
- )
+
+ offset: float = 0.2
+ n_repeats: int = 8
+ decay: float = 1
+
+ @audio_video_effect
+ def apply(self, clip: Clip) -> Clip:
+ decayments = np.linspace(1, max(0, self.decay), self.n_repeats + 1)
+ return CompositeAudioClip(
+ [
+ clip.copy(),
+ *[
+ clip.with_start((rep + 1) * self.offset).with_effect(MultiplyVolume(decayments[rep + 1]))
+ for rep in range(self.n_repeats)
+ ],
+ ]
+ )
diff --git a/moviepy/audio/fx/AudioFadeIn.py b/moviepy/audio/fx/AudioFadeIn.py
new file mode 100644
index 00000000..ac1ef93b
--- /dev/null
+++ b/moviepy/audio/fx/AudioFadeIn.py
@@ -0,0 +1,59 @@
+import numpy as np
+
+from moviepy.decorators import audio_video_effect
+from moviepy.tools import convert_to_seconds
+
+from moviepy.Clip import Clip
+from moviepy.Effect import Effect
+from dataclasses import dataclass
+
+@dataclass
+class AudioFadeIn(Effect) :
+ """Return an audio (or video) clip that is first mute, then the
+ sound arrives progressively over ``duration`` seconds.
+
+ Parameters
+ ----------
+
+ duration : float
+ How long does it take for the sound to return to its normal level.
+
+ Examples
+ --------
+
+ >>> clip = VideoFileClip("media/chaplin.mp4")
+ >>> clip.with_effect(AudioFadeIn("00:00:06"))
+ """
+
+ duration: float
+
+ def __post_init__ (self) :
+ self.duration = convert_to_seconds(self.duration)
+
+
+ def _mono_factor_getter(self):
+ return lambda t, duration: np.minimum(t / duration, 1)
+
+
+ def _stereo_factor_getter(self, nchannels):
+ def getter(t, duration):
+ factor = np.minimum(t / duration, 1)
+ return np.array([factor for _ in range(nchannels)]).T
+
+ return getter
+
+
+ @audio_video_effect
+ def apply(self, clip: Clip) -> Clip:
+ if clip.duration is None:
+ raise ValueError("Attribute 'duration' not set")
+
+ get_factor = (
+ self._mono_factor_getter()
+ if clip.nchannels == 1
+ else self._stereo_factor_getter(clip.nchannels)
+ )
+
+ return clip.transform(
+ lambda get_frame, t: get_factor(t, self.duration) * get_frame(t),
+ )
diff --git a/moviepy/audio/fx/AudioFadeOut.py b/moviepy/audio/fx/AudioFadeOut.py
new file mode 100644
index 00000000..42dab8b6
--- /dev/null
+++ b/moviepy/audio/fx/AudioFadeOut.py
@@ -0,0 +1,61 @@
+import numpy as np
+
+from moviepy.decorators import audio_video_effect
+from moviepy.tools import convert_to_seconds
+
+from moviepy.Clip import Clip
+from moviepy.Effect import Effect
+from dataclasses import dataclass
+
+@dataclass
+class AudioFadeOut(Effect) :
+ """Return a sound clip where the sound fades out progressively
+ over ``duration`` seconds at the end of the clip.
+
+ Parameters
+ ----------
+
+ duration : float
+ How long does it take for the sound to reach the zero level at the end
+ of the clip.
+
+ Examples
+ --------
+
+ >>> clip = VideoFileClip("media/chaplin.mp4")
+ >>> clip.with_effect(afx.AudioFadeOut("00:00:06"))
+ """
+
+ duration: float
+
+ def __post_init__ (self) :
+ self.duration = convert_to_seconds(self.duration)
+
+
+ def _mono_factor_getter(self, clip_duration):
+ return lambda t, duration: np.minimum(1.0 * (clip_duration - t) / duration, 1)
+
+
+ def _stereo_factor_getter(self, clip_duration, nchannels):
+ def getter(t, duration):
+ factor = np.minimum(1.0 * (clip_duration - t) / duration, 1)
+ return np.array([factor for _ in range(nchannels)]).T
+
+ return getter
+
+
+ @audio_video_effect
+ def apply(self, clip: Clip) -> Clip:
+ if clip.duration is None:
+ raise ValueError("Attribute 'duration' not set")
+
+ get_factor = (
+ self._mono_factor_getter(clip.duration)
+ if clip.nchannels == 1
+ else self._stereo_factor_getter(clip.duration, clip.nchannels)
+ )
+
+ return clip.transform(
+ lambda get_frame, t: get_factor(t, self.duration) * get_frame(t),
+ keep_duration=True,
+ )
diff --git a/moviepy/audio/fx/AudioLoop.py b/moviepy/audio/fx/AudioLoop.py
new file mode 100644
index 00000000..ef540d1d
--- /dev/null
+++ b/moviepy/audio/fx/AudioLoop.py
@@ -0,0 +1,35 @@
+from moviepy.audio.AudioClip import concatenate_audioclips
+from moviepy.decorators import audio_video_effect
+
+from moviepy.Clip import Clip
+from moviepy.Effect import Effect
+from dataclasses import dataclass
+
+@dataclass
+class AudioLoop(Effect) :
+ """Loops over an audio clip.
+
+ Returns an audio clip that plays the given clip either
+ `n_loops` times, or during `duration` seconds.
+
+ Examples
+ --------
+
+ >>> from moviepy import *
+ >>> videoclip = VideoFileClip('myvideo.mp4')
+ >>> music = AudioFileClip('music.ogg')
+ >>> audio = music.with_effect(afx.AudioLoop(duration=videoclip.duration))
+ >>> videoclip.with_audio(audio)
+
+ """
+
+ n_loops: int = None
+ duration: float = None
+
+ @audio_video_effect
+ def apply(self, clip: Clip) -> Clip:
+ if self.duration is not None:
+ self.n_loops = int(self.duration / clip.duration) + 1
+ return concatenate_audioclips(self.n_loops * [clip]).with_duration(self.duration)
+
+ return concatenate_audioclips(self.n_loops * [clip])
diff --git a/moviepy/audio/fx/AudioNormalize.py b/moviepy/audio/fx/AudioNormalize.py
new file mode 100644
index 00000000..b78a395b
--- /dev/null
+++ b/moviepy/audio/fx/AudioNormalize.py
@@ -0,0 +1,29 @@
+from moviepy.audio.fx.MultiplyVolume import MultiplyVolume
+from moviepy.decorators import audio_video_effect
+
+from moviepy.Clip import Clip
+from moviepy.Effect import Effect
+from dataclasses import dataclass
+
+@dataclass
+class AudioNormalize(Effect) :
+ """Return a clip whose volume is normalized to 0db.
+
+ Return an audio (or video) clip whose audio volume is normalized
+ so that the maximum volume is at 0db, the maximum achievable volume.
+
+ Examples
+ --------
+
+ >>> from moviepy import *
+ >>> videoclip = VideoFileClip('myvideo.mp4').with_effect(afx.AudioNormalize())
+
+ """
+
+ @audio_video_effect
+ def apply(self, clip: Clip) -> Clip:
+ max_volume = clip.max_volume()
+ if max_volume == 0:
+ return clip
+ else:
+ return clip.with_effect(MultiplyVolume(1 / max_volume))
diff --git a/moviepy/audio/fx/MultiplyStereoVolume.py b/moviepy/audio/fx/MultiplyStereoVolume.py
new file mode 100644
index 00000000..fdf90d3b
--- /dev/null
+++ b/moviepy/audio/fx/MultiplyStereoVolume.py
@@ -0,0 +1,38 @@
+from moviepy.decorators import audio_video_effect
+
+from moviepy.Clip import Clip
+from moviepy.Effect import Effect
+from dataclasses import dataclass
+
+@dataclass
+class MultiplyStereoVolume(Effect) :
+ """For a stereo audioclip, this function enables to change the volume
+ of the left and right channel separately (with the factors `left`
+ and `right`). Makes a stereo audio clip in which the volume of left
+ and right is controllable.
+
+ Examples
+ --------
+
+ >>> from moviepy import AudioFileClip
+ >>> music = AudioFileClip('music.ogg')
+ >>> audio_r = music.with_effect(afx.MultiplyStereoVolume(left=0, right=1)) # mute left channel/s
+ >>> audio_h = music.with_effect(afx.MultiplyStereoVolume(left=0.5, right=0.5))) # half audio
+ """
+
+ left: float = 1
+ right: float = 1
+
+ @audio_video_effect
+ def apply(self, clip: Clip) -> Clip:
+
+ def stereo_volume(get_frame, t):
+ frame = get_frame(t)
+ if len(frame) == 1: # mono
+ frame *= self.left if self.left is not None else self.right
+ else: # stereo, stereo surround...
+ for i in range(len(frame[0])): # odd channels are left
+ frame[:, i] *= self.left if i % 2 == 0 else self.right
+ return frame
+
+ return clip.transform(stereo_volume)
diff --git a/moviepy/audio/fx/MultiplyVolume.py b/moviepy/audio/fx/MultiplyVolume.py
new file mode 100644
index 00000000..c327817b
--- /dev/null
+++ b/moviepy/audio/fx/MultiplyVolume.py
@@ -0,0 +1,86 @@
+import numpy as np
+
+from moviepy.decorators import audio_video_effect
+from moviepy.tools import convert_to_seconds
+
+from moviepy.Clip import Clip
+from moviepy.Effect import Effect
+from dataclasses import dataclass
+
+@dataclass
+class MultiplyVolume(Effect) :
+ """Returns a clip with audio volume multiplied by the
+ value `factor`. Can be applied to both audio and video clips.
+
+ Parameters
+ ----------
+
+ factor : float
+ Volume multiplication factor.
+
+ start_time : float, optional
+ Time from the beginning of the clip until the volume transformation
+ begins to take effect, in seconds. By default at the beginning.
+
+ end_time : float, optional
+ Time from the beginning of the clip until the volume transformation
+ ends to take effect, in seconds. By default at the end.
+
+ Examples
+ --------
+
+ >>> from moviepy import AudioFileClip
+ >>>
+ >>> music = AudioFileClip('music.ogg')
+ >>> doubled_audio_clip = clip.with_effect(MultiplyVolume(2)) # doubles audio volume
+ >>> half_audio_clip = clip.with_effect(MultiplyVolume(0.5)) # half audio
+ >>>
+ >>> # silenced clip during one second at third
+ >>> silenced_clip = clip.with_effect(MultiplyVolume(0, start_time=2, end_time=3))
+ """
+
+ factor: float
+ start_time = None
+ end_time = None
+
+ def __post_init__ (self) :
+ if self.start_time is not None:
+ self.start_time = convert_to_seconds(self.start_time)
+
+ if self.start_time is not None:
+ self.end_time = convert_to_seconds(self.end_time)
+
+
+ def _multiply_volume_in_range(factor, start_time, end_time, nchannels):
+ def factors_filter(factor, t):
+ return np.array([factor if start_time <= t_ <= end_time else 1 for t_ in t])
+
+ def multiply_stereo_volume(get_frame, t):
+ return np.multiply(
+ get_frame(t),
+ np.array([factors_filter(factor, t) for _ in range(nchannels)]).T,
+ )
+
+ def multiply_mono_volume(get_frame, t):
+ return np.multiply(get_frame(t), factors_filter(factor, t))
+
+ return multiply_mono_volume if nchannels == 1 else multiply_stereo_volume
+
+
+ @audio_video_effect
+ def apply(self, clip: Clip) -> Clip:
+ if self.start_time is None and self.end_time is None:
+ return clip.transform(
+ lambda get_frame, t: self.factor * get_frame(t),
+ keep_duration=True,
+ )
+
+ return clip.transform(
+ self._multiply_volume_in_range(
+ self.factor,
+ clip.start if self.start_time is None else self.start_time,
+ clip.end if self.end_time is None else self.end_time,
+ clip.nchannels,
+ ),
+ keep_duration=True,
+ )
\ No newline at end of file
diff --git a/moviepy/audio/fx/__init__.py b/moviepy/audio/fx/__init__.py
index 626afa8c..dc3d462a 100644
--- a/moviepy/audio/fx/__init__.py
+++ b/moviepy/audio/fx/__init__.py
@@ -1,20 +1,20 @@
# import every video fx function
-from moviepy.audio.fx.audio_delay import audio_delay
-from moviepy.audio.fx.audio_fadein import audio_fadein
-from moviepy.audio.fx.audio_fadeout import audio_fadeout
-from moviepy.audio.fx.audio_loop import audio_loop
-from moviepy.audio.fx.audio_normalize import audio_normalize
-from moviepy.audio.fx.multiply_stereo_volume import multiply_stereo_volume
-from moviepy.audio.fx.multiply_volume import multiply_volume
+from moviepy.audio.fx.AudioDelay import AudioDelay
+from moviepy.audio.fx.AudioFadeIn import AudioFadeIn
+from moviepy.audio.fx.AudioFadeOut import AudioFadeOut
+from moviepy.audio.fx.AudioLoop import AudioLoop
+from moviepy.audio.fx.AudioNormalize import AudioNormalize
+from moviepy.audio.fx.MultiplyStereoVolume import MultiplyStereoVolume
+from moviepy.audio.fx.MultiplyVolume import MultiplyVolume
__all__ = (
- "audio_delay",
- "audio_fadein",
- "audio_fadeout",
- "audio_loop",
- "audio_normalize",
- "multiply_stereo_volume",
- "multiply_volume",
+ "AudioDelay",
+ "AudioFadeIn",
+ "AudioFadeOut",
+ "AudioLoop",
+ "AudioNormalize",
+ "MultiplyStereoVolume",
+ "MultiplyVolume",
)
diff --git a/moviepy/audio/fx/audio_fadein.py b/moviepy/audio/fx/audio_fadein.py
deleted file mode 100644
index e62c6412..00000000
--- a/moviepy/audio/fx/audio_fadein.py
+++ /dev/null
@@ -1,45 +0,0 @@
-import numpy as np
-
-from moviepy.decorators import audio_video_fx, convert_parameter_to_seconds
-
-
-def _mono_factor_getter():
- return lambda t, duration: np.minimum(t / duration, 1)
-
-
-def _stereo_factor_getter(nchannels):
- def getter(t, duration):
- factor = np.minimum(t / duration, 1)
- return np.array([factor for _ in range(nchannels)]).T
-
- return getter
-
-
-@audio_video_fx
-@convert_parameter_to_seconds(["duration"])
-def audio_fadein(clip, duration):
- """Return an audio (or video) clip that is first mute, then the
- sound arrives progressively over ``duration`` seconds.
-
- Parameters
- ----------
-
- duration : float
- How long does it take for the sound to return to its normal level.
-
- Examples
- --------
-
- >>> clip = VideoFileClip("media/chaplin.mp4")
- >>> clip.fx(audio_fadein, "00:00:06")
- """
- get_factor = (
- _mono_factor_getter()
- if clip.nchannels == 1
- else _stereo_factor_getter(clip.nchannels)
- )
-
- return clip.transform(
- lambda get_frame, t: get_factor(t, duration) * get_frame(t),
- keep_duration=True,
- )
diff --git a/moviepy/audio/fx/audio_fadeout.py b/moviepy/audio/fx/audio_fadeout.py
deleted file mode 100644
index c7a1316c..00000000
--- a/moviepy/audio/fx/audio_fadeout.py
+++ /dev/null
@@ -1,51 +0,0 @@
-import numpy as np
-
-from moviepy.decorators import (
- audio_video_fx,
- convert_parameter_to_seconds,
- requires_duration,
-)
-
-
-def _mono_factor_getter(clip_duration):
- return lambda t, duration: np.minimum(1.0 * (clip_duration - t) / duration, 1)
-
-
-def _stereo_factor_getter(clip_duration, nchannels):
- def getter(t, duration):
- factor = np.minimum(1.0 * (clip_duration - t) / duration, 1)
- return np.array([factor for _ in range(nchannels)]).T
-
- return getter
-
-
-@audio_video_fx
-@requires_duration
-@convert_parameter_to_seconds(["duration"])
-def audio_fadeout(clip, duration):
- """Return a sound clip where the sound fades out progressively
- over ``duration`` seconds at the end of the clip.
-
- Parameters
- ----------
-
- duration : float
- How long does it take for the sound to reach the zero level at the end
- of the clip.
-
- Examples
- --------
-
- >>> clip = VideoFileClip("media/chaplin.mp4")
- >>> clip.fx(audio_fadeout, "00:00:06")
- """
- get_factor = (
- _mono_factor_getter(clip.duration)
- if clip.nchannels == 1
- else _stereo_factor_getter(clip.duration, clip.nchannels)
- )
-
- return clip.transform(
- lambda get_frame, t: get_factor(t, duration) * get_frame(t),
- keep_duration=True,
- )
diff --git a/moviepy/audio/fx/audio_loop.py b/moviepy/audio/fx/audio_loop.py
deleted file mode 100644
index c047aa18..00000000
--- a/moviepy/audio/fx/audio_loop.py
+++ /dev/null
@@ -1,26 +0,0 @@
-from moviepy.audio.AudioClip import concatenate_audioclips
-from moviepy.decorators import audio_video_fx
-
-
-@audio_video_fx
-def audio_loop(clip, n_loops=None, duration=None):
- """Loops over an audio clip.
-
- Returns an audio clip that plays the given clip either
- `n_loops` times, or during `duration` seconds.
-
- Examples
- --------
-
- >>> from moviepy import *
- >>> videoclip = VideoFileClip('myvideo.mp4')
- >>> music = AudioFileClip('music.ogg')
- >>> audio = afx.audio_loop( music, duration=videoclip.duration)
- >>> videoclip.with_audio(audio)
-
- """
- if duration is not None:
- n_loops = int(duration / clip.duration) + 1
- return concatenate_audioclips(n_loops * [clip]).with_duration(duration)
-
- return concatenate_audioclips(n_loops * [clip])
diff --git a/moviepy/audio/fx/audio_normalize.py b/moviepy/audio/fx/audio_normalize.py
deleted file mode 100644
index cf0a96a1..00000000
--- a/moviepy/audio/fx/audio_normalize.py
+++ /dev/null
@@ -1,25 +0,0 @@
-from moviepy.audio.fx.multiply_volume import multiply_volume
-from moviepy.decorators import audio_video_fx
-
-
-@audio_video_fx
-def audio_normalize(clip):
- """Return a clip whose volume is normalized to 0db.
-
- Return an audio (or video) clip whose audio volume is normalized
- so that the maximum volume is at 0db, the maximum achievable volume.
-
- Examples
- --------
-
- >>> from moviepy import *
- >>> videoclip = VideoFileClip('myvideo.mp4').fx(afx.audio_normalize)
-
- """
- max_volume = clip.max_volume()
- if max_volume == 0:
- # Nothing to normalize.
- # Avoids a divide by zero error.
- return clip.copy()
- else:
- return multiply_volume(clip, 1 / max_volume)
diff --git a/moviepy/audio/fx/multiply_stereo_volume.py b/moviepy/audio/fx/multiply_stereo_volume.py
deleted file mode 100644
index 982892ae..00000000
--- a/moviepy/audio/fx/multiply_stereo_volume.py
+++ /dev/null
@@ -1,29 +0,0 @@
-from moviepy.decorators import audio_video_fx
-
-
-@audio_video_fx
-def multiply_stereo_volume(clip, left=1, right=1):
- """For a stereo audioclip, this function enables to change the volume
- of the left and right channel separately (with the factors `left`
- and `right`). Makes a stereo audio clip in which the volume of left
- and right is controllable.
-
- Examples
- --------
-
- >>> from moviepy import AudioFileClip
- >>> music = AudioFileClip('music.ogg')
- >>> audio_r = music.multiply_stereo_volume(left=0, right=1) # mute left channel/s
- >>> audio_h = music.multiply_stereo_volume(left=0.5, right=0.5) # half audio
- """
-
- def stereo_volume(get_frame, t):
- frame = get_frame(t)
- if len(frame) == 1: # mono
- frame *= left if left is not None else right
- else: # stereo, stereo surround...
- for i in range(len(frame[0])): # odd channels are left
- frame[:, i] *= left if i % 2 == 0 else right
- return frame
-
- return clip.transform(stereo_volume, keep_duration=True)
diff --git a/moviepy/audio/fx/multiply_volume.py b/moviepy/audio/fx/multiply_volume.py
deleted file mode 100644
index 6d7a86b4..00000000
--- a/moviepy/audio/fx/multiply_volume.py
+++ /dev/null
@@ -1,68 +0,0 @@
-import numpy as np
-
-from moviepy.decorators import audio_video_fx, convert_parameter_to_seconds
-
-
-def _multiply_volume_in_range(factor, start_time, end_time, nchannels):
- def factors_filter(factor, t):
- return np.array([factor if start_time <= t_ <= end_time else 1 for t_ in t])
-
- def multiply_stereo_volume(get_frame, t):
- return np.multiply(
- get_frame(t),
- np.array([factors_filter(factor, t) for _ in range(nchannels)]).T,
- )
-
- def multiply_mono_volume(get_frame, t):
- return np.multiply(get_frame(t), factors_filter(factor, t))
-
- return multiply_mono_volume if nchannels == 1 else multiply_stereo_volume
-
-
-@audio_video_fx
-@convert_parameter_to_seconds(["start_time", "end_time"])
-def multiply_volume(clip, factor, start_time=None, end_time=None):
- """Returns a clip with audio volume multiplied by the
- value `factor`. Can be applied to both audio and video clips.
-
- Parameters
- ----------
-
- factor : float
- Volume multiplication factor.
-
- start_time : float, optional
- Time from the beginning of the clip until the volume transformation
- begins to take effect, in seconds. By default at the beginning.
-
- end_time : float, optional
- Time from the beginning of the clip until the volume transformation
- ends to take effect, in seconds. By default at the end.
-
- Examples
- --------
-
- >>> from moviepy import AudioFileClip
- >>>
- >>> music = AudioFileClip('music.ogg')
- >>> doubled_audio_clip = clip.multiply_volume(2) # doubles audio volume
- >>> half_audio_clip = clip.multiply_volume(0.5) # half audio
- >>>
- >>> # silenced clip during one second at third
- >>> silenced_clip = clip.multiply_volume(0, start_time=2, end_time=3)
- """
- if start_time is None and end_time is None:
- return clip.transform(
- lambda get_frame, t: factor * get_frame(t),
- keep_duration=True,
- )
-
- return clip.transform(
- _multiply_volume_in_range(
- factor,
- clip.start if start_time is None else start_time,
- clip.end if end_time is None else end_time,
- clip.nchannels,
- ),
- keep_duration=True,
- )
diff --git a/moviepy/decorators.py b/moviepy/decorators.py
index 78beaef4..97447479 100644
--- a/moviepy/decorators.py
+++ b/moviepy/decorators.py
@@ -61,6 +61,21 @@ def requires_fps(func, clip, *args, **kwargs):
return func(clip, *args, **kwargs)
+def audio_video_effect(func, effect, clip, *args, **kwargs):
+ """Use an audio function on a video/audio clip.
+
+ This decorator tells that the function func (audioclip -> audioclip)
+ can be also used on a video clip, at which case it returns a
+ videoclip with unmodified video and modified audio.
+ """
+ if hasattr(clip, "audio"):
+ if clip.audio is not None:
+ clip.audio = func(effect, clip.audio, *args, **kwargs)
+ return clip
+ else:
+ return func(effect, clip, *args, **kwargs)
+
@decorator.decorator
def audio_video_fx(func, clip, *args, **kwargs):
"""Use an audio function on a video/audio clip.
diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.py
index bc07785a..26f3ac96 100644
--- a/moviepy/video/VideoClip.py
+++ b/moviepy/video/VideoClip.py
@@ -958,14 +958,6 @@ class VideoClip(Clip):
"""
self.audio = None
- @outplace
- def afx(self, fun, *args, **kwargs):
- """Transform the clip's audio.
-
- Return a new clip whose audio has been transformed by ``fun``.
- """
- self.audio = self.audio.fx(fun, *args, **kwargs)
-
def __add__(self, other):
if isinstance(other, VideoClip):
from moviepy.video.compositing.CompositeVideoClip import concatenate_videoclips