forked from Zulko/moviepy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from moviepy.decorators import apply_to_mask | ||
from .crop import crop | ||
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip | ||
|
||
|
||
#@apply_to_mask | ||
def freeze_region(clip, t=0, region=None, outside_region=None, mask=None): | ||
""" Freezes one region of the clip while the rest remains animated. | ||
You can choose one of three methods by providing either `region`, | ||
`outside_region`, or `mask`. | ||
Parameters | ||
----------- | ||
t | ||
Time at which to freeze the freezed region. | ||
region | ||
A tuple (x1, y1, x2, y2) defining the region of the screen (in pixels) | ||
which will be freezed. You can provide outside_region or mask instead. | ||
outside_region | ||
A tuple (x1, y1, x2, y2) defining the region of the screen (in pixels) | ||
which will be the only non-freezed region. | ||
mask | ||
If not None, will overlay a freezed version of the clip on the current clip, | ||
with the provided mask. In other words, the "visible" pixels in the mask | ||
indicate the freezed region in the final picture. | ||
""" | ||
|
||
if region is not None: | ||
|
||
x1, y1, x2, y2 = region | ||
freeze = (clip.fx(crop, *region) | ||
.set_position((x1,y1)) | ||
.to_ImageClip(t=t) | ||
.set_duration(clip.duration)) | ||
return CompositeVideoClip([clip, freeze]) | ||
|
||
elif outside_region is not None: | ||
|
||
x1, y1, x2, y2 = outside_region | ||
animated_region = (clip.fx(crop, *outside_region) | ||
.set_position((x1,y1))) | ||
freeze = (clip.to_ImageClip(t=t) | ||
.set_duration(clip.duration)) | ||
return CompositeVideoClip([freeze, animated_region]) | ||
|
||
elif mask is not None: | ||
freeze = (clip.to_ImageClip(t=t) | ||
.set_duration(clip.duration) | ||
.set_mask(mask)) | ||
return CompositeVideoClip([clip, freeze]) |