Overview
MovieLite’s flexible API allows you to create custom effects beyond the built-invfx module. You can apply transformations at different levels: pixel-level, frame-level, or by creating reusable effect classes.
Frame Transformations
Using add_transform()
The simplest way to create custom effects is withadd_transform(), which applies a function to each frame:
The transform function receives:
frame: NumPy array in BGR format (uint8)t: Relative time within the clip (0 to duration)
Time-Based Effects
Use the time parameter for animated effects:Chaining Multiple Transforms
Transforms are applied in the order they’re added:Pixel-Level Transformations
Using add_pixel_transform()
For color adjustments, pixel-level transforms are more efficient than frame transforms. They use Numba JIT compilation for near-native performance:Pixel Transform Examples
Creating Reusable Effects
Custom Effect Classes
Create reusable effects by extending theGraphicEffect base class:
Parameterized Effects
Create effects with adjustable parameters:Advanced Effect Examples
Chromatic Aberration
Film Grain
Color Lookup Table (LUT)
Glitch Effect
Performance Optimization
Caching Expensive Computations
Cache results that don’t change per frame:Using Numba for Speed
Compile performance-critical code with Numba:Best Practices
Prefer Pixel Transforms
For color operations, use
add_pixel_transform() with Numba. It’s significantly faster than frame transforms for pixel-wise operations.Cache Expensive Calculations
If your effect has time-independent computations, calculate them once and cache the results.
Test on Short Clips
Develop and test effects on 2-3 second clips before processing full videos.
Use Built-in OpenCV Functions
OpenCV functions like
cv2.GaussianBlur(), cv2.filter2D(), etc. are highly optimized. Use them when possible.Common Patterns
Next Steps
- Optimize rendering with Performance Tips
- Combine custom effects with Transitions
- Use custom effects with Masking for advanced compositions