{"templateId":"openapi_docs","sharedDataIds":{"openAPIDocsStore":"oas-reference/ai_video_background_replace.yaml","sidebar":"sidebar-reference/sidebars.yaml"},"props":{"definitionId":"reference/ai_video_background_replace.yaml","dynamicMarkdocComponents":[],"baseSlug":"/reference/ai_video_background_replace","seo":{"title":"AI Video Background Replace","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"itemId":"","disableAutoScroll":true,"metadata":{"type":"openapi","title":"AI Video Background Replace","description":"# Overview\n\n**AI Video Background Replace**\n\n![](https://bcw-media.s3.ap-northeast-1.amazonaws.com/Green_Screen_ddb7892393.png)\n\nThe AI Video Background Replace API enables you to seamlessly add any background you choose. You can select from a wide range of options, including scenic landscapes, custom images, or even lighthearted visuals, giving you complete creative control to design the ideal setting for your content.\nThere is no need for a studio or green screen. You can easily replace video backgrounds to achieve a clean and professional look. Whether you want to introduce a new environment or remove unwanted distractions, this solution is ideal for producing engaging videos and tutorials without requiring expensive equipment.\n\n\n---\n\n## Integration Guide\n\n**1. Prepare a Source Video and a Background Image**\nThe output must be in MP4 format with the same resolution as the input, a frame rate capped at 30 frames per second with automatic conversion if the input exceeds this limit, and a maximum duration of 600 seconds with only the first 600 seconds retained if the input video is longer.\n\nThe background image must be in JPG or PNG format with a maximum resolution of 4096 by 4096 pixels with the long side not exceeding 4096 pixels and a file size limit of 10 megabytes.\n\n\n**2. Upload File**\nRequest upload URLs and file IDs via:\n\n```\nPOST /s2s/v2.0/file/bg-replace-vid\n```\n\n\n**3. Execute AI Task**\n\n```\nPOST /s2s/v2.0/task/bg-replace-vid\n```\n\nSubmit the task using file IDs or image URLs as input. The response returns a task_id for tracking and retrieving the result.\n\n\n**4. Retrieve Task Result**\n\n```\nGET /s2s/v2.0/task/bg-replace-vid/{task_id}\n```\n\nUse the task ID to track status and obtain results.\n\n[Webhooks](/develop/webhook.md) can be configured to receive asynchronous notifications on task completion with a success or error status. Polling is also supported by repeatedly calling the task endpoint until the status is updated from running to success or error.\n\nUsage is only charged when the task completes successfully.\n\n\n\n---\n\n## File Specs & Errors\n\n* Supported Formats & Dimensions\n\n|AI Feature|Supported Dimensions|Supported File Size|Supported Formats|\n|  ----  | ----  | ----  | ----  |\n| AI Video Background Replace | The output must be in MP4 format with the same resolution as the input, a frame rate capped at 30 frames per second with automatic conversion if the input exceeds this limit, and a maximum duration of 600 seconds with only the first 600 seconds retained if the input video is longer. <br>The background image must be in JPG or PNG format with a maximum resolution of 4096 by 4096 pixels with the long side not exceeding 4096 pixels and a file size limit of 10 megabytes. | Video length limit: 600s <br> Background image: <10MB | container: mp4 <br>video: MPEG-4, MPEG-4 AVC, <br>audio: aac, amr, mp3 |\n\n* Error Codes\n\n|Error Code|Description|\n|  ----  | ----  |\n| error_download_video | Download source video error |\n| error_decode_video | Decode source video error |\n| error_unsupported_video | Unsupported video format |\n| exceed_max_filesize | Input file size exceeds the maximum limit|\n| error_nsfw_content_detected | NSFW content detected in the source file |\n| error_decode_mask | Decode mask image error |\n| invalid_parameter | Invalid parameter value|\n\n* Environment & Dependency\n\n| Sample Code Language / Tool | Recommended Runtime Versions |\n|---|---|\n| cURL | - bash >= 3.2</br>   - curl >= 7.58 (modern TLS/HTTP support)</br>   - jq >= 1.6 (robust JSON parsing) |\n| Node.js (JavaScript) | Node >= 18 (for global fetch) |\n| JavaScript | - Chrome / Edge >= 80</br>   - Firefox >= 74</br>   - Safari >= 13.1 |\n| PHP | PHP >= 7.4 (for modern TLS/compat), ext-curl (recommended) or allow_url_fopen=On + ext-openssl, ext-json |\n| Python | Python >= 3.10 (for f-strings), requests >= 2.20.0 |\n| Java | Java 11+ (for HttpClient), Jackson Databind >= 2.12.0 |\n"},"compilationErrors":[],"markdown":{"partials":{},"variables":{"rbac":{"teams":["anonymous"]},"user":{},"remoteAddr":{"hostname":"docs.perfectcorp.com","port":4000,"ipAddress":"216.73.216.114"},"lang":"default_locale","env":{"PUBLIC_REDOCLY_BRANCH_NAME":"master"}}},"pagePropGetterError":{"message":"","name":""}},"slug":"/reference/ai_video_background_replace","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}