### Install CapCutAPI with git clone and pip Source: https://github.com/ashreo/capcutapi/blob/main/README.md One-click installation steps: clone the repository, create a virtual environment, install dependencies (HTTP API and optional MCP support), and copy the example configuration file. ```bash git clone https://github.com/sun-guannan/CapCutAPI.git cd CapCutAPI # 2. Create virtual environment (recommended) python -m venv venv-capcut source venv-capcut/bin/activate # Linux/macOS # or venv-capcut\Scripts\activate # Windows # 3. Install dependencies pip install -r requirements.txt # HTTP API basic dependencies pip install -r requirements-mcp.txt # MCP protocol support (optional) # 4. Configuration cp config.json.example config.json # Edit config.json as needed ``` -------------------------------- ### Install dependencies with virtual environment Source: https://github.com/ashreo/capcutapi/blob/main/MCP_Documentation_English.md Creates a Python 3.10 virtual environment and installs dependencies from requirements-mcp.txt. Use the appropriate activation command for your OS. ```bash # Create virtual environment python3.10 -m venv venv-mcp source venv-mcp/bin/activate # macOS/Linux # or venv-mcp\Scripts\activate # Windows # Install dependencies pip install -r requirements-mcp.txt ``` -------------------------------- ### Start MCP server with python mcp_server.py Source: https://github.com/ashreo/capcutapi/blob/main/README.md Starts the MCP protocol server, which supports stdio communication. ```bash python mcp_server.py ``` -------------------------------- ### Start HTTP API server with python capcut_server.py Source: https://github.com/ashreo/capcutapi/blob/main/README.md Starts the HTTP API server. The default port is 9001. ```bash python capcut_server.py ``` -------------------------------- ### API response format example (JSON) Source: https://github.com/ashreo/capcutapi/blob/main/MCP_Documentation_English.md Example response format from the API, showing success status, draft identifier and URL, and the features used. Use this as a reference when handling API responses. ```json { "success": true, "result": { "draft_id": "dfd_cat_xxx", "draft_url": "https://..." }, "features_used": { "shadow": false, "background": false, "multi_style": false } } ``` -------------------------------- ### Usage example: add effect and fetch video duration Source: https://github.com/ashreo/capcutapi Demonstrates importing add_effect_impl and get_video_duration, fetching a video's duration, and adding a Glow effect with reversed params. ```python from add_effect_impl import add_effect_impl from get_duration_impl import get_video_duration d = get_video_duration("https://example.com/clip.mp4") if d["success"]: print(f"duration={d['output']:.2f}s") else: print("probe failed:", d["error"]) result = add_effect_impl( effect_type="Glow", start=0, end=3, params=[0.5, None, 0.8], # reversed internally by the implementation ) print(result) ``` -------------------------------- ### Test MCP connection with python test_mcp_client.py Source: https://github.com/ashreo/capcutapi/blob/main/README.md Tests the MCP connection and shows the expected output: server started, 11 tools retrieved, and draft creation test passed. ```bash python test_mcp_client.py # Expected output ✅ MCP server started successfully ✅ Retrieved 11 available tools ✅ Draft creation test passed ``` -------------------------------- ### Enable debug mode (mcp_server.py) Source: https://github.com/ashreo/capcutapi/blob/main/MCP_Documentation_English.md Enables verbose logging by setting DEBUG=1 and starting the MCP server. Use this to diagnose server startup failures or tool call errors. ```bash # Enable verbose logging export DEBUG=1 python mcp_server.py ``` -------------------------------- ### Configure MCP client in mcp_config.json Source: https://github.com/ashreo/capcutapi/blob/main/README.md Example mcp_config.json configuration for the capcut-api MCP server, specifying the command, arguments, working directory, and environment variables. ```json { "mcpServers": { "capcut-api": { "command": "python3", "args": ["mcp_server.py"], "cwd": "/path/to/CapCutAPI", "env": { "PYTHONPATH": "/path/to/CapCutAPI", "DEBUG": "0" } } } } ``` -------------------------------- ### config.json.example - CapCutAPI configuration file Source: https://github.com/ashreo/capcutapi Example configuration file for CapCutAPI. Loaded at import time; parse/IO errors are swallowed and defaults are used. Contains settings for CapCut environment, draft domain, port, preview router, upload behavior, and OSS credentials. ```json { "is_capcut_env": true, "draft_domain": "https://www.install-ai-guider.top", "port": 9001, "preview_router": "/draft/downloader", "is_upload_draft": false, "oss_config": { "bucket_name": "your-bucket-name", "access_key_id": "your-access-key-id", "access_key_secret": "your-access-key-secret", "endpoint": "https://your-endpoint.aliyuncs.com" }, "mp4_oss_config": { "bucket_name": "your-mp4-bucket-name", "access_key_id": "your-access-key-id", "access_key_secret": "your-access-key-secret", "region": "your-region", "endpoint": "http://your-custom-domain" } } ``` -------------------------------- ### Minimal MCP client interaction with mcp_server.py Source: https://github.com/ashreo/capcutapi Shows how to launch mcp_server.py as a subprocess and send JSON-RPC requests over stdin/stdout. The example initializes the server, lists tools, creates a draft, adds text, and saves the draft. The expected tool list includes 'create_draft', 'add_video', 'add_audio', 'add_image', 'add_text', 'add_subtitle', 'add_effect', 'add_sticker', 'add_video_keyframe', 'get_video_duration', and 'save_draft'. ```python import json, subprocess proc = subprocess.Popen( ["python3", "mcp_server.py"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True ) def rpc(method, params=None, mid=1): req = {"jsonrpc": "2.0", "id": mid, "method": method} if params is not None: req["params"] = params proc.stdin.write(json.dumps(req) + "\n") proc.stdin.flush() return json.loads(proc.stdout.readline()) init = rpc("initialize", {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "t", "version": "1"}}) assert init["result"]["serverInfo"]["name"] == "capcut-api" tools = rpc("tools/list") print([t["name"] for t in tools["result"]["tools"]]) # ['create_draft', 'add_video', 'add_audio', 'add_image', 'add_text', # 'add_subtitle', 'add_effect', 'add_sticker', 'add_video_keyframe', # 'get_video_duration', 'save_draft'] created = rpc("tools/call", {"name": "create_draft", "arguments": {"width": 1080, "height": 1920}}) text = created["result"]["content"][0]["text"] result = json.loads(text) # {"success": true, "result": {"draft_id": ..., "draft_url": ...}, ...} draft_id = result["result"]["draft_id"] rpc("tools/call", {"name": "add_text", "arguments": {"text": "Hello", "start": 0, "end": 3, "draft_id": draft_id}}) rpc("tools/call", {"name": "save_draft", "arguments": {"draft_id": draft_id}}) ``` -------------------------------- ### Example success response for POST /create_draft Source: https://github.com/ashreo/capcutapi Shows the JSON structure returned by the create_draft endpoint on success, including draft_id and draft_url fields. ```json { "draft_id": "dfd_cat_1752912902_0cae2e04", "draft_url": "https://?draft_id=dfd_cat_..." } ``` -------------------------------- ### GET /get_text_intro_types Source: https://github.com/ashreo/capcutapi Retrieves the list of text intro types. The list source depends on the IS_CAPCUT_ENV environment variable. ```APIDOC ## GET /get_text_intro_types ### Description Retrieves the list of text intro types. The list source depends on the IS_CAPCUT_ENV environment variable. ### Method GET ### Endpoint /get_text_intro_types ### Response #### Success Response (200) - **output** (list of objects) - Each object contains a `name` field (string). #### Error Response - **success** (boolean) - false on error. - **error** (string) - Error message: "Error occurred while getting text intro types: ". ``` -------------------------------- ### GET /get_text_intro_types Source: https://github.com/ashreo/capcutapi Retrieves the list of text intro types. The response envelope contains an `output` list of `{"name": ""}` objects, with enum values selected based on the `IS_CAPCUT_ENV` environment variable. ```APIDOC ## GET /get_text_intro_types ### Description Retrieves the list of text intro types. The response envelope contains an `output` list of `{"name": ""}` objects, with enum values selected based on the `IS_CAPCUT_ENV` environment variable. ### Method GET ### Endpoint /get_text_intro_types ### Response #### Success Response (200) - **output** (array) - List of objects with a `name` field containing the enum member name. ``` -------------------------------- ### timing_decorator(func_name) Source: https://github.com/ashreo/capcutapi Decorator that prints execution start and elapsed time for the wrapped function. Re-raises any exceptions after logging. ```APIDOC ## timing_decorator(func_name) ### Description Decorator that prints execution start and elapsed time for the wrapped function. Re-raises any exceptions after logging. ### Parameters - **func_name** (str) - Required - Name to display in the log messages. ### Returns - **callable** - Decorated function that logs execution time. ``` -------------------------------- ### POST /add_text Source: https://github.com/ashreo/capcutapi Adds a styled text segment. Required: text, start, end (all checked explicitly). ```APIDOC ## [POST] /add_text ### Description Adds a styled text segment. Required: `text`, `start`, `end` (all checked explicitly). ### Method POST ### Endpoint /add_text ### Parameters #### Request Body - `text` (string) - Required - Text content - `start` (number) - Required - Start (s) - `end` (number) - Required - End (s) - `draft_id` (string) - Optional - Draft id - `font` (string) - Optional - Default: "文轩体" - Font name from `Font_type` - `font_color` (string) - Optional - Default: "#FF0000" - Hex color - `font_size` (number) - Optional - Default: 8.0 - Size - `track_name` (string) - Optional - Default: "text_main" - Track name - `vertical` (bool) - Optional - Default: false - Vertical text - `font_alpha` (number) - Optional - Default: 1.0 - Text opacity - `fixed_width` (number) - Optional - Default: -1 - Fixed size ratio (<=0 disables) - `fixed_height` (number) - Optional - Default: -1 - Fixed size ratio (<=0 disables) - `border_alpha` (number) - Optional - Default: 1.0 - Border opacity - `border_color` (string) - Optional - Default: "#000000" - Border color - `border_width` (number) - Optional - Default: 0.0 - Border width - `background_color` (string) - Optional - Default: "#000000" - Background color - `background_style` (number) - Optional - Default: 0 - Background style - `background_alpha` (number) - Optional - Default: 0.0 - Background opacity - `bubble_effect_id` (string) - Optional - Bubble effect id - `bubble_resource_id` (string) - Optional - Bubble effect id - `effect_effect_id` (string) - Optional - Text effect id - `intro_animation` (string) - Optional - Entrance animation name - `intro_duration` (number) - Optional - Default: 0.5 - Entrance duration (s) - `outro_animation` (string) - Optional - Exit animation name - `outro_duration` (number) - Optional - Default: 0.5 - Exit duration (s) - `width` (number) - Optional - Default: 1080 - Canvas width - `height` (number) - Optional - Default: 1920 - Canvas height ### Response #### Success Response (200) - No response schema provided in source. ``` -------------------------------- ### Example response from add_text endpoint Source: https://github.com/ashreo/capcutapi Shows the JSON response returned by the add_text endpoint, including success flag, draft ID, and draft URL. ```json { "success": true, "output": { "draft_id": "dfd_cat_1752912902_0cae2e04", "draft_url": "https://www.install-ai-guider.top/draft/downloader?draft_id=dfd_cat_1752912902_0cae2e04" }, "error": "" } ``` -------------------------------- ### Example request to add_text endpoint Source: https://github.com/ashreo/capcutapi Sends a POST request to the /add_text endpoint with a JSON payload containing text and timing parameters. ```bash curl -s -X POST http://localhost:9001/add_text \ -H 'Content-Type: application/json' \ -d '{"text":"Hello","start":0,"end":3}' ``` -------------------------------- ### GET /get_intro_animation_types Source: https://github.com/ashreo/capcutapi Retrieves the list of intro animation types. The response envelope contains an `output` list of `{"name": ""}` objects, with enum values selected based on the `IS_CAPCUT_ENV` environment variable. ```APIDOC ## GET /get_intro_animation_types ### Description Retrieves the list of intro animation types. The response envelope contains an `output` list of `{"name": ""}` objects, with enum values selected based on the `IS_CAPCUT_ENV` environment variable. ### Method GET ### Endpoint /get_intro_animation_types ### Response #### Success Response (200) - **output** (array) - List of objects with a `name` field containing the enum member name. ``` -------------------------------- ### upload_to_oss function signature Source: https://github.com/ashreo/capcutapi Defines the upload_to_oss function that uploads a file to Aliyun OSS using OSS_CONFIG credentials and generates a 24-hour signed GET URL, then deletes the local file. ```python def upload_to_oss(path): ``` -------------------------------- ### Import and use utility functions from util Source: https://github.com/ashreo/capcutapi Demonstrates importing and using hex_to_rgb, url_to_hash, generate_draft_url, and is_windows_path. Shows expected outputs and that hex_to_rgb raises ValueError for invalid input. ```python from util import hex_to_rgb, url_to_hash, generate_draft_url, is_windows_path print(hex_to_rgb("#FF0000")) # (1.0, 0.0, 0.0) print(url_to_hash("https://a/b.mp4")) # 16-char sha256 prefix print(generate_draft_url("dfd_cat_1_ab")) # https://www.install-ai-guider.top/draft/downloader?draft_id=... assert is_windows_path(r"C:\Users\me") is True try: hex_to_rgb("notacolor") except ValueError as e: print(e) ``` -------------------------------- ### Timerange.__init__(start, duration) Source: https://github.com/ashreo/capcutapi Initializes a Timerange object with start and duration in microseconds. Duration is not the end time. ```APIDOC ## Timerange.__init__(start, duration) ### Description Initializes a Timerange object with start and duration in microseconds. Duration is not the end time. ### Method Constructor ### Signature ```python def __init__(self, start: int, duration: int) ``` ### Parameters - **start** (int) - Required - Start time in microseconds. - **duration** (int) - Required - Duration in microseconds (not end time). ``` -------------------------------- ### Basic video + audio composition using add_video_track and add_audio_track Source: https://github.com/ashreo/capcutapi Shows how to add a video track and then an audio track to the same draft. The video function returns a draft_id that is passed to the audio function. The audio result includes a draft_url. ```python from add_video_track import add_video_track from add_audio_track import add_audio_track video = add_video_track( video_url="https://example.com/clip.mp4", start=0, end=10, speed=1.0, volume=0.9, transition="Dissolve", transition_duration=0.5, mask_type="Circle", background_blur=2, ) draft_id = video["draft_id"] audio = add_audio_track( audio_url="https://example.com/music.mp3", draft_id=draft_id, volume=0.6, track_name="bgm", sound_effects=[("Echo", [0.5, None])], ) print(audio["draft_url"]) ``` -------------------------------- ### Upload files to OSS using upload_to_oss and upload_mp4_to_oss Source: https://github.com/ashreo/capcutapi Demonstrates uploading a draft zip and an MP4 file to OSS. upload_to_oss uses OSS_CONFIG and deletes the file; upload_mp4_to_oss uses MP4_OSS_CONFIG with V4 signature. ```python from oss import upload_to_oss, upload_mp4_to_oss url = upload_to_oss("/tmp/draft.zip") # uses OSS_CONFIG, deletes the file mp4_url = upload_mp4_to_oss("/tmp/final.mp4") # uses MP4_OSS_CONFIG, V4 signature ``` -------------------------------- ### Timerange class - init, import_json, end, overlaps, export_json Source: https://github.com/ashreo/capcutapi Timerange represents a time range in microseconds. Constructor takes start and duration (not end time). import_json parses a dict, end property returns start + duration, overlaps checks overlap, export_json returns {'start': ..., 'duration': ...}. ```python def __init__(self, start: int, duration: int): # µs; duration, not end time @classmethod def import_json(cls, json_obj: Dict[str, str]) -> "Timerange": # line 52 @property def end(self) -> int: # start + duration def overlaps(self, other: "Timerange") -> bool def export_json(self) -> Dict[str, int] # {"start": ..., "duration": ...} ``` -------------------------------- ### Timerange class definition Source: https://github.com/ashreo/capcutapi Defines a time range with start and duration in microseconds. The 'end' property is read-only and equals start + duration. Used by trange(), tim(), segment constructors, and track functions. ```python class Timerange: start: int # µs duration: int # µs ``` -------------------------------- ### Catching exceptions in consumer code Source: https://github.com/ashreo/capcutapi Example showing how consumer code can catch the custom exceptions raised by the pyJianYingDraft API. The example demonstrates catching TrackNotFound and AmbiguousTrack when calling get_imported_track. ```APIDOC ```python from pyJianYingDraft import exceptions try: script.get_imported_track(draft.Track_type.text, name="subs") except exceptions.TrackNotFound: print("no such imported track") except exceptions.AmbiguousTrack: print("several tracks match") ``` ``` -------------------------------- ### Video_segment add_animation method Source: https://github.com/ashreo/capcutapi Adds an animation to the segment. Intro starts at 0 using default duration; outro starts at target_timerange.duration - duration; combo fills the whole segment. Raises TypeError for invalid animation types. ```python add_animation(self, animation_type: Union[Intro_type, Outro_type, Group_animation_type, CapCut_Intro_type, CapCut_Outro_type, CapCut_Group_animation_type], duration: Optional[Union[int, str]] = None) ``` -------------------------------- ### Timerange.export_json() Source: https://github.com/ashreo/capcutapi Exports the timerange as a JSON dictionary with start and duration fields. ```APIDOC ## Timerange.export_json() ### Description Exports the timerange as a JSON dictionary with start and duration fields. ### Method Method ### Signature ```python def export_json(self) -> Dict[str, int] ``` ### Returns - **Dict[str, int]** - Dictionary with keys `"start"` and `"duration"`. ``` -------------------------------- ### Run test client (test_mcp_client.py) Source: https://github.com/ashreo/capcutapi/blob/main/MCP_Documentation_English.md Runs the test client to validate the CapCut MCP server. Use this to verify server startup, tool list retrieval, draft creation, text addition, media addition, effects, and draft saving. ```bash # Run test client python test_mcp_client.py ``` -------------------------------- ### add_effect_impl(effect_type, start, end, params) Source: https://github.com/ashreo/capcutapi Adds an effect to a video project. The parameters list is reversed internally by the implementation. ```APIDOC ## add_effect_impl(effect_type, start, end, params) ### Description Adds an effect to a video project. The parameters list is reversed internally by the implementation. ### Method Function call ### Endpoint `add_effect_impl(effect_type, start, end, params)` ### Parameters - **effect_type** (string) - Required - Type of effect (e.g., "Glow") - **start** (number) - Required - Start time in seconds - **end** (number) - Required - End time in seconds - **params** (array) - Required - List of effect parameters (reversed internally) ### Request Example ```python from add_effect_impl import add_effect_impl result = add_effect_impl( effect_type="Glow", start=0, end=3, params=[0.5, None, 0.8], # reversed internally by the implementation ) print(result) ``` ``` -------------------------------- ### Timerange.end property Source: https://github.com/ashreo/capcutapi Returns the end time of the timerange, calculated as start + duration. ```APIDOC ## Timerange.end property ### Description Returns the end time of the timerange, calculated as start + duration. ### Method Property ### Signature ```python @property def end(self) -> int ``` ### Returns - **int** - End time in microseconds (start + duration). ``` -------------------------------- ### Add multi-style text with different colors Source: https://github.com/ashreo/capcutapi/blob/main/MCP_Documentation_English.md Adds text with different font colors for different segments, defined by start and end indices. ```python # Different colored text segments mcp_client.call_tool("add_text", { "text": "Colorful Text Effect", "draft_id": draft_id, "text_styles": [ {"start": 0, "end": 2, "font_color": "#FF0000"}, {"start": 2, "end": 4, "font_color": "#00FF00"} ] }) ``` -------------------------------- ### Create draft Source: https://github.com/ashreo/capcutapi/blob/main/MCP_Documentation_English.md Creates a 1080x1920 portrait project and returns a draft ID for subsequent operations. ```python # Create 1080x1920 portrait project result = mcp_client.call_tool("create_draft", { "width": 1080, "height": 1920 }) draft_id = result["draft_id"] ``` -------------------------------- ### Basic draft creation and save with requests Source: https://github.com/ashreo/capcutapi Shows the core workflow: create a draft, add a video, then save the draft. Uses the local server at http://localhost:9001. The response envelope contains 'success' and 'output' fields; the draft URL is returned after saving. ```python import requests BASE = "http://localhost:9001" r = requests.post(f"{BASE}/create_draft", json={"width": 1080, "height": 1920}) r.raise_for_status() draft_id = r.json()["output"]["draft_id"] r = requests.post(f"{BASE}/add_video", json={ "video_url": "https://example.com/bg.mp4", "draft_id": draft_id, "start": 0, "end": 10, "volume": 0.8, "transition": "fade_in" }) print(r.json()["success"]) r = requests.post(f"{BASE}/save_draft", json={"draft_id": draft_id}) print(r.json()["output"]["draft_url"]) ``` -------------------------------- ### GET /get_font_types Source: https://github.com/ashreo/capcutapi Retrieves the list of font types. This route does not switch based on the IS_CAPCUT_ENV environment variable. ```APIDOC ## GET /get_font_types ### Description Retrieves the list of font types. This route does not switch based on the IS_CAPCUT_ENV environment variable. ### Method GET ### Endpoint /get_font_types ### Response #### Success Response (200) - **output** (list of objects) - Each object contains a `name` field (string). #### Error Response - **success** (boolean) - false on error. - **error** (string) - Error message: "Error occurred while getting font types: ". ``` -------------------------------- ### GET /get_mask_types Source: https://github.com/ashreo/capcutapi Retrieves the list of mask types. The list source depends on the IS_CAPCUT_ENV environment variable. ```APIDOC ## GET /get_mask_types ### Description Retrieves the list of mask types. The list source depends on the IS_CAPCUT_ENV environment variable. ### Method GET ### Endpoint /get_mask_types ### Response #### Success Response (200) - **output** (list of objects) - Each object contains a `name` field (string). #### Error Response - **success** (boolean) - false on error. - **error** (string) - Error message: "Error occurred while getting mask types: ". ``` -------------------------------- ### GET /get_transition_types Source: https://github.com/ashreo/capcutapi Retrieves the list of transition types. The list source depends on the IS_CAPCUT_ENV environment variable. ```APIDOC ## GET /get_transition_types ### Description Retrieves the list of transition types. The list source depends on the IS_CAPCUT_ENV environment variable. ### Method GET ### Endpoint /get_transition_types ### Response #### Success Response (200) - **output** (list of objects) - Each object contains a `name` field (string). #### Error Response - **success** (boolean) - false on error. - **error** (string) - Error message: "Error occurred while getting transition types: ". ``` -------------------------------- ### Download file with retry using download_file Source: https://github.com/ashreo/capcutapi Shows how to download a file with retries and timeout. download_file returns False on failure and never raises an exception. ```python from downloader import download_file ok = download_file("https://example.com/asset.mp4", "/tmp/assets/asset.mp4", max_retries=5, timeout=60) if not ok: print("download failed after retries") # download_file returns False, never raises ``` -------------------------------- ### Contribution workflow with git commands Source: https://github.com/ashreo/capcutapi/blob/main/README.md Commands to fork, branch, commit, push, and open a pull request for contributing to the CapCutAPI project. ```bash # 1. Fork the project git clone https://github.com/your-username/CapCutAPI.git # 2. Create feature branch git checkout -b feature/amazing-feature # 3. Commit changes git commit -m 'Add amazing feature' # 4. Push branch git push origin feature/amazing-feature # 5. Create Pull Request ``` -------------------------------- ### GET /get_text_outro_types Source: https://github.com/ashreo/capcutapi Retrieves the list of text outro types. The list source depends on the IS_CAPCUT_ENV environment variable. ```APIDOC ## GET /get_text_outro_types ### Description Retrieves the list of text outro types. The list source depends on the IS_CAPCUT_ENV environment variable. ### Method GET ### Endpoint /get_text_outro_types ### Response #### Success Response (200) - **output** (list of objects) - Each object contains a `name` field (string). #### Error Response - **success** (boolean) - false on error. - **error** (string) - Error message: "Error occurred while getting text outro types: ". ``` -------------------------------- ### Complete MCP Workflow for Video Creation Source: https://github.com/ashreo/capcutapi/blob/main/README.md Complete MCP workflow: creates a draft, adds a background video, adds styled text, adds a keyframe animation, and saves the project. The draft_id is passed between calls. The final save returns a draft_url. ```python # 1. Create new project draft = mcp_client.call_tool("create_draft", { "width": 1080, "height": 1920 }) draft_id = draft["result"]["draft_id"] # 2. Add background video mcp_client.call_tool("add_video", { "video_url": "https://example.com/bg.mp4", "draft_id": draft_id, "start": 0, "end": 10, "volume": 0.6 }) # 3. Add title text mcp_client.call_tool("add_text", { "text": "AI-Driven Video Production", "draft_id": draft_id, "start": 1, "end": 6, "font_size": 56, "shadow_enabled": True, "background_color": "#1E1E1E" }) # 4. Add keyframe animation mcp_client.call_tool("add_video_keyframe", { "draft_id": draft_id, "track_name": "main", "property_types": ["scale_x", "scale_y", "alpha"], "times": [0, 2, 4], "values": ["1.0", "1.2", "0.8"] }) # 5. Save project result = mcp_client.call_tool("save_draft", { "draft_id": draft_id }) print(f"Project saved: {result['result']['draft_url']}") ``` -------------------------------- ### url_to_hash Source: https://github.com/ashreo/capcutapi Generates a 16-character SHA256 prefix hash from a URL string. Used for creating unique identifiers for media assets. ```APIDOC ## url_to_hash ### Description Generates a 16-character SHA256 prefix hash from a URL string. Used for creating unique identifiers for media assets. ### Method Function ### Signature `url_to_hash(url: str) -> str` ### Parameters - **url** (str) - Required - The URL string to hash. ### Returns - **str** - A 16-character SHA256 prefix hash of the input URL. ### Request Example ```python url_to_hash("https://a/b.mp4") ``` ### Response Example ```python "16-char sha256 prefix" ``` ``` -------------------------------- ### GET /get_outro_animation_types Source: https://github.com/ashreo/capcutapi Retrieves the list of outro animation types. The list source depends on the IS_CAPCUT_ENV environment variable. ```APIDOC ## GET /get_outro_animation_types ### Description Retrieves the list of outro animation types. The list source depends on the IS_CAPCUT_ENV environment variable. ### Method GET ### Endpoint /get_outro_animation_types ### Response #### Success Response (200) - **output** (list of objects) - Each object contains a `name` field (string). #### Error Response - **success** (boolean) - false on error. - **error** (string) - Error message: "Error occurred while getting outro animation types: ". ``` -------------------------------- ### generate_draft_url function definition Source: https://github.com/ashreo/capcutapi Builds a draft preview URL using DRAFT_DOMAIN and PREVIEW_ROUTER from settings.local. Returns f"{DRAFT_DOMAIN}{PREVIEW_ROUTER}?draft_id={draft_id}". ```python def generate_draft_url(draft_id): return f"{DRAFT_DOMAIN}{PREVIEW_ROUTER}?draft_id={draft_id}" ``` -------------------------------- ### trange(start, duration) Source: https://github.com/ashreo/capcutapi Convenience constructor for creating a Timerange. The second argument is a duration, not an end time. ```APIDOC ## trange(start, duration) ### Description Convenience constructor for creating a Timerange. The second argument is a duration, not an end time. ### Method Function ### Signature ```python def trange(start: Union[str, float], duration: Union[str, float]) -> Timerange ``` ### Parameters - **start** (Union[str, float]) - Required - Start time, can be string or number. - **duration** (Union[str, float]) - Required - Duration, can be string or number. ### Returns - **Timerange** - A new Timerange instance. ### Example ```python trange("1s", "2s") ``` ``` -------------------------------- ### get_platform_info function definition Source: https://github.com/ashreo/capcutapi Defines get_platform_info, which returns platform information for script_file.py's dumps method. Returns None when IS_CAPCUT_ENV is false, otherwise a dict with app_id 359289, app_source 'cc', app_version '6.5.0', device_id, hard_disk_id, mac_address, os 'mac', os_version '15.5'. ```python def get_platform_info(): """获取平台信息,用于script_file.py中的dumps方法,cap_cut需要返回platform信息 Returns: dict: 平台信息字典 """ ``` -------------------------------- ### GET /get_video_character_effect_types Source: https://github.com/ashreo/capcutapi Retrieves the list of video character effect types. The list source depends on the IS_CAPCUT_ENV environment variable. ```APIDOC ## GET /get_video_character_effect_types ### Description Retrieves the list of video character effect types. The list source depends on the IS_CAPCUT_ENV environment variable. ### Method GET ### Endpoint /get_video_character_effect_types ### Response #### Success Response (200) - **output** (list of objects) - Each object contains a `name` field (string). #### Error Response - **success** (boolean) - false on error. - **error** (string) - Error message: "Error occurred while getting video character effect types: ". ``` -------------------------------- ### Add Video Material via HTTP API Source: https://github.com/ashreo/capcutapi/blob/main/README.md Sends a POST request to the /add_video endpoint to add a background video to the project. The request includes video URL, start/end times, dimensions, volume, and a fade_in transition. The response is printed as JSON. ```python import requests # Add background video response = requests.post("http://localhost:9001/add_video", json={ "video_url": "https://example.com/background.mp4", "start": 0, "end": 10, "width": 1080, "height": 1920, "volume": 0.8, "transition": "fade_in" }) print(f"Video addition result: {response.json()}") ``` -------------------------------- ### GET /get_video_scene_effect_types Source: https://github.com/ashreo/capcutapi Retrieves the list of video scene effect types. The list source depends on the IS_CAPCUT_ENV environment variable. ```APIDOC ## GET /get_video_scene_effect_types ### Description Retrieves the list of video scene effect types. The list source depends on the IS_CAPCUT_ENV environment variable. ### Method GET ### Endpoint /get_video_scene_effect_types ### Response #### Success Response (200) - **output** (list of objects) - Each object contains a `name` field (string). #### Error Response - **success** (boolean) - false on error. - **error** (string) - Error message: "Error occurred while getting video scene effect types: ". ``` -------------------------------- ### Flask app initialization Source: https://github.com/ashreo/capcutapi Creates the Flask application instance used by the HTTP server. This is the core object that all routes are registered on. ```python app = Flask(__name__) ``` -------------------------------- ### url_to_hash(url, length=16) Source: https://github.com/ashreo/capcutapi Converts a URL to a fixed-length hash string using SHA-256, truncated to the specified length. Used to build material names. ```APIDOC ## url_to_hash(url, length=16) ### Description Converts a URL to a fixed-length hash string using SHA-256, truncated to the specified length. Used to build material names. ### Parameters - **url** (str) - Required - The original URL string. - **length** (int) - Optional - Length of the hash string (maximum 64, default 16). ### Returns - **str** - Hash string of the specified length (without extension). ``` -------------------------------- ### Base_segment constructor Source: https://github.com/ashreo/capcutapi Base class for all segment types. Requires a material_id and target_timerange. Provides properties start, duration, end, and overlaps(other). ```python class Base_segment: def __init__(self, material_id: str, target_timerange: Timerange): ``` -------------------------------- ### POST /create_draft Source: https://github.com/ashreo/capcutapi Creates a new empty draft. Returns a draft ID and URL. ```APIDOC ## POST /create_draft ### Description Creates a new empty draft. ### Method POST ### Endpoint /create_draft ### Parameters #### Request Body - `width` (number) - Optional - Canvas width in pixels (default: 1080) - `height` (number) - Optional - Canvas height in pixels (default: 1920) ### Response #### Success Response (200) - `success` (bool) - true when the handler completed without raising - `output` (any) - Payload on success; a dict with `draft_id` and `draft_url` - `error` (string) - Error message on failure ("" on success) #### Response Example ```json { "draft_id": "dfd_cat_1752912902_0cae2e04", "draft_url": "https://?draft_id=dfd_cat_..." } ``` ``` -------------------------------- ### Timerange.import_json(json_obj) Source: https://github.com/ashreo/capcutapi Class method to create a Timerange from a JSON object. The JSON object should contain start and duration fields. ```APIDOC ## Timerange.import_json(json_obj) ### Description Class method to create a Timerange from a JSON object. The JSON object should contain start and duration fields. ### Method Class Method ### Signature ```python @classmethod def import_json(cls, json_obj: Dict[str, str]) -> "Timerange" ``` ### Parameters - **json_obj** (Dict[str, str]) - Required - JSON object with start and duration fields. ### Returns - **Timerange** - A new Timerange instance. ``` -------------------------------- ### Add text and video content Source: https://github.com/ashreo/capcutapi/blob/main/MCP_Documentation_English.md Adds a title text and a background video to the draft. The text is displayed from 0 to 5 seconds, and the video from 0 to 10 seconds with volume 0.8. ```python # Add title text mcp_client.call_tool("add_text", { "text": "My Video Title", "start": 0, "end": 5, "draft_id": draft_id, "font_size": 48, "font_color": "#FFFFFF" }) # Add background video mcp_client.call_tool("add_video", { "video_url": "https://example.com/video.mp4", "draft_id": draft_id, "start": 0, "end": 10, "volume": 0.8 }) ``` -------------------------------- ### generate_draft_url(draft_id) Source: https://github.com/ashreo/capcutapi Generates a preview URL for a draft using the configured draft domain and preview router. Returns the full URL string. ```APIDOC ## generate_draft_url(draft_id) ### Description Generates a preview URL for a draft using the configured draft domain and preview router. Returns the full URL string. ### Parameters - **draft_id** - Required - The draft identifier to include in the URL. ### Returns - **str** - The generated preview URL in the format `{DRAFT_DOMAIN}{PREVIEW_ROUTER}?draft_id={draft_id}`. ``` -------------------------------- ### POST /add_audio Source: https://github.com/ashreo/capcutapi Adds an audio segment. Requires an audio URL. ```APIDOC ## POST /add_audio ### Description Adds an audio segment. ### Method POST ### Endpoint /add_audio ### Parameters #### Request Body - `audio_url` (string) - Required - Audio URL - `draft_folder` (string) - Optional - Draft root for `replace_path` - `draft_id` (string) - Optional - Draft id - `start` (number) - Optional - Source start (s) (default: 0) - `end` (number) - Optional - Source end (s), `None` = full duration - `target_start` (number) - Optional - Target position (s) (default: 0) - `volume` (number) - Optional - Volume (default: 1.0) - `speed` (number) - Optional - Playback speed (default: 1.0) - `track_name` (string) - Optional - Track name (default: "audio_main") - `duration` (number) - Optional - Explicit duration (s) - `effect_type` (string) - Optional - Audio effect name; combined with `effect_params` into `sound_effects` - `effect_params` (array) - Optional - Effect parameter list - `width` (number) - Optional - Canvas width (default: 1080) - `height` (number) - Optional - Canvas height (default: 1920) ### Response #### Success Response (200) - `success` (bool) - true when the handler completed without raising - `output` (any) - Payload on success; a dict with `draft_id` and `draft_url` - `error` (string) - Error message on failure ("" on success) ``` -------------------------------- ### POST /add_subtitle Source: https://github.com/ashreo/capcutapi Imports SRT subtitles. Required: srt (SRT text, local path, or URL). ```APIDOC ## [POST] /add_subtitle ### Description Imports SRT subtitles. Required: `srt` (SRT text, local path, or URL). ### Method POST ### Endpoint /add_subtitle ### Parameters #### Request Body - `srt` (string) - Required - Content/path/URL - `draft_id` (string) - Optional - Draft id - `time_offset` (number) - Optional - Default: 0.0 - Global time shift (s) - `font` (string) - Optional - Font name - `font_size` (number) - Optional - Default: 5.0 - Size - `bold` (bool) - Optional - Default: false - Text style flag - `italic` (bool) - Optional - Default: false - Text style flag - `underline` (bool) - Optional - Default: false - Text style flag - `font_color` (string) - Optional - Default: "#FFFFFF" - Color - `vertical` (bool) - Optional - Default: false - Vertical layout - `alpha` (number) - Optional - Default: 1 - Text opacity - `border_alpha` (number) - Optional - Default: 1.0 - Border opacity - `border_color` (string) - Optional - Default: "#000000" - Border color - `border_width` (number) - Optional - Default: 0.0 - Border width - `background_color` (string) - Optional - Default: "#000000" - Background color - `background_style` (number) - Optional - Default: 0 - Background style - `background_alpha` (number) - Optional - Default: 0.0 - Background opacity - `transform_x` (number) - Optional - Default: 0.0 - X offset - `transform_y` (number) - Optional - Default: -0.8 - Y offset - `scale_x` (number) - Optional - Default: 1.0 - Scale - `scale_y` (number) - Optional - Default: 1.0 - Scale - `rotation` (number) - Optional - Default: 0.0 - Rotation (degrees) - `track_name` (string) - Optional - Default: "subtitle" - Track name - `width` (number) - Optional - Default: 1080 - Canvas width - `height` (number) - Optional - Default: 1920 - Canvas height ### Response #### Success Response (200) - No response schema provided in source. ``` -------------------------------- ### initialize Source: https://github.com/ashreo/capcutapi Initializes the MCP server and returns protocol version and server information. This is the first method called by an MCP client to establish the connection. ```APIDOC ## initialize ### Description Initializes the MCP server and returns protocol version and server information. This is the first method called by an MCP client to establish the connection. ### Method JSON-RPC ### Endpoint `initialize` ### Response #### Success Response ```json { "protocolVersion": "2024-11-05", "capabilities": { "experimental": {}, "tools": { "listChanged": false } }, "serverInfo": { "name": "capcut-api", "version": "1.12.3" } } ``` ``` -------------------------------- ### Task status JSON shape Source: https://github.com/ashreo/capcutapi Example of the status dictionary structure stored in the cache, containing fields like status, message, progress, completed_files, total_files, and draft_url. ```json { "status": "initialized", "message": "Task initialized", "progress": 0, "completed_files": 0, "total_files": 0, "draft_url": "" } ```