moviepy.video.fx.Rotate#
- class moviepy.video.fx.Rotate.Rotate(angle: float, unit: str = 'deg', resample: str = 'bicubic', expand: bool = True, center: tuple = None, translate: tuple = None, bg_color: tuple = None)[source]#
Rotates the specified clip by
angledegrees (or radians) anticlockwise If the angle is not a multiple of 90 (degrees) orcenter,translate, andbg_colorare notNone, there will be black borders. You can make them transparent with:>>> new_clip = clip.with_mask().rotate(72)
- Parameters:
clip (VideoClip)
clip. (A video)
angle (float)
rotation. (Either a value or a function angle(t) representing the angle of)
unit (str, optional)
radians). (Unit of parameter angle (either "deg" for degrees or "rad" for)
resample (str, optional)
"nearest" (An optional resampling filter. One of)
"bilinear"
"bicubic". (or)
expand (bool, optional)
true (If)
the (expands the output image to make it large enough to hold)
omitted (entire rotated image. If false or)
same (make the output image the)
image. (size as the input)
translate (tuple, optional)
2-tuple). (An optional post-rotate translation (a)
center (tuple, optional)
corner. (Optional center of rotation (a 2-tuple). Origin is the upper left)
bg_color (tuple, optional)
if (An optional color for area outside the rotated image. Only has effect)
true. (expand is)
- copy()#
Return a shallow copy of an Effect.
You must always copy an
Effectbefore applying, because some of them will modify their own attributes when applied. For example, setting a previously unset property by using target clip property.If we was to use the original effect, calling the same effect multiple times could lead to different properties, and different results for equivalent clips.
By using copy, we ensure we can use the same effect object multiple times while maintaining the same behavior/result.
In a way, copy makes the effect himself being kind of idempotent.
- rotate_frame(frame: ndarray, angle: float, resample: int, expand: bool, center: tuple | None, translate: tuple | None, bg_color: tuple | None) ndarray[source]#
Rotate a single image or mask using OpenCV.
- Parameters:
frame (np.ndarray) -- HxWxC RGB image (dtype uint8) or HxW mask (any dtype).
angle (float) -- Counter-clockwise rotation angle in degrees.
resample (int) -- One of cv2.INTER_NEAREST, cv2.INTER_LINEAR, or cv2.INTER_CUBIC. For masks, you’ll typically want cv2.INTER_NEAREST. Default is cv2.INTER_CUBIC.
expand (bool) -- If True, expand the output canvas so the full rotated frame fits. If False, output size == input size (cropping corners). Default False. Expansion does not account for translation.
center (tuple or None) -- (cx, cy) rotation center in pixel coords. Defaults to image center.
translate (tuple or None) -- (dx, dy) post-rotation translation in pixels. Default (0, 0).
bg_color (tuple, scalar, or None) -- Fill color for areas outside the frame. If frame is HxWx3 RGB, bg_color=(R,G,B). If HxW mask, bg_color is a scalar. Default black.
- Returns:
rotated -- The rotated (and possibly expanded) frame or mask.
- Return type:
np.ndarray