Transform Your Videos with Inpainting: A Guide to andreasjansson/wan-1.3b-inpaint Actions

In the world of video editing and content creation, the ability to modify existing footage creatively is invaluable. The andreasjansson/wan-1.3b-inpaint API offers developers a powerful toolset for inpainting and video-to-video transformations using the advanced Wan 2.1 model. This set of Cognitive Actions enables users to modify specified areas within a video based on a text prompt and a mask, facilitating both creative enhancements and corrective adjustments to video content.
Prerequisites
Before diving into the integration of Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform.
- A basic understanding of how to make HTTP requests and handle JSON data.
Authentication typically involves passing your API key in the headers of your requests, allowing you to securely access the available actions.
Cognitive Actions Overview
Perform Video Inpainting with Wan 2.1
Description: This action executes inpainting and video-to-video transformations using the Wan 2.1 model. It modifies specified areas in a video according to a provided text prompt and a mask, enabling both creative and corrective changes.
Category: Video Processing
Input
The action requires the following fields in its input schema:
- inputVideo (string, required): URI of the original video file to be processed for inpainting.
- prompt (string, required): Text input that guides the inpainting of the masked area in the video.
- seed (integer, optional): Random seed for initialization, default is -1 (random seed).
- maskVideo (string, optional): URI of a mask video indicating areas to be inpainted. Leave blank for a full video-to-video transformation.
- strength (number, optional): Intensity of the inpainting effect, ranging from 0 to 1, with a default of 0.9.
- expandMask (integer, optional): Number of pixels to expand the existing mask, default is 10 (range 0-100).
- guideScale (number, optional): Controls adherence to the input prompt, default is 5 (range 1-15).
- samplingSteps (integer, optional): Number of sampling steps, default is 50 (range 20-100).
- negativePrompt (string, optional): Aspects to avoid during inpainting; leave blank if not applicable.
- framesPerSecond (integer, optional): Frame rate of the output video, default is 16 (range 5-30).
- inpaintFixupSteps (integer, optional): Number of fixup steps applied after inpainting, default is 0 (not applicable in video-to-video mode).
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 pointing to the processed video file.
Example Output:
https://assets.cognitiveactions.com/invocations/fb038429-01a7-4857-96cd-462143407295/5e93b5fc-37b8-4b37-a965-56b3e1a2e35b.mp4
Conceptual Usage Example (Python)
Here’s how you might call the Perform Video Inpainting with Wan 2.1 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 = "9e292570-97f9-42d8-87f9-d88a2caf25be" # Action ID for Perform Video Inpainting with 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, replace the placeholder for the API key and adjust the endpoint URL as necessary. The action ID and input payload are structured according to the requirements of the Perform Video Inpainting with Wan 2.1 action, illustrating how to integrate this powerful functionality into your application.
Conclusion
The andreasjansson/wan-1.3b-inpaint Cognitive Actions provide a robust set of tools for video manipulation, allowing developers to creatively enhance their content through inpainting techniques. By leveraging the capabilities of the Wan 2.1 model, you can implement exciting features in your applications. Explore further possibilities, experiment with different parameters, and push the boundaries of what you can create!