mirror of
https://github.com/Hommy-master/capcut-mate.git
synced 2026-09-03 06:25:40 +08:00
解决transform_y、transform_x值设置不正确的BUG。
This commit is contained in:
@@ -30,8 +30,8 @@ POST /openapi/capcut-mate/v1/add_captions
|
||||
"line_spacing": null,
|
||||
"scale_x": 1.0,
|
||||
"scale_y": 1.0,
|
||||
"transform_x": 0,
|
||||
"transform_y": 0,
|
||||
"transform_x": 0.0,
|
||||
"transform_y": 0.0,
|
||||
"style_text": false
|
||||
}
|
||||
```
|
||||
@@ -52,8 +52,8 @@ POST /openapi/capcut-mate/v1/add_captions
|
||||
| line_spacing | number | ❌ | null | 行间距 |
|
||||
| scale_x | number | ❌ | 1.0 | 水平缩放比例 |
|
||||
| scale_y | number | ❌ | 1.0 | 垂直缩放比例 |
|
||||
| transform_x | integer | ❌ | 0 | X轴位置偏移(像素) |
|
||||
| transform_y | integer | ❌ | 0 | Y轴位置偏移(像素) |
|
||||
| transform_x | number | ❌ | 0.0 | X轴位置偏移(像素) |
|
||||
| transform_y | number | ❌ | 0.0 | Y轴位置偏移(像素) |
|
||||
| style_text | boolean | ❌ | false | 是否使用样式文本 |
|
||||
|
||||
### captions字段详细说明
|
||||
@@ -212,8 +212,8 @@ curl -X POST https://capcut-mate.jcaigc.cn/openapi/capcut-mate/v1/add_captions \
|
||||
"font_size": 20,
|
||||
"scale_x": 1.2,
|
||||
"scale_y": 1.2,
|
||||
"transform_x": 100,
|
||||
"transform_y": -50
|
||||
"transform_x": 100.0,
|
||||
"transform_y": -50.0
|
||||
}'
|
||||
```
|
||||
|
||||
@@ -261,7 +261,6 @@ curl -X POST https://capcut-mate.jcaigc.cn/openapi/capcut-mate/v1/add_captions \
|
||||
- [生成视频](./gen_video.md)
|
||||
|
||||
---
|
||||
|
||||
<div align="right">
|
||||
|
||||
📚 **项目资源**
|
||||
|
||||
@@ -16,8 +16,8 @@ class AddCaptionsRequest(BaseModel):
|
||||
line_spacing: Optional[float] = Field(default=None, description="行间距")
|
||||
scale_x: float = Field(default=1.0, description="水平缩放")
|
||||
scale_y: float = Field(default=1.0, description="垂直缩放")
|
||||
transform_x: int = Field(default=0, description="水平位移")
|
||||
transform_y: int = Field(default=0, description="垂直位移")
|
||||
transform_x: float = Field(default=0.0, description="水平位移")
|
||||
transform_y: float = Field(default=0.0, description="垂直位移")
|
||||
style_text: bool = Field(default=False, description="是否使用样式文本")
|
||||
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ def add_captions(
|
||||
line_spacing: Optional[float] = None,
|
||||
scale_x: float = 1.0,
|
||||
scale_y: float = 1.0,
|
||||
transform_x: int = 0,
|
||||
transform_y: int = 0,
|
||||
transform_x: float = 0.0,
|
||||
transform_y: float = 0.0,
|
||||
style_text: bool = False
|
||||
) -> Tuple[str, str, List[str], List[str], List[dict]]:
|
||||
"""
|
||||
@@ -58,8 +58,8 @@ def add_captions(
|
||||
line_spacing: 行间距,默认None
|
||||
scale_x: 水平缩放,默认1.0
|
||||
scale_y: 垂直缩放,默认1.0
|
||||
transform_x: 水平位移,默认0
|
||||
transform_y: 垂直位移,默认0
|
||||
transform_x: 水平位移,默认0.0
|
||||
transform_y: 垂直位移,默认0.0
|
||||
style_text: 是否使用样式文本,默认False
|
||||
|
||||
Returns:
|
||||
@@ -160,8 +160,8 @@ def add_caption_to_draft(
|
||||
line_spacing: Optional[float] = None,
|
||||
scale_x: float = 1.0,
|
||||
scale_y: float = 1.0,
|
||||
transform_x: int = 0,
|
||||
transform_y: int = 0,
|
||||
transform_x: float = 0.0,
|
||||
transform_y: float = 0.0,
|
||||
style_text: bool = False
|
||||
) -> Tuple[str, str, dict]:
|
||||
"""
|
||||
@@ -223,8 +223,8 @@ def add_caption_to_draft(
|
||||
clip_settings = ClipSettings(
|
||||
scale_x=scale_x,
|
||||
scale_y=scale_y,
|
||||
transform_x=float(transform_x) / script.width * 2, # 转换为半画布宽度单位
|
||||
transform_y=float(transform_y) / script.height * 2 # 转换为半画布高度单位
|
||||
transform_x=transform_x / script.width, # 转换为画布宽度单位
|
||||
transform_y=transform_y / script.height # 转换为画布高度单位
|
||||
)
|
||||
|
||||
# 5. 创建文本片段
|
||||
|
||||
66
tests/test_caption_transform.py
Normal file
66
tests/test_caption_transform.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import requests
|
||||
import json
|
||||
import time
|
||||
|
||||
def test_caption_transform():
|
||||
"""测试字幕位置变换功能"""
|
||||
|
||||
# 1. 先创建一个草稿
|
||||
create_draft_url = "http://localhost:8000/v1/create_draft"
|
||||
create_draft_data = {
|
||||
"width": 1920,
|
||||
"height": 1080
|
||||
}
|
||||
|
||||
try:
|
||||
print("Creating draft...")
|
||||
create_response = requests.post(create_draft_url, json=create_draft_data)
|
||||
|
||||
if create_response.status_code != 200:
|
||||
print(f"Failed to create draft: {create_response.status_code}")
|
||||
print(create_response.text)
|
||||
return
|
||||
|
||||
draft_url = create_response.json()["draft_url"]
|
||||
print(f"Draft created successfully: {draft_url}")
|
||||
|
||||
# 2. 添加带位置变换的字幕
|
||||
add_captions_url = "http://localhost:8000/v1/add_captions"
|
||||
captions = [
|
||||
{
|
||||
"start": 0,
|
||||
"end": 5000000, # 5秒
|
||||
"text": "测试字幕位置变换"
|
||||
}
|
||||
]
|
||||
|
||||
add_captions_data = {
|
||||
"draft_url": draft_url,
|
||||
"captions": json.dumps(captions),
|
||||
"text_color": "#ffffff", # 默认白色文本
|
||||
"font_size": 16,
|
||||
"transform_x": 100, # X轴位置偏移100像素
|
||||
"transform_y": -50 # Y轴位置偏移-50像素
|
||||
}
|
||||
|
||||
print("Adding captions with position transformation...")
|
||||
add_response = requests.post(add_captions_url, json=add_captions_data)
|
||||
|
||||
if add_response.status_code == 200:
|
||||
result = add_response.json()
|
||||
print(f"Captions added successfully!")
|
||||
print(f"Track ID: {result['track_id']}")
|
||||
print(f"Text IDs: {result['text_ids']}")
|
||||
print(f"Segment IDs: {result['segment_ids']}")
|
||||
print(f"Draft URL: {result['draft_url']}")
|
||||
else:
|
||||
print(f"Failed to add captions: {add_response.status_code}")
|
||||
print(add_response.text)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error occurred: {e}")
|
||||
print("Make sure the server is running on http://localhost:8000")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_caption_transform()
|
||||
69
tests/test_caption_transform_fix.py
Normal file
69
tests/test_caption_transform_fix.py
Normal file
@@ -0,0 +1,69 @@
|
||||
import requests
|
||||
import json
|
||||
import time
|
||||
|
||||
def test_caption_transform_fix():
|
||||
"""测试修复后的字幕位置变换功能"""
|
||||
|
||||
# 1. 先创建一个草稿
|
||||
create_draft_url = "http://localhost:8000/v1/create_draft"
|
||||
create_draft_data = {
|
||||
"width": 1920,
|
||||
"height": 1080
|
||||
}
|
||||
|
||||
try:
|
||||
print("Creating draft...")
|
||||
create_response = requests.post(create_draft_url, json=create_draft_data)
|
||||
|
||||
if create_response.status_code != 200:
|
||||
print(f"Failed to create draft: {create_response.status_code}")
|
||||
print(create_response.text)
|
||||
return
|
||||
|
||||
draft_url = create_response.json()["draft_url"]
|
||||
print(f"Draft created successfully: {draft_url}")
|
||||
|
||||
# 2. 添加带位置变换的字幕(测试修复后的transform参数)
|
||||
add_captions_url = "http://localhost:8000/v1/add_captions"
|
||||
captions = [
|
||||
{
|
||||
"start": 0,
|
||||
"end": 5000000, # 5秒
|
||||
"text": "测试字幕位置变换修复"
|
||||
}
|
||||
]
|
||||
|
||||
add_captions_data = {
|
||||
"draft_url": draft_url,
|
||||
"captions": json.dumps(captions),
|
||||
"text_color": "#ffffff", # 默认白色文本
|
||||
"font_size": 16,
|
||||
"transform_x": 200, # X轴位置偏移200像素
|
||||
"transform_y": 100 # Y轴位置偏移100像素
|
||||
}
|
||||
|
||||
print("Adding captions with fixed position transformation...")
|
||||
print(f"Setting transform_x={add_captions_data['transform_x']}, transform_y={add_captions_data['transform_y']}")
|
||||
add_response = requests.post(add_captions_url, json=add_captions_data)
|
||||
|
||||
if add_response.status_code == 200:
|
||||
result = add_response.json()
|
||||
print(f"Captions added successfully!")
|
||||
print(f"Track ID: {result['track_id']}")
|
||||
print(f"Text IDs: {result['text_ids']}")
|
||||
print(f"Segment IDs: {result['segment_ids']}")
|
||||
print(f"Draft URL: {result['draft_url']}")
|
||||
print("\n注意:在剪映中验证时,transform_x=200应该精确移动200像素,而不是之前的400像素")
|
||||
print("修复说明:根据ClipSettings类定义,transform参数单位是'半个画布宽/高',已使用正确的转换公式")
|
||||
else:
|
||||
print(f"Failed to add captions: {add_response.status_code}")
|
||||
print(add_response.text)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error occurred: {e}")
|
||||
print("Make sure the server is running on http://localhost:8000")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_caption_transform_fix()
|
||||
68
tests/test_float_transform.py
Normal file
68
tests/test_float_transform.py
Normal file
@@ -0,0 +1,68 @@
|
||||
import requests
|
||||
import json
|
||||
import time
|
||||
|
||||
def test_float_transform():
|
||||
"""测试浮点数类型的transform参数"""
|
||||
|
||||
# 1. 先创建一个草稿
|
||||
create_draft_url = "http://localhost:8000/v1/create_draft"
|
||||
create_draft_data = {
|
||||
"width": 1920,
|
||||
"height": 1080
|
||||
}
|
||||
|
||||
try:
|
||||
print("Creating draft...")
|
||||
create_response = requests.post(create_draft_url, json=create_draft_data)
|
||||
|
||||
if create_response.status_code != 200:
|
||||
print(f"Failed to create draft: {create_response.status_code}")
|
||||
print(create_response.text)
|
||||
return
|
||||
|
||||
draft_url = create_response.json()["draft_url"]
|
||||
print(f"Draft created successfully: {draft_url}")
|
||||
|
||||
# 2. 添加带浮点数位置变换的字幕
|
||||
add_captions_url = "http://localhost:8000/v1/add_captions"
|
||||
captions = [
|
||||
{
|
||||
"start": 0,
|
||||
"end": 5000000, # 5秒
|
||||
"text": "测试浮点数字幕位置变换"
|
||||
}
|
||||
]
|
||||
|
||||
add_captions_data = {
|
||||
"draft_url": draft_url,
|
||||
"captions": json.dumps(captions),
|
||||
"text_color": "#ffffff", # 默认白色文本
|
||||
"font_size": 16,
|
||||
"transform_x": 150.5, # X轴位置偏移150.5像素
|
||||
"transform_y": -75.25 # Y轴位置偏移-75.25像素
|
||||
}
|
||||
|
||||
print("Adding captions with float position transformation...")
|
||||
print(f"Setting transform_x={add_captions_data['transform_x']}, transform_y={add_captions_data['transform_y']}")
|
||||
add_response = requests.post(add_captions_url, json=add_captions_data)
|
||||
|
||||
if add_response.status_code == 200:
|
||||
result = add_response.json()
|
||||
print(f"Captions added successfully!")
|
||||
print(f"Track ID: {result['track_id']}")
|
||||
print(f"Text IDs: {result['text_ids']}")
|
||||
print(f"Segment IDs: {result['segment_ids']}")
|
||||
print(f"Draft URL: {result['draft_url']}")
|
||||
print("\n注意:在剪映中验证时,transform_x=150.5应该精确移动150.5像素")
|
||||
else:
|
||||
print(f"Failed to add captions: {add_response.status_code}")
|
||||
print(add_response.text)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error occurred: {e}")
|
||||
print("Make sure the server is running on http://localhost:8000")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_float_transform()
|
||||
Reference in New Issue
Block a user