mirror of
https://github.com/sun-guannan/CapCutAPI.git
synced 2025-11-25 03:15:00 +08:00
add background blur
This commit is contained in:
@@ -43,7 +43,8 @@ def add_image_impl(
|
||||
mask_feather: float = 0.0, # Mask feather parameter (0-100)
|
||||
mask_invert: bool = False, # Whether to invert the mask
|
||||
mask_rect_width: Optional[float] = None, # Rectangle mask width (rectangle mask only)
|
||||
mask_round_corner: Optional[float] = None # Rectangle mask rounded corner (rectangle mask only, 0-100)
|
||||
mask_round_corner: Optional[float] = None, # Rectangle mask rounded corner (rectangle mask only, 0-100)
|
||||
background_blur: Optional[int] = None # Background blur level, 1-4, corresponding to four blur intensity levels
|
||||
) -> Dict[str, str]:
|
||||
"""
|
||||
Add an image track to the specified draft
|
||||
@@ -79,6 +80,7 @@ def add_image_impl(
|
||||
:param mask_invert: Whether to invert the mask, default not inverted
|
||||
:param mask_rect_width: Rectangle mask width, only allowed when mask type is rectangle, represented as a proportion of material width
|
||||
:param mask_round_corner: Rectangle mask rounded corner parameter, only allowed when mask type is rectangle, range 0~100
|
||||
:param background_blur: Background blur level, 1-4, corresponding to four blur intensity levels (0.0625, 0.375, 0.75, 1.0)
|
||||
:return: Updated draft information, including draft_id and draft_url
|
||||
"""
|
||||
# Get or create draft
|
||||
@@ -223,6 +225,23 @@ def add_image_impl(
|
||||
except:
|
||||
raise ValueError(f"Unsupported mask type {mask_type}, supported types include: Linear, Mirror, Circle, Rectangle, Heart, Star")
|
||||
|
||||
# Add background blur effect
|
||||
if background_blur is not None:
|
||||
# Background blur level mapping table
|
||||
blur_levels = {
|
||||
1: 0.0625, # Light blur
|
||||
2: 0.375, # Medium blur
|
||||
3: 0.75, # Heavy blur
|
||||
4: 1.0 # Maximum blur
|
||||
}
|
||||
|
||||
# Validate background blur level
|
||||
if background_blur not in blur_levels:
|
||||
raise ValueError(f"Invalid background blur level {background_blur}, valid values are 1-4")
|
||||
|
||||
# Add background blur effect
|
||||
image_segment.add_background_filling("blur", blur=blur_levels[background_blur])
|
||||
|
||||
# Add image segment to track
|
||||
script.add_segment(image_segment, track_name=track_name)
|
||||
|
||||
|
||||
@@ -38,7 +38,8 @@ def add_video_track(
|
||||
mask_invert: bool = False, # Whether to invert mask
|
||||
mask_rect_width: Optional[float] = None, # Rectangle mask width (only for rectangle mask)
|
||||
mask_round_corner: Optional[float] = None, # Rectangle mask rounded corner (only for rectangle mask, 0-100)
|
||||
volume: float = 1.0 # Volume level, default 1.0
|
||||
volume: float = 1.0, # Volume level, default 1.0
|
||||
background_blur: Optional[int] = None # Background blur level, optional values: 1 (light), 2 (medium), 3 (strong), 4 (maximum), default None (no background blur)
|
||||
) -> Dict[str, str]:
|
||||
"""
|
||||
Add video track to specified draft
|
||||
@@ -70,6 +71,7 @@ def add_video_track(
|
||||
:param mask_rect_width: Rectangle mask width, only allowed when mask type is rectangle, represented as a proportion of material width
|
||||
:param mask_round_corner: Rectangle mask rounded corner parameter, only allowed when mask type is rectangle, range 0~100
|
||||
:param volume: Volume level, default 1.0 (0.0 is mute, 1.0 is original volume)
|
||||
:param background_blur: Background blur level, optional values: 1 (light), 2 (medium), 3 (strong), 4 (maximum), default None (no background blur)
|
||||
:return: Updated draft information, including draft_id and draft_url
|
||||
"""
|
||||
# Get or create draft
|
||||
@@ -209,6 +211,23 @@ def add_video_track(
|
||||
except:
|
||||
raise ValueError(f"Unsupported mask type {mask_type}, supported types include: linear, mirror, circle, rectangle, heart, star")
|
||||
|
||||
# Add background blur effect
|
||||
if background_blur is not None:
|
||||
# Validate if background blur level is valid
|
||||
if background_blur not in [1, 2, 3, 4]:
|
||||
raise ValueError(f"Invalid background blur level: {background_blur}, valid values are: 1, 2, 3, 4")
|
||||
|
||||
# Map blur level to specific blur values
|
||||
blur_values = {
|
||||
1: 0.0625, # Light blur
|
||||
2: 0.375, # Medium blur
|
||||
3: 0.75, # Strong blur
|
||||
4: 1.0 # Maximum blur
|
||||
}
|
||||
|
||||
# Add background blur
|
||||
video_segment.add_background_filling("blur", blur=blur_values[background_blur])
|
||||
|
||||
# Add video segment to track
|
||||
# if imported_track is not None:
|
||||
# imported_track.add_segment(video_segment)
|
||||
|
||||
@@ -70,6 +70,8 @@ def add_video():
|
||||
mask_rect_width = data.get('mask_rect_width') # Rectangle mask width
|
||||
mask_round_corner = data.get('mask_round_corner') # Rectangle mask rounded corner
|
||||
|
||||
background_blur = data.get('background_blur') # Background blur level, optional values: 1 (light), 2 (medium), 3 (strong), 4 (maximum), default None (no background blur)
|
||||
|
||||
result = {
|
||||
"success": False,
|
||||
"output": "",
|
||||
@@ -112,7 +114,8 @@ def add_video():
|
||||
mask_feather=mask_feather,
|
||||
mask_invert=mask_invert,
|
||||
mask_rect_width=mask_rect_width,
|
||||
mask_round_corner=mask_round_corner
|
||||
mask_round_corner=mask_round_corner,
|
||||
background_blur=background_blur
|
||||
)
|
||||
|
||||
result["success"] = True
|
||||
@@ -456,6 +459,8 @@ def add_image():
|
||||
mask_rect_width = data.get('mask_rect_width') # Rectangle mask width
|
||||
mask_round_corner = data.get('mask_round_corner') # Rectangle mask rounded corner
|
||||
|
||||
background_blur = data.get('background_blur') # Background blur level, optional values: 1 (light), 2 (medium), 3 (strong), 4 (maximum), default None (no background blur)
|
||||
|
||||
result = {
|
||||
"success": False,
|
||||
"output": "",
|
||||
@@ -502,7 +507,8 @@ def add_image():
|
||||
mask_feather=mask_feather,
|
||||
mask_invert=mask_invert,
|
||||
mask_rect_width=mask_rect_width,
|
||||
mask_round_corner=mask_round_corner
|
||||
mask_round_corner=mask_round_corner,
|
||||
background_blur=background_blur
|
||||
)
|
||||
|
||||
result["success"] = True
|
||||
|
||||
Reference in New Issue
Block a user