跳到主要内容
CapCutAPI:开源剪映编程控制与视频编辑方案 | 极客日志
Python AI
CapCutAPI:开源剪映编程控制与视频编辑方案 CapCutAPI 是一个开源的剪映/Jianying API 解决方案,允许开发者通过编程方式控制 AI 生成的媒体资产。支持图像、音频、视频和文本的编辑。提供 HTTP API 和 MCP 协议,兼容多种媒体格式。安装需配置 Python 环境和 FFmpeg。适用于社交媒体内容批量生产、教育课程制作、电商推广及新闻自动化等场景,旨在解决 AI 视频生成中的控制不足问题,实现程序化视频编辑。
观心 发布于 2026/3/30 更新于 2026/5/22 26 浏览简介
CapCutAPI 是一个强大的开源编辑 API,让开发者能够通过编程方式完全控制 AI 生成的媒体资产,包括图像、音频、视频和文本。该项目旨在解决 AI 视频生成中常见的控制不足问题,提供精确的后期编辑和定制能力。无论是调整视频速度、镜像图像,还是添加复杂的特效和动画,CapCutAPI 都能帮助您轻松将创意想法转化为精美的视频内容。
核心价值:程序化视频编辑 · 云端预览 · 多格式支持 · 开源免费
主要功能特性
1. 核心架构概览
项目采用模块化设计,支持多种协议接入。
2. 核心功能矩阵
功能模块 支持程度 详细功能 草稿管理 ✅ 完全支持 创建、保存、导入、导出剪映草稿文件 视频处理 ✅ 完全支持 多格式导入、剪辑、转场、特效应用 音频编辑 ✅ 完全支持 音轨管理、音量控制、音效处理 图像处理 ✅ 完全支持 图像导入、动画、蒙版、滤镜 文本编辑 ✅ 完全支持 多样式文本、阴影、背景、动画 字幕系统 ✅ 完全支持 SRT 字幕导入、样式设置、时间同步 特效引擎 ✅ 完全支持 视觉效果、滤镜、转场动画 贴纸系统 ✅ 完全支持 贴纸资源、位置控制、动画效果 关键帧动画 ✅ 完全支持 属性动画、时间线控制、缓动函数 媒体分析 ✅ 完全支持 视频时长获取、格式检测
3. 协议支持对比
协议类型 支持特性 适用场景 HTTP API RESTful 接口,JSON 数据交换 Web 应用、自动化脚本、云服务集成 MCP 协议 标准通信协议,工具发现,流式处理 开发工具、IDE 插件、CLI 应用
4. 媒体格式支持
媒体类型 支持格式 特殊功能 视频格式 MP4, MOV, AVI, MKV, WebM 多轨道同时处理,Alpha 通道支持 音频格式 MP3, WAV, FLAC, AAC, OGG 多声道支持,实时混音 图像格式 JPEG, PNG, GIF, WEBP, BMP 动态图像支持,透明通道 文本格式 SRT, ASS, TXT, JSON 样式化文本,动画效果
安装与配置
1. 系统要求
操作系统:Windows 10+, macOS 11+, Ubuntu 18.04+
Python 版本:3.10+
内存:8GB RAM
存储:2GB 可用空间
FFmpeg: 最新稳定版
操作系统:Windows 11, macOS 13+, Ubuntu 22.04+
Python 版本:3.11+
内存:16GB+ RAM
存储:SSD, 10GB+ 可用空间
FFmpeg: 带硬件加速版本
GPU: 支持 CUDA 或 Metal 的显卡(可选)
2. 安装步骤
git clone https://github.com/sun-guannan/CapCutAPI.git
cd CapCutAPI
python -m venv venv-capcut
source venv-capcut/bin/activate
venv-capcut\Scripts\activate
pip install -r requirements.txt
pip install -r requirements-mcp.txt
cp config.json.example config.json
# Dockerfile 示例
FROM python:3.11-slim
WORKDIR /app
# 安装系统依赖
RUN apt-get update && apt-get install -y \
ffmpeg \
libsm6 \
libxext6 \
&& rm -rf /var/lib/apt/lists/*
# 复制项目文件
COPY . .
# 安装 Python 依赖
RUN pip install -r requirements.txt
# 暴露端口
EXPOSE 9001
# 启动服务
CMD ["python", "capcut_server.py"]
docker-compose up -d
docker build -t capcut-api .
docker run -p 9001:9001 -v $(pwd )/data:/app/data capcut-api
3. 配置详解 {
"server" : {
"host" : "0.0.0.0" ,
"port" : 9001 ,
"debug" : false ,
"workers" : 4
} ,
"storage" : {
"draft_dir" : "./drafts" ,
"temp_dir" : "./temp" ,
"max_file_size" : "2GB"
} ,
"media" : {
"ffmpeg_path" : "/usr/bin/ffmpeg" ,
"supported_formats" : [
"mp4" , "mov" , "avi" , "mkv" , "mp3" , "wav" , "flac" , "jpg" , "png" , "gif"
] ,
"max_resolution" : "4096x2160"
} ,
"security" : {
"api_key" : "your-secret-key-here" ,
"cors_origins" : [ "*" ] ,
"rate_limit" : "100/minute"
} ,
"logging" : {
"level" : "INFO" ,
"file" : "./logs/capcutapi.log" ,
"max_size" : "100MB" ,
"backup_count" : 5
}
}
export CUTAPI_HOST="0.0.0.0"
export CUTAPI_PORT="9001"
export CUTAPI_DEBUG="false"
export FFMPEG_PATH="/usr/bin/ffmpeg"
export DRAFT_DIR="./drafts"
export API_KEY="your-secret-key"
echo 'CUTAPI_HOST=0.0.0.0 CUTAPI_PORT=9001 FFMPEG_PATH=/usr/bin/ffmpeg DRAFT_DIR=./drafts' > .env
4. MCP 协议配置 {
"mcpServers" : {
"capcut-api" : {
"command" : "python3" ,
"args" : [ "mcp_server.py" ] ,
"cwd" : "/path/to/CapCutAPI" ,
"env" : {
"PYTHONPATH" : "/path/to/CapCutAPI" ,
"DEBUG" : "0"
} ,
"timeout" : 30
}
}
}
python test_mcp_client.py
使用指南
1. 基本使用流程
初始化 API 客户端
创建草稿项目
添加媒体素材
应用编辑效果
导出最终视频
2. API 使用示例 import requests
import json
def create_draft (width=1080 , height=1920 ):
url = "http://localhost:9001/create_draft"
payload = {
"width" : width,
"height" : height,
"fps" : 30 ,
"background_color" : "#000000" ,
"metadata" : {
"title" : "我的第一个 API 项目" ,
"author" : "开发者" ,
"description" : "使用 CapCutAPI 创建的项目"
}
}
response = requests.post(url, json=payload)
return response.json()
def add_video (draft_id, video_url, start_time=0 , duration=10 ):
url = "http://localhost:9001/add_video"
payload = {
"draft_id" : draft_id,
"video_url" : video_url,
"start" : start_time,
"end" : start_time + duration,
"volume" : 0.8 ,
"transition" : "fade_in" ,
"effects" : ["color_correction" , "stabilization" ]
}
response = requests.post(url, json=payload)
return response.json()
def add_text (draft_id, text, start_time, duration ):
url = "http://localhost:9001/add_text"
payload = {
"draft_id" : draft_id,
"text" : text,
"start" : start_time,
"end" : start_time + duration,
"font" : "Source Han Sans" ,
"font_size" : 48 ,
"font_color" : "#FFD700" ,
"background_color" : "#00000080" ,
"animation" : "fade_slide_in"
}
response = requests.post(url, json=payload)
return response.json()
draft = create_draft(1080 , 1920 )
draft_id = draft["result" ]["draft_id" ]
add_video(draft_id, "https://example.com/background.mp4" , 0 , 10 )
add_text(draft_id, "欢迎使用 CapCutAPI" , 2 , 5 )
print (f"项目创建成功!草稿 ID: {draft_id} " )
def add_keyframe_animation (draft_id, track_name, property_type, times, values ):
url = "http://localhost:9001/add_keyframe"
payload = {
"draft_id" : draft_id,
"track_name" : track_name,
"property_type" : property_type,
"times" : times,
"values" : values,
"easing" : "ease_in_out"
}
response = requests.post(url, json=payload)
return response.json()
def add_audio_effect (draft_id, audio_url, effects ):
url = "http://localhost:9001/add_audio_effect"
payload = {
"draft_id" : draft_id,
"audio_url" : audio_url,
"effects" : effects,
"volume" : 0.7 ,
"fade_in" : 2.0 ,
"fade_out" : 2.0
}
response = requests.post(url, json=payload)
return response.json()
def add_visual_effect (draft_id, effect_type, parameters ):
url = "http://localhost:9001/add_effect"
payload = {
"draft_id" : draft_id,
"effect_type" : effect_type,
"parameters" : parameters,
"duration" : 5.0 ,
"intensity" : 0.8
}
response = requests.post(url, json=payload)
return response.json()
3. MCP 协议使用 from mcp_client import McpClient
client = McpClient("capcut-api" )
draft = client.call_tool("create_draft" , {
"width" : 1080 ,
"height" : 1920 ,
"fps" : 30 ,
"metadata" : {
"title" : "MCP 示例项目" ,
"tags" : ["demo" , "test" ]
}
})
draft_id = draft["result" ]["draft_id" ]
client.call_tool("add_video" , {
"draft_id" : draft_id,
"video_url" : "https://example.com/main.mp4" ,
"start" : 0 ,
"end" : 15 ,
"track" : "main_video"
})
client.call_tool("add_audio" , {
"draft_id" : draft_id,
"audio_url" : "https://example.com/bgm.mp3" ,
"start" : 0 ,
"end" : 30 ,
"volume" : 0.6
})
client.call_tool("add_text" , {
"draft_id" : draft_id,
"text" : "AI 视频生成演示" ,
"start" : 2 ,
"end" : 10 ,
"style" : {
"font_size" : 56 ,
"font_color" : "#FFFFFF" ,
"background" : "#00000080"
}
})
client.call_tool("add_transition" , {
"draft_id" : draft_id,
"type" : "crossfade" ,
"duration" : 1.5 ,
"position" : 5.0
})
client.call_tool("add_filter" , {
"draft_id" : draft_id,
"filter_type" : "cinematic" ,
"intensity" : 0.7 ,
"duration" : 15.0
})
result = client.call_tool("export_draft" , {
"draft_id" : draft_id,
"format" : "mp4" ,
"resolution" : "1080p" ,
"quality" : "high"
})
print (f"项目导出完成:{result['result' ]['output_url' ]} " )
4. 高级功能使用 import concurrent.futures
def batch_process_videos (video_list, template_id ):
"""批量处理视频项目"""
results = []
with concurrent.futures.ThreadPoolExecutor(max_workers=4 ) as executor:
futures = []
for video_data in video_list:
future = executor.submit(process_single_video, video_data, template_id)
futures.append(future)
for future in concurrent.futures.as_completed(futures):
try :
result = future.result()
results.append(result)
except Exception as e:
print (f"处理失败:{e} " )
return results
def process_single_video (video_data, template_id ):
"""处理单个视频"""
draft = create_draft_from_template(template_id)
draft_id = draft["draft_id" ]
add_video(draft_id, video_data["video_url" ], 0 , video_data["duration" ])
add_audio(draft_id, video_data["audio_url" ], 0 , video_data["duration" ])
for text_item in video_data["text_elements" ]:
add_text(draft_id, text_item["text" ], text_item["start_time" ], text_item["duration" ])
for effect in video_data["effects" ]:
add_effect(draft_id, effect["type" ], effect["parameters" ])
result = export_draft(draft_id, video_data["output_format" ])
return result
def automated_video_workflow (config ):
"""全自动视频生成工作流"""
media_assets = prepare_media_assets(config)
draft = create_draft(config["project_settings" ])
draft_id = draft["draft_id" ]
for asset in media_assets["videos" ]:
add_video(draft_id, asset["url" ], asset["start" ], asset["duration" ])
for asset in media_assets["audios" ]:
add_audio(draft_id, asset["url" ], asset["start" ], asset["duration" ])
for text in config["text_elements" ]:
add_text(draft_id, text["content" ], text["start" ], text["duration" ])
for graphic in config["graphics" ]:
add_image(draft_id, graphic["url" ], graphic["start" ], graphic["duration" ])
for effect in config["effects" ]:
add_effect(draft_id, effect["type" ], effect["params" ])
for transition in config["transitions" ]:
add_transition(draft_id, transition["type" ], transition["position" ])
output = export_project(draft_id, config["output_settings" ])
cleanup_temp_files(draft_id)
return output
应用场景实例
案例 1:社交媒体内容批量生产 场景 :营销机构需要为多个客户批量生产社交媒体视频内容
利用模板机制快速填充不同客户的素材和文案,实现规模化生产。
class SocialMediaProducer :
def __init__ (self, api_client ):
self .client = api_client
self .templates = {}
def load_template (self, template_name, config ):
"""加载生产模板"""
template = {
'base_draft' : self .create_base_draft(config),
'media_slots' : config.get('media_slots' , []),
'text_slots' : config.get('text_slots' , []),
'effects' : config.get('effects' , []),
'output_settings' : config.get('output' , {})
}
self .templates[template_name] = template
def batch_produce (self, template_name, data_list ):
"""批量生产视频"""
results = []
for data in data_list:
try :
draft_id = self .duplicate_draft(
self .templates[template_name]['base_draft' ]
)
for slot in self .templates[template_name]['media_slots' ]:
media_data = data['media' ].get(slot['name' ])
if media_data:
self .fill_media_slot(draft_id, slot, media_data)
for slot in self .templates[template_name]['text_slots' ]:
text_data = data['text' ].get(slot['name' ])
if text_data:
self .fill_text_slot(draft_id, slot, text_data)
for effect in self .templates[template_name]['effects' ]:
self .apply_effect(draft_id, effect)
output = self .export_video(
draft_id, self .templates[template_name]['output_settings' ]
)
results.append({
'success' : True ,
'output' : output,
'data' : data
})
except Exception as e:
results.append({
'success' : False ,
'error' : str (e),
'data' : data
})
return results
def fill_media_slot (self, draft_id, slot, media_data ):
"""填充媒体槽位"""
if slot['type' ] == 'video' :
self .client.add_video(
draft_id, media_data['url' ], slot['start_time' ], slot['duration' ],
track=slot.get('track' , 'main' )
)
elif slot['type' ] == 'audio' :
self .client.add_audio(
draft_id, media_data['url' ], slot['start_time' ], slot['duration' ],
volume=slot.get('volume' , 1.0 )
)
def fill_text_slot (self, draft_id, slot, text_data ):
"""填充文本槽位"""
self .client.add_text(
draft_id, text_data['content' ], slot['start_time' ], slot['duration' ],
style={
'font_size' : slot.get('font_size' , 48 ),
'font_color' : text_data.get('color' , '#FFFFFF' ),
'animation' : slot.get('animation' , 'fade_in' )
}
)
生产效益 :显著提升生产效率,有效降低制作成本,保持内容一致性,缩短发布时间,实现效果追踪自动化。
案例 2:教育机构课程视频制作 场景 :在线教育平台需要为大量课程制作统一风格的视频内容
template:
name: "education_lecture"
duration: 1800
dimensions: [1920 , 1080 ]
fps: 30
tracks:
main_video:
type: "video"
position: "primary"
default_content: "lecturer_video.mp4"
presentation:
type: "video"
position: "picture_in_picture"
default_content: "slides.mp4"
size: [800 , 600 ]
position: [100 , 100 ]
background_music:
type: "audio"
volume: 0.3
loop: true
default_content: "background_music.mp3"
intro_outro:
type: "composite"
elements:
- type: "video"
file: "intro.mp4"
start: 0
end: 10
- type: "video"
file: "outro.mp4"
start: 1790
end: 1800
text_elements:
title:
type: "text"
start: 10
end: 20
content: "课程标题"
style:
font_size: 72
font_color: "#FFFFFF"
background: "#00000080"
animation: "zoom_in"
chapter_title:
type: "text"
position: "top_center"
duration: 5
style:
font_size: 48
font_color: "#4A90E2"
shadow: true
watermark:
type: "text"
start: 0
end: 1800
content: "© 教育机构名称"
position: [50 , 50 ]
style:
font_size: 24
font_color: "#FFFFFF80"
effects:
transition_between_slides:
type: "transition"
trigger: "slide_change"
effect: "crossfade"
duration: 1.5
highlight_key_points:
type: "effect"
effect: "highlight"
parameters:
color: "#FFFF00"
size: 1.2
duration: 3
automation:
auto_subtitles:
enabled: true
source: "audio_track"
language: "zh-CN"
style: "education"
slide_sync:
enabled: true
source: "presentation_track"
detect_slide_changes: true
from capcutapi import EducationVideoProducer
producer = EducationVideoProducer(template="education_template.yaml" )
course_data = {
"title" : "人工智能基础与应用" ,
"lecturer_video" : "ai_lecture.mp4" ,
"slides" : "ai_slides.pptx" ,
"background_music" : "classical_bgm.mp3" ,
"chapters" : [
{
"title" : "第一章:机器学习基础" ,
"start" : 0 ,
"duration" : 600 ,
"key_points" : [
{"text" : "监督学习" , "time" : 120 },
{"text" : "无监督学习" , "time" : 300 },
{"text" : "强化学习" , "time" : 450 }
]
},
{
"title" : "第二章:深度学习原理" ,
"start" : 600 ,
"duration" : 600 ,
"key_points" : [
{"text" : "神经网络结构" , "time" : 720 },
{"text" : "反向传播算法" , "time" : 900 },
{"text" : "卷积神经网络" , "time" : 1050 }
]
},
{
"title" : "第三章:AI 应用案例" ,
"start" : 1200 ,
"duration" : 600 ,
"key_points" : [
{"text" : "计算机视觉" , "time" : 1320 },
{"text" : "自然语言处理" , "time" : 1500 },
{"text" : "强化学习应用" , "time" : 1650 }
]
}
]
}
output_video = producer.generate_course(
course_data,
output_format="mp4" ,
quality="high" ,
output_path="courses/ai_foundations.mp4"
)
print (f"课程视频生成完成:{output_video} " )
教育价值 :提升课程制作效率,确保视频质量统一标准化,减少教师工作量,提高学生参与度,支持内容快速迭代。
案例 3:电商产品推广视频自动化 from capcutapi import EcommerceVideoGenerator
import pandas as pd
generator = EcommerceVideoGenerator(
template="ecommerce_template.yaml" ,
media_library="ecommerce_media/" ,
voice_library="voices/"
)
products = pd.read_csv("products.csv" )
for _, product in products.iterrows():
video_data = {
"product_id" : product["id" ],
"name" : product["name" ],
"category" : product["category" ],
"price" : product["price" ],
"discount" : product.get("discount" , 0 ),
"images" : [f"products/{product['id' ]} _{i} .jpg" for i in range (1 , 6 )],
"features" : product["features" ].split(";" ),
"reviews" : [
{"text" : "质量非常好,物超所值" , "rating" : 5 },
{"text" : "包装精美,送货快速" , "rating" : 4 }
],
"promotion" : {
"type" : "flash_sale" if product["discount" ] > 0 else "normal" ,
"end_time" : "2024-12-31 23:59:59"
}
}
output_file = f"videos/{product['id' ]} _{product['name' ]} .mp4"
generator.generate_video(
video_data, output_file, voice_over=True , subtitles=True
)
print (f"已生成:{product['name' ]} " )
print ("所有产品视频生成完成!" )
电商效益 :大幅降低视频制作成本,提高内容产出速度,提升转化率,实现个性化推荐精准匹配,支持促销活动即时响应。
案例 4:新闻媒体自动化报道 from capcutapi import NewsVideoProducer
from news_scraper import NewsAggregator
producer = NewsVideoProducer(
template="news_template.yaml" ,
voice="news_anchor_voice.mp3"
)
aggregator = NewsAggregator()
news_items = aggregator.get_top_news(limit=5 )
for news in news_items:
draft_id = producer.create_draft(
title=news["title" ],
category=news["category" ],
duration=news["duration" ]
)
producer.add_intro(news["headline" ])
producer.add_video_clip(news["video_url" ])
producer.add_text_overlay(news["summary" ])
if news["location" ]:
producer.add_location_marker(news["location" ])
if news["statistics" ]:
producer.add_infographic(news["statistics" ])
for related in news["related_stories" ]:
producer.add_related_story(related["title" ], related["url" ])
producer.add_reporter_info(
name=news["reporter" ], contact=news["contact" ]
)
producer.add_outro("感谢收看" )
output_file = f"news/{news['date' ]} _{news['id' ]} .mp4"
producer.export_draft(
draft_id, output_file, quality="medium" , subtitles=True
)
print (f"新闻报道生成:{news['title' ]} " )
producer.cleanup()
新闻价值 :大幅提高报道速度,减少人力成本,保持内容一致性统一标准,支持多平台适配一键生成,实现突发新闻即时响应。
案例 5:个人创作者内容生产 from capcutapi import CreatorStudio
from content_planner import ContentCalendar
studio = CreatorStudio(
user_profile="creator_profile.json" ,
template_library="templates/"
)
calendar = ContentCalendar()
content_plan = calendar.get_weekly_plan()
for day, content_items in content_plan.items():
print (f"处理 {day} 的内容:" )
for item in content_items:
template = studio.select_template(
content_type=item["type" ],
platform=item["platform" ],
style=item["style" ]
)
media = studio.prepare_media(
item["media_sources" ], duration=item["duration" ]
)
if item["script" ]:
subtitles = studio.generate_subtitles(
item["script" ], voice_over=item["voice_over" ]
)
draft_id = studio.create_draft(
template=template, duration=item["duration" ]
)
studio.add_media(draft_id, media)
if item["script" ]:
studio.add_subtitles(draft_id, subtitles)
studio.add_branding(
draft_id, logo=True , watermark=True , color_scheme=item["brand_colors" ]
)
if item["effects" ]:
for effect in item["effects" ]:
studio.add_effect(draft_id, effect)
output_file = f"output/{day} /{item['title' ]} .mp4"
studio.export_video(
draft_id, output_file, platform=item["platform" ], optimize=True
)
print (f" - 完成:{item['title' ]} " )
print (f"{day} 内容生成完成\n" )
print ("本周所有内容已生成!" )
创作者价值 :显著提高内容产出,使创意实现更加自由,支持平台适配一键优化,全面保持品牌一致性,提升粉丝互动效率。
社区与支持
1. 贡献指南
Fork 项目仓库
创建特性分支 (git checkout -b feature/amazing-feature)
提交代码变更 (git commit -m 'Add some amazing feature')
推送到分支 (git push origin feature/amazing-feature)
创建 Pull Request 到 dev 分支
2. 社区资源 资源类型 获取方式 内容描述 文档教程 GitHub Wiki 完整 API 参考和开发指南 示例模板 /templates目录各类视频模板示例 社区论坛 GitHub Issues Bug 报告和功能请求 路线图 GitHub Projects 项目发展规划和里程碑
3. 支持与联系
问题反馈 :GitHub Issues
功能建议 :GitHub Issues
总结 CapCutAPI 作为开源剪映/Jianying API 解决方案,通过其强大的功能和灵活的架构,改变了视频内容创作的方式。它让视频编辑变得可编程化,为 AI 生成内容提供精准控制,解决 AI 视频生成中常见的控制不足问题。该工具已在多个领域证明其价值,适用于内容创作者、教育机构、电商平台、新闻媒体及营销机构等场景,为用户提供强大的视频创作能力。
相关免费在线工具 RSA密钥对生成器 生成新的随机RSA私钥和公钥pem证书。 在线工具,RSA密钥对生成器在线工具,online
Mermaid 预览与可视化编辑 基于 Mermaid.js 实时预览流程图、时序图等图表,支持源码编辑与即时渲染。 在线工具,Mermaid 预览与可视化编辑在线工具,online
随机西班牙地址生成器 随机生成西班牙地址(支持马德里、加泰罗尼亚、安达卢西亚、瓦伦西亚筛选),支持数量快捷选择、显示全部与下载。 在线工具,随机西班牙地址生成器在线工具,online
curl 转代码 解析常见 curl 参数并生成 fetch、axios、PHP curl 或 Python requests 示例代码。 在线工具,curl 转代码在线工具,online
Base64 字符串编码/解码 将字符串编码和解码为其 Base64 格式表示形式即可。 在线工具,Base64 字符串编码/解码在线工具,online
Base64 文件转换器 将字符串、文件或图像转换为其 Base64 表示形式。 在线工具,Base64 文件转换器在线工具,online