-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into doc-accel_decel
- Loading branch information
Showing
16 changed files
with
360 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,45 @@ | ||
import numpy as np | ||
|
||
from moviepy.decorators import audio_video_fx | ||
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. | ||
""" | ||
def fading(get_frame, t): | ||
frame = get_frame(t) | ||
Parameters | ||
---------- | ||
duration : float | ||
How long does it take for the sound to return to its normal level. | ||
if np.isscalar(t): | ||
factor = min(1.0 * t / duration, 1) | ||
factor = np.array([factor, factor]) | ||
else: | ||
factor = np.minimum(1.0 * t / duration, 1) | ||
factor = np.vstack([factor, factor]).T | ||
return factor * frame | ||
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(fading, keep_duration=True) | ||
return clip.transform( | ||
lambda get_frame, t: get_factor(t, duration) * get_frame(t), | ||
keep_duration=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,51 @@ | ||
import numpy as np | ||
|
||
from moviepy.decorators import audio_video_fx, requires_duration | ||
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. | ||
""" | ||
def fading(get_frame, t): | ||
frame = get_frame(t) | ||
Parameters | ||
---------- | ||
duration : float | ||
How long does it take for the sound to reach the zero level at the end | ||
of the clip. | ||
if np.isscalar(t): | ||
factor = min(1.0 * (clip.duration - t) / duration, 1) | ||
factor = np.array([factor, factor]) | ||
else: | ||
factor = np.minimum(1.0 * (clip.duration - t) / duration, 1) | ||
factor = np.vstack([factor, factor]).T | ||
return factor * frame | ||
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(fading, keep_duration=True) | ||
return clip.transform( | ||
lambda get_frame, t: get_factor(t, duration) * get_frame(t), | ||
keep_duration=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.