Skip to content

Video editing with Python

Document 'accel_decel' FX properly; raise ValueError for invalid 'sooness' value (#1546)

Álvaro Mondéjar3c1638111424
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e4a3c77b..4cf091f7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 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)
- `requests` package is no longer a dependency [\#1566](https://github.com/Zulko/moviepy/pull/1566)
+- `accel_decel` FX raises `ValueError` if `sooness` parameter value is lower than zero [\#1546](https://github.com/Zulko/moviepy/pull/1546)
### Deprecated <!-- for soon-to-be removed features -->
- `moviepy.video.fx.all` and `moviepy.audio.fx.all`. Use the fx method directly from the clip instance or import the fx function from `moviepy.video.fx` and `moviepy.audio.fx`. [\#1105](https://github.com/Zulko/moviepy/pull/1105)
diff --git a/docs/_static/accel_decel-fx-params.png b/docs/_static/accel_decel-fx-params.png
new file mode 100644
index 00000000..cf9dbf9e
Binary files /dev/null and b/docs/_static/accel_decel-fx-params.png differ
diff --git a/moviepy/video/fx/accel_decel.py b/moviepy/video/fx/accel_decel.py
index f667498a..d157675a 100644
--- a/moviepy/video/fx/accel_decel.py
+++ b/moviepy/video/fx/accel_decel.py
@@ -1,15 +1,4 @@
-def f_accel_decel(t, old_duration, new_duration, abruptness=1.0, soonness=1.0):
- """Acceleration and deceleration function.
-
- abruptness
- negative abruptness (>-1): speed up down up
- zero abruptness : no effect
- positive abruptness: speed down up down
-
- soonness
- for positive abruptness, determines how soon the
- speedup occurs (0<soonness < inf)
- """
+def _f_accel_decel(t, old_duration, new_duration, abruptness=1.0, soonness=1.0):
a = 1.0 + abruptness
def _f(t):
@@ -27,21 +16,47 @@ def f_accel_decel(t, old_duration, new_duration, abruptness=1.0, soonness=1.0):
def accel_decel(clip, new_duration=None, abruptness=1.0, soonness=1.0):
"""Accelerates and decelerates a clip, useful for GIF making.
- new_duration
- If None, will be that of the current clip.
+ Parameters
+ ----------
+
+ new_duration : float
+ Duration for the new transformed clip. If None, will be that of the
+ current clip.
+
+ abruptness : float
+ Slope shape in the acceleration-deceleration function. It will depend
+ on the value of the parameter:
+
+ * ``-1 < abruptness < 0``: speed up, down, up.
+ * ``abruptness == 0``: no effect.
+ * ``abruptness > 0``: speed down, up, down.
+
+ soonness : float
+ For positive abruptness, determines how soon the transformation occurs.
+ Should be a positive number.
+
+ Raises
+ ------
+
+ ValueError
+ When ``sooness`` argument is lower than 0.
+
+ Examples
+ --------
- abruptness
- negative abruptness (>-1): speed up down up
- zero abruptness : no effect
- positive abruptness: speed down up down
+ The following graphs show functions generated by different combinations
+ of arguments, where the value of the slopes represents the speed of the
+ videos generated, being the linear function (in red) a combination that
+ does not produce any transformation.
- soonness
- for positive abruptness, determines how soon the
- speedup occurs (0<soonness < inf)
+ .. image:: /_static/accel_decel-fx-params.png
+ :alt: acced_decel FX parameters combinations
"""
if new_duration is None:
new_duration = clip.duration
+ if soonness < 0:
+ raise ValueError("'sooness' should be a positive number")
return clip.time_transform(
- lambda t: f_accel_decel(t, clip.duration, new_duration, abruptness, soonness)
+ lambda t: _f_accel_decel(t, clip.duration, new_duration, abruptness, soonness)
).with_duration(new_duration)