Create Dynamic Animations with Okaris Live Portrait Cognitive Actions

In the evolving landscape of digital content creation, the ability to animate static images using video inputs offers a transformative experience. The Okaris Live Portrait Cognitive Actions provide developers with powerful tools to create engaging animated portraits by manipulating source images with driving videos. These pre-built actions simplify the integration of sophisticated animation capabilities into your applications, allowing you to enhance user interaction and creativity without needing extensive animation expertise.
Prerequisites
Before integrating the Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform to authenticate your requests.
- Basic familiarity with JSON and making HTTP requests.
Authentication generally involves passing the API key in the request headers, allowing secure access to the action endpoints.
Cognitive Actions Overview
Animate Source Image Using Driving Video
The Animate Source Image Using Driving Video action allows you to create captivating animated portraits by utilizing a driving video to manipulate a static source image. This action supports customizable cropping, motion adjustments, and even head rotation for dynamic animations.
Input
The input for this action is a JSON object that must include the following required fields:
- drivingVideo: URI of the driving video for animation.
- sourceImage: URI of the source image to be animated.
Additionally, several optional parameters fine-tune the animation characteristics:
- scale: Scale factor for cropping the source (default is 2.3).
- enableCrop: Crop the source image (default is true).
- enableRemap: Use paste-back (default is true).
- sourceVideo: Optional URI of an additional source video.
- verticalRatio: Vertical position adjustment for cropping (default is -0.125).
- horizontalRatio: Horizontal position adjustment for cropping (default is 0).
- drivingVideoScale: Scale factor for the driving video (default is 2.2).
- enableCropDrivingVideo: Crop the driving video (default is false).
- enableVideoHeadRotation: Enable head rotation for animations (default is false).
- drivingSmoothnessVariance: Strength of motion smoothness (default is 3e-7).
- verticalCropRatioDrivingVideo: Vertical adjustment for driving video crop (default is -0.1).
- horizontalCropRatioDrivingVideo: Horizontal adjustment for driving video crop (default is 0).
Example Input:
{
"scale": 2.3,
"enableCrop": true,
"enableRemap": true,
"sourceImage": "https://replicate.delivery/pbxt/LM1eHhq9VUnim4cZmYHDLBZp7eKRj3QXxTid79ifYn37NJoi/image-13.webp",
"drivingVideo": "https://replicate.delivery/pbxt/LLyKx8PIeZAMBkTTpxCpoM1lWSx6YBBrRGXeMhBOxjFdpyFe/IMG_2228.mov",
"verticalRatio": -0.01,
"enableRelative": true,
"horizontalRatio": 0,
"drivingVideoScale": 2.2,
"enableCropDrivingVideo": false,
"enableVideoHeadRotation": false,
"drivingSmoothnessVariance": 0.01,
"verticalCropRatioDrivingVideo": -0.1,
"horizontalCropRatioDrivingVideo": 0
}
Output
Upon successful execution, this action returns a JSON object containing:
- gif: URI of the generated animated GIF.
- video: URI of the rendered animation video.
- video_comparison: URI for comparing the original and animated content.
Example Output:
{
"gif": "https://assets.cognitiveactions.com/invocations/440c5e75-fe6e-45f8-8c19-b182f9209b20/b2bcff9d-ce6b-4786-aa7e-c81e1a2523d0.gif",
"video": "https://assets.cognitiveactions.com/invocations/440c5e75-fe6e-45f8-8c19-b182f9209b20/b3795841-7cff-4c5d-9416-d5258825afe5.mp4",
"video_comparison": "https://assets.cognitiveactions.com/invocations/440c5e75-fe6e-45f8-8c19-b182f9209b20/8183af9f-4480-4184-ae74-2af4ce932702.mp4"
}
Conceptual Usage Example (Python)
Here is a conceptual Python code snippet demonstrating how to call the Cognitive Actions endpoint for this action:
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 = "d5ac62e7-bf82-4d3b-a88f-a454a9c4053b" # Action ID for Animate Source Image Using Driving Video
# Construct the input payload based on the action's requirements
payload = {
"scale": 2.3,
"enableCrop": True,
"enableRemap": True,
"sourceImage": "https://replicate.delivery/pbxt/LM1eHhq9VUnim4cZmYHDLBZp7eKRj3QXxTid79ifYn37NJoi/image-13.webp",
"drivingVideo": "https://replicate.delivery/pbxt/LLyKx8PIeZAMBkTTpxCpoM1lWSx6YBBrRGXeMhBOxjFdpyFe/IMG_2228.mov",
"verticalRatio": -0.01,
"enableRelative": True,
"horizontalRatio": 0,
"drivingVideoScale": 2.2,
"enableCropDrivingVideo": False,
"enableVideoHeadRotation": False,
"drivingSmoothnessVariance": 0.01,
"verticalCropRatioDrivingVideo": -0.1,
"horizontalCropRatioDrivingVideo": 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 API key with your actual key and ensure the endpoint URL aligns with your implementation. This example shows how to structure the input JSON payload for the action, making it straightforward for developers to adapt for their needs.
Conclusion
The Okaris Live Portrait Cognitive Actions provide an innovative way to animate static images using driving videos, opening new avenues for creative applications. By leveraging these actions, developers can enhance their applications with visually engaging content that captivates users. Whether you are building a multimedia application, a social media tool, or an artistic platform, these Cognitive Actions are a valuable addition to your development toolkit. As a next step, consider experimenting with the parameters to create unique animated effects tailored to your application’s requirements.