Skip to content

Commit

Permalink
Rebase with master
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja committed Jan 22, 2021
2 parents 6fefbf4 + b576403 commit cc9e1e7
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Renamed `cols_widths` argument of `clips_array` function by `cols_heights` [\#1465](https://github.com/Zulko/moviepy/pull/1465)
- `video_nframes` attribute of dictionary returned from `ffmpeg_parse_infos` renamed to `video_n_frames` [\#1471](https://github.com/Zulko/moviepy/pull/1471)
- Renamed `colorx` FX by `multiply_color` [\#1475](https://github.com/Zulko/moviepy/pull/1475)
- Renamed `speedx` FX by `multiply_speed` [\#1478](https://github.com/Zulko/moviepy/pull/1478)
- `make_loopable` transition must be used as FX [\#1477](https://github.com/Zulko/moviepy/pull/1477)

### Deprecated <!-- for soon-to-be removed features -->
Expand Down
2 changes: 1 addition & 1 deletion docs/getting_started/effects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Much better! There are already many effects implemented in the modules ``moviepy
from moviepy import *
clip = (VideoFileClip("myvideo.avi")
.fx( vfx.resize, width=460) # resize (keep aspect ratio)
.fx( vfx.speedx, 2) # double the speed
.fx( vfx.multiply_speed, 2) # double the speed
.fx( vfx.multiply_color, 0.5)) # darken the picture

For convenience, fx methods such as ``resize`` can be called in a simpler way: ``clip.resize(...)`` instead of ``clip.fx( vfx.resize, ...)``
Expand Down
2 changes: 1 addition & 1 deletion docs/ref/videofx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ the module ``video.fx`` is loaded as ``vfx`` and you can use ``vfx.multiply_colo
mirror_x
mirror_y
multiply_color
multiply_speed
painting
resize
rotate
scroll
speedx
supersample
time_mirror
time_symmetrize
Expand Down
6 changes: 6 additions & 0 deletions docs/ref/videofx/moviepy.video.fx.all.multiply_speed.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
moviepy.video.fx.all.multiply_speed
===================================

.. currentmodule:: moviepy.video.fx.all

.. autofunction:: multiply_speed
6 changes: 0 additions & 6 deletions docs/ref/videofx/moviepy.video.fx.all.speedx.rst

This file was deleted.

4 changes: 2 additions & 2 deletions moviepy/Clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ def with_fps(self, fps, change_duration=False):
halved in this mode, the duration will be doubled."""

if change_duration:
from moviepy.video.fx.speedx import speedx
from moviepy.video.fx.multiply_speed import multiply_speed

newclip = speedx(self, fps / self.fps)
newclip = multiply_speed(self, fps / self.fps)
else:
newclip = self.copy()

Expand Down
4 changes: 2 additions & 2 deletions moviepy/video/VideoClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def write_gif(
slower than the clip you will use ::
>>> # slow down clip 50% and make it a gif
>>> myClip.speedx(0.5).to_gif('myClip.gif')
>>> myClip.multiply_speed(0.5).to_gif('myClip.gif')
"""
# A little sketchy at the moment, maybe move all that in write_gif,
Expand Down Expand Up @@ -589,7 +589,7 @@ def subfx(self, fx, start_time=0, end_time=None, **kwargs):
>>> # The scene between times t=3s and t=6s in ``clip`` will be
>>> # be played twice slower in ``new_clip``
>>> new_clip = clip.subapply(lambda c:c.speedx(0.5) , 3,6)
>>> new_clip = clip.subapply(lambda c:c.multiply_speed(0.5) , 3,6)
"""
left = None if (start_time == 0) else self.subclip(0, start_time)
Expand Down
4 changes: 2 additions & 2 deletions moviepy/video/fx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
from moviepy.video.fx.mirror_x import mirror_x
from moviepy.video.fx.mirror_y import mirror_y
from moviepy.video.fx.multiply_color import multiply_color
from moviepy.video.fx.multiply_speed import multiply_speed
from moviepy.video.fx.painting import painting
from moviepy.video.fx.resize import resize
from moviepy.video.fx.rotate import rotate
from moviepy.video.fx.scroll import scroll
from moviepy.video.fx.speedx import speedx
from moviepy.video.fx.supersample import supersample
from moviepy.video.fx.time_mirror import time_mirror
from moviepy.video.fx.time_symmetrize import time_symmetrize
Expand Down Expand Up @@ -55,11 +55,11 @@
"mirror_x",
"mirror_y",
"multiply_color",
"multiply_speed",
"painting",
"resize",
"rotate",
"scroll",
"speedx",
"supersample",
"time_mirror",
"time_symmetrize",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def speedx(clip, factor=None, final_duration=None):
def multiply_speed(clip, factor=None, final_duration=None):
"""
Returns a clip playing the current clip but at a speed multiplied
by ``factor``. Instead of factor one can indicate the desired
Expand Down
2 changes: 1 addition & 1 deletion moviepy/video/io/gif_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def write_gif(
slower than the clip you will use ::
>>> # slow down clip 50% and make it a gif
>>> myClip.speedx(0.5).write_gif('myClip.gif')
>>> myClip.multiply_speed(0.5).write_gif('myClip.gif')
"""

Expand Down
4 changes: 2 additions & 2 deletions tests/test_VideoClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from moviepy.audio.io.AudioFileClip import AudioFileClip
from moviepy.utils import close_all_clips
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
from moviepy.video.fx.speedx import speedx
from moviepy.video.fx.multiply_speed import multiply_speed
from moviepy.video.io.VideoFileClip import VideoFileClip
from moviepy.video.VideoClip import BitmapClip, ColorClip, VideoClip

Expand Down Expand Up @@ -166,7 +166,7 @@ def test_write_gif_ImageMagick_tmpfiles_pixel_format():

def test_subfx():
clip = VideoFileClip("media/big_buck_bunny_0_30.webm").subclip(0, 1)
transform = lambda c: speedx(c, 0.5)
transform = lambda c: multiply_speed(c, 0.5)
new_clip = clip.subfx(transform, 0.5, 0.8)
location = os.path.join(TMP_DIR, "subfx.mp4")
new_clip.write_videofile(location)
Expand Down
74 changes: 59 additions & 15 deletions tests/test_fx.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest

from moviepy import AudioClip, AudioFileClip, BitmapClip, ColorClip, VideoFileClip
from moviepy.audio.fx import audio_normalize, multiply_stereo_volume
from moviepy.audio.fx import audio_normalize, multiply_stereo_volume, multiply_volume
from moviepy.utils import close_all_clips
from moviepy.video.fx import (
blackwhite,
Expand All @@ -23,9 +23,9 @@
mirror_x,
mirror_y,
multiply_color,
multiply_speed,
resize,
rotate,
speedx,
time_mirror,
time_symmetrize,
)
Expand Down Expand Up @@ -532,22 +532,22 @@ def test_scroll():
pass


def test_speedx():
def test_multiply_speed():
clip = BitmapClip([["A"], ["B"], ["C"], ["D"]], fps=1)

clip1 = speedx(clip, 0.5) # 1/2x speed
clip1 = multiply_speed(clip, 0.5) # 1/2x speed
target1 = BitmapClip(
[["A"], ["A"], ["B"], ["B"], ["C"], ["C"], ["D"], ["D"]], fps=1
)
assert clip1 == target1

clip2 = speedx(clip, final_duration=8) # 1/2x speed
clip2 = multiply_speed(clip, final_duration=8) # 1/2x speed
target2 = BitmapClip(
[["A"], ["A"], ["B"], ["B"], ["C"], ["C"], ["D"], ["D"]], fps=1
)
assert clip2 == target2

clip3 = speedx(clip, final_duration=12) # 1/2x speed
clip3 = multiply_speed(clip, final_duration=12) # 1/2x speed
target3 = BitmapClip(
[
["A"],
Expand All @@ -567,15 +567,15 @@ def test_speedx():
)
assert clip3 == target3

clip4 = speedx(clip, 2) # 2x speed
clip4 = multiply_speed(clip, 2) # 2x speed
target4 = BitmapClip([["A"], ["C"]], fps=1)
assert clip4 == target4

clip5 = speedx(clip, final_duration=2) # 2x speed
clip5 = multiply_speed(clip, final_duration=2) # 2x speed
target5 = BitmapClip([["A"], ["C"]], fps=1)
assert clip5 == target5

clip6 = speedx(clip, 4) # 4x speed
clip6 = multiply_speed(clip, 4) # 4x speed
target6 = BitmapClip([["A"]], fps=1)
assert (
clip6 == target6
Expand Down Expand Up @@ -637,10 +637,54 @@ def test_audio_normalize_muted():
close_all_clips(locals())


def test_multiply_volume():
clip = AudioFileClip("media/crunching.mp3")
clip_array = clip.to_soundarray()

# stereo mute
clip_muted = multiply_volume(clip, 0)

left_channel_muted = clip_muted.to_soundarray()[:, 0]
right_channel_muted = clip_muted.to_soundarray()[:, 1]

z_channel = np.zeros(len(left_channel_muted))

assert np.array_equal(left_channel_muted, z_channel)
assert np.array_equal(right_channel_muted, z_channel)

# stereo level doubled
clip_doubled = multiply_volume(clip, 2)
clip_doubled_array = clip_doubled.to_soundarray()
left_channel_doubled = clip_doubled_array[:, 0]
right_channel_doubled = clip_doubled_array[:, 1]
expected_left_channel_doubled = clip_array[:, 0] * 2
expected_right_channel_doubled = clip_array[:, 1] * 2

assert np.array_equal(left_channel_doubled, expected_left_channel_doubled)
assert np.array_equal(right_channel_doubled, expected_right_channel_doubled)

# mono muted
sinus_wave = lambda t: [np.sin(440 * 2 * np.pi * t)]
mono_clip = AudioClip(sinus_wave, duration=1, fps=22050)
muted_mono_clip = multiply_volume(mono_clip, 0)
mono_channel_muted = muted_mono_clip.to_soundarray()

z_channel = np.zeros(len(mono_channel_muted))
assert np.array_equal(mono_channel_muted, z_channel)

mono_clip = AudioClip(sinus_wave, duration=1, fps=22050)
doubled_mono_clip = multiply_volume(mono_clip, 2)
mono_channel_doubled = doubled_mono_clip.to_soundarray()
d_channel = mono_clip.to_soundarray() * 2
assert np.array_equal(mono_channel_doubled, d_channel)

close_all_clips(locals())


def test_multiply_stereo_volume():
clip = AudioFileClip("media/crunching.mp3")

# mute
# stereo mute
clip_left_channel_muted = multiply_stereo_volume(clip, left=0)
clip_right_channel_muted = multiply_stereo_volume(clip, right=0, left=2)

Expand All @@ -652,22 +696,22 @@ def test_multiply_stereo_volume():
assert np.array_equal(left_channel_muted, z_channel)
assert np.array_equal(right_channel_muted, z_channel)

# double level
# stereo level doubled
left_channel_doubled = clip_right_channel_muted.to_soundarray()[:, 0]
d_channel = clip.to_soundarray()[:, 0] * 2
assert np.array_equal(left_channel_doubled, d_channel)
expected_left_channel_doubled = clip.to_soundarray()[:, 0] * 2
assert np.array_equal(left_channel_doubled, expected_left_channel_doubled)

# mono muted
sinus_wave = lambda t: [np.sin(440 * 2 * np.pi * t)]
mono_clip = AudioClip(sinus_wave, duration=2, fps=22050)
mono_clip = AudioClip(sinus_wave, duration=1, fps=22050)
muted_mono_clip = multiply_stereo_volume(mono_clip, left=0)
mono_channel_muted = muted_mono_clip.to_soundarray()

z_channel = np.zeros(len(mono_channel_muted))
assert np.array_equal(mono_channel_muted, z_channel)

# mono doubled
mono_clip = AudioClip(sinus_wave, duration=2, fps=22050)
mono_clip = AudioClip(sinus_wave, duration=1, fps=22050)
doubled_mono_clip = multiply_stereo_volume(
mono_clip, left=None, right=2
) # using right
Expand Down

0 comments on commit cc9e1e7

Please sign in to comment.