Rotation effect rotates clips by a specified angle. It supports both static (constant angle) and animated (time-based) rotation with extensive customization options.
Constructor
Rotation angle. Can be:
- A
floatfor static rotation (e.g.,45) - A function of time for animated rotation (e.g.,
lambda t: t * 360)
Unit of the angle. Options:
"deg": Degrees (default)"rad": Radians
Resampling filter for rotation. Options:
"nearest": Fastest, but can look blocky"bilinear": Good balance of speed and quality (default)"bicubic": Best quality, but slower
If
True (default), expands the canvas to fit the rotated content without clipping corners.
If False, keeps original size (may clip rotated corners).Center of rotation as
(x, y) in pixels, relative to top-left corner.
If None (default), uses the center of the frame.Optional post-rotation translation as
(dx, dy) in pixels.Background color for areas outside the rotated frame.
- For RGB:
(R, G, B) - For RGBA:
(R, G, B, A)
None (default), uses black for RGB or transparent for RGBA.Examples
Static Rotation
Animated Rotation
Advanced Options
Resampling Filters
Fastest but lowest quality. Suitable for:
- Pixel art or low-resolution content
- When performance is critical
- Preview/draft renders
Balanced speed and quality (default). Suitable for:
- Most general use cases
- Good quality without performance penalty
- Production renders
Highest quality but slower. Suitable for:
- High-resolution video
- Final/export quality renders
- When visual quality is paramount
Canvas Expansion
With Expansion (expand=True)
- Canvas size increases to fit entire rotated content
- No clipping of corners
- Output dimensions may be larger than input
- Best for: Preserving entire frame content
Without Expansion (expand=False)
- Canvas size remains unchanged
- Corners may be clipped
- Output dimensions = input dimensions
- Best for: Maintaining fixed dimensions, subtle rotations
Performance Optimizations
The
Rotation effect includes several optimizations for common cases:Fast paths for 90°, 180°, and 270° rotations:- Uses NumPy’s
rot90()instead of OpenCV transform - 10-50× faster than general rotation
- Only when
expand=Trueand no custom parameters
Common Angle Optimizations
| Angle | Optimization | Speed Gain |
|---|---|---|
| 0° | Returns original frame | Instant |
| 90° | np.rot90(k=1) | 50× faster |
| 180° | frame[::-1, ::-1] | 100× faster |
| 270° | np.rot90(k=3) | 50× faster |
| Other | OpenCV warpAffine | Standard |
Rotation Center Examples
Animated Rotation Patterns
Continuous Spin
Oscillation
Accelerating Rotation
Combining with Other Effects
Rotation + Zoom
Rotation + Color Effects
Rotation + Fade
Technical Details
Rotation Matrix
Uses OpenCV’sgetRotationMatrix2D to create a 2×3 affine transformation matrix:
θ= rotation angletx, ty= translation to center/expand canvas
Canvas Size Calculation
Whenexpand=True, new dimensions are calculated to fit rotated content:
Border Handling
Usescv2.BORDER_CONSTANT with configurable bg_color:
- RGB frames: defaults to black
(0, 0, 0) - RGBA frames: defaults to transparent
(0, 0, 0, 0)
src/movielite/vfx/rotation.py:8-194
Common Issues
See Also
- Zoom Effects - Combine rotation with zoom for dynamic motion
- Glitch Effects - Add distortion to rotated content
- OpenCV warpAffine Documentation