Change a video’s background
Describe a new setting for your footage while keeping its subject and movement.
下载工作流在 Cloud 中试用 API 文档
00:00
查看工作流内部
源模板的只读预览。在 Cloud 中打开,即可查看节点并进行修改。
Loading the graph
Open full-size workflow preview- 作者
- ComfyUI
从代码中调用该模型
以下请求使用与体验区相同的预设图和设置。每次提交都可能开始一次付费运行;如果提交结果未知,请勿自动重试。
1 获取 API 密钥 ↗
What you need
- Runs on
- Comfy Cloud
- 密钥
- COMFY_API_KEY
- 你的文件
- 由代码根据链接上传
需要付费的 Cloud 方案和额度。
# Python 3.10+: pip install comfy-sdk==0.4.0
import os
from comfy_sdk import Comfy
api_key = os.environ.get("COMFY_API_KEY", "").strip()
if not api_key: raise RuntimeError("Set COMFY_API_KEY")
os.environ.setdefault("COMFY_BASE_URL", "https://cloud.comfy.org")
client = Comfy(api_key=api_key)
workflow = client.workflows.from_json({
"16": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/Seedance2.5_video_edit",
"format": "auto",
"format.codec": "auto",
"video": [
"39",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"35": {
"class_type": "LoadVideo",
"inputs": {
"file": "UPLOADED_video_FILENAME"
},
"_meta": {
"title": "Load Video"
}
},
"36": {
"class_type": "Video Slice",
"inputs": {
"duration": 5,
"start_time": 0,
"strict_duration": False,
"video": [
"35",
0
]
},
"_meta": {
"title": "Trim Video"
}
},
"39": {
"class_type": "ByteDance2ReferenceNodeV2",
"inputs": {
"model": "Seedance 2.5",
"model.auto_downscale": True,
"model.auto_upscale": False,
"model.duration": 5,
"model.generate_audio": True,
"model.output_format": "mp4",
"model.prompt": [
"workshop-prompt",
0
],
"model.ratio": "16:9",
"model.reference_videos.video_1": [
"36",
0
],
"model.resolution": "720p",
"model.task_type": "edit",
"seed": 0,
"watermark": False
},
"_meta": {
"title": "ByteDance Seedance 2.5 Reference to Video"
}
},
"workshop-prompt": {
"class_type": "StringConcatenate",
"inputs": {
"delimiter": " ",
"string_a": "Replace the background with a sunlit city park, leafy trees, and a soft blue sky. Preserve the subject, its clothing, movement, camera framing, and timing. Change only the background and match its lighting to the subject.",
"string_b": "Use this as the new background of the video. Keep the subject, its clothing, pose, movement, camera framing and timing exactly as in the source video. Change only the background, and match the new background's lighting to the subject."
},
"_meta": {
"title": "Workshop prompt + fixed instructions"
}
}
})
workflow.set_input("35", "file", client.assets.from_url("https://cdn.jsdelivr.net/gh/Comfy-Org/workflow_templates@90c71fb78b3726392d010ff62a8e79e92d7296ad/input/kitten_cop.mp4"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)
for output in job.get_outputs("16"):
output.to_file(output.name)