Transform Your Videos with Cognitive Actions: Inpainting Using Wan 2.1

In the world of video processing, enhancing visuals by removing unwanted elements or filling gaps can be a challenging task. The andreasjansson/wan-1.3b-inpaint Cognitive Actions offer a powerful solution for developers looking to integrate advanced video inpainting capabilities into their applications. This set of actions leverages the Wan 2.1 model to perform inpainting on videos, allowing you to customize how masked areas are transformed based on textual prompts. With the ability to adjust parameters like mask expansion and inpainting strength, developers can achieve stunning results with minimal effort.
Prerequisites
Before you begin using the Cognitive Actions, you'll need to ensure you have:
- An API key for the Cognitive Actions platform.
- A basic understanding of how to make API calls, specifically POST requests with JSON payloads.
Authentication typically involves passing your API key in the request headers, allowing you to securely access the Cognitive Actions.
Cognitive Actions Overview
Perform Video Inpainting Using Wan 2.1
This action enables the use of the Wan 2.1 model to conduct inpainting experiments on videos. You can transform masked areas according to the provided text prompts and fine-tune various parameters for customized video enhancements.
Input
The input for this action requires the following fields:
- inputVideo (string, required): URI of the original video that will be processed for inpainting.
- prompt (string, required): Text prompt guiding the inpainting process in the masked area.
- maskVideo (string, optional): URI of the video to use as a mask. White areas will be inpainted. Defaults to video-to-video processing if left blank.
- seed (integer, optional): Sets a random seed for generation. Use -1 for a random seed.
- strength (number, optional): Controls the strength of inpainting (0 to 1).
- expandMask (integer, optional): Expands the mask area by the specified number of pixels (0 to 100).
- guideScale (number, optional): Scale factor for model adherence to the prompt (1 to 15).
- samplingSteps (integer, optional): Number of iterations during inpainting (20 to 100).
- negativePrompt (string, optional): Specifies what should not appear in the inpainted area.
- framesPerSecond (integer, optional): Specifies output video frame rate (5 to 30).
- keepAspectRatio (boolean, optional): Maintains the original aspect ratio of the input video.
- inpaintFixupSteps (integer, optional): Number of fixup steps for refining the inpainted video (0 to 10).
Example Input:
{
"seed": -1,
"prompt": "A robot walking on the street",
"strength": 0.9,
"maskVideo": "https://replicate.delivery/xezq/N94eQyo3WBVWXyN8Aj4kpwQ42l6prb578m9tCJWaFgREnlJKA/masked_video.mp4",
"expandMask": 10,
"guideScale": 5,
"inputVideo": "https://replicate.delivery/xezq/UpqkYwl7hTqTJ5rfIE0eb5WpDv6quG6PeFcdtH157Y2uonloA/tmp2dc62s6m.output.mp4",
"samplingSteps": 30,
"negativePrompt": "",
"framesPerSecond": 16,
"inpaintFixupSteps": 0
}
Output
The action typically returns a URI to the processed video that has been inpainted according to the specified parameters.
Example Output:
https://assets.cognitiveactions.com/invocations/bf2852fc-66c6-469a-9705-7dd44016b15d/aa28fd4b-e5eb-450a-86e2-644c936d7017.mp4
Conceptual Usage Example (Python)
Here’s how a developer could call this action using Python:
import requests
import json
# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint
action_id = "eadbe620-a548-46cf-a075-ebfbe49bc6f3" # Action ID for Perform Video Inpainting Using Wan 2.1
# Construct the input payload based on the action's requirements
payload = {
"seed": -1,
"prompt": "A robot walking on the street",
"strength": 0.9,
"maskVideo": "https://replicate.delivery/xezq/N94eQyo3WBVWXyN8Aj4kpwQ42l6prb578m9tCJWaFgREnlJKA/masked_video.mp4",
"expandMask": 10,
"guideScale": 5,
"inputVideo": "https://replicate.delivery/xezq/UpqkYwl7hTqTJ5rfIE0eb5WpDv6quG6PeFcdtH157Y2uonloA/tmp2dc62s6m.output.mp4",
"samplingSteps": 30,
"negativePrompt": "",
"framesPerSecond": 16,
"inpaintFixupSteps": 0
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json"
}
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json={"action_id": action_id, "inputs": payload} # Hypothetical structure
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully:")
print(json.dumps(result, indent=2))
except requests.exceptions.RequestException as e:
print(f"Error executing action {action_id}: {e}")
if e.response is not None:
print(f"Response status: {e.response.status_code}")
try:
print(f"Response body: {e.response.json()}")
except json.JSONDecodeError:
print(f"Response body: {e.response.text}")
In this code snippet:
- You replace the Cognitive Actions API key and endpoint with your own credentials.
- The action ID corresponds to the inpainting action you want to invoke.
- The payload is constructed based on the required input schema for the action.
- The response is processed to handle any errors or output the results.
Conclusion
The andreasjansson/wan-1.3b-inpaint Cognitive Actions provide developers with a robust toolset for video inpainting. By utilizing the Wan 2.1 model, you can create customized video enhancements that transform your content seamlessly. Whether you're looking to enhance video quality or remove unwanted elements, these actions simplify the process while providing flexibility in how you implement them. Explore further use cases and dive deeper into the capabilities of these actions to elevate your video processing projects!