# 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({
"3": {
"class_type": "LoadVideo",
"inputs": {
"file": "UPLOADED_video_FILENAME"
},
"_meta": {
"title": "Load Video"
}
},
"4": {
"class_type": "SaveVideo",
"inputs": {
"codec": "auto",
"filename_prefix": "video/ComfyUI",
"format": "auto",
"format.codec": "auto",
"video": [
"101",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"100": {
"class_type": "SaveVideo",
"inputs": {
"codec": "auto",
"filename_prefix": "video/ComfyUI",
"format": "auto",
"format.codec": "auto",
"video": [
"98:80",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"101": {
"class_type": "ByteDanceVideoEnhanceNode",
"inputs": {
"bitrate_level": "medium",
"fps": "source",
"resolution": "1080p",
"tool_version": "standard",
"tool_version.enhance_style": "hd",
"tool_version.scene": "aigc",
"video": [
"3",
0
]
},
"_meta": {
"title": "ByteDance vCube Video Enhance"
}
},
"98:77": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"3",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"98:78": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"4",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"98:79": {
"class_type": "ImageStitch",
"inputs": {
"direction": "right",
"image1": [
"98:77",
0
],
"image2": [
"98:78",
0
],
"match_image_size": True,
"spacing_color": "white",
"spacing_width": 0
},
"_meta": {
"title": "Stitch Images"
}
},
"98:80": {
"class_type": "CreateVideo",
"inputs": {
"audio": [
"98:77",
1
],
"bit_depth": "auto",
"chroma_subsampling": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": [
"98:77",
2
],
"images": [
"98:97",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"98:90": {
"class_type": "GetImageSize",
"inputs": {
"image": [
"98:79",
0
]
},
"_meta": {
"title": "Get Image Size"
}
},
"98:95": {
"class_type": "ComfyMathExpression",
"inputs": {
"expression": "a & ~1",
"values.a": [
"98:90",
0
]
},
"_meta": {
"title": "Math Expression"
}
},
"98:96": {
"class_type": "ComfyMathExpression",
"inputs": {
"expression": "a & ~1",
"values.a": [
"98:90",
1
]
},
"_meta": {
"title": "Math Expression"
}
},
"98:97": {
"class_type": "ResizeImageMaskNode",
"inputs": {
"input": [
"98:79",
0
],
"resize_type": "scale dimensions",
"resize_type.crop": "center",
"resize_type.height": [
"98:96",
1
],
"resize_type.width": [
"98:95",
1
],
"scale_method": "area"
},
"_meta": {
"title": "Resize Image/Mask"
}
}
})
# Replace each example.com URL with a public URL of your file.
workflow.set_input("3", "file", client.assets.from_url("https://example.com/replace-with-a-url/video"))
# 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("4"):
output.to_file(output.name)