Create Stunning Video Animations with the Stable Video Diffusion Cognitive Actions

In the world of video generation, creating engaging animations from static images can be a game changer for developers. The Stable Video Diffusion Cognitive Actions offer a powerful solution for transforming images into dynamic video content. This API allows you to manipulate various parameters, such as video length and frame rate, to produce visually striking results tailored to your needs.
Prerequisites
Before getting started with the Stable Video Diffusion Cognitive Actions, you'll need to have the following in place:
- An API key for accessing the Cognitive Actions platform.
- Basic knowledge of JSON and HTTP requests.
Authentication typically involves including your API key in the request headers, allowing you to securely interact with the API.
Cognitive Actions Overview
Generate Stable Video Diffusion
The Generate Stable Video Diffusion action enables you to create video animations from an input image using advanced video generation techniques. You can customize parameters to achieve the desired effects, making it a versatile tool for developers looking to enhance their applications with animated content.
Input:
The input for this action must conform to the following schema:
{
"inputImage": "string", // URI of the input image
"seed": "integer", // Random seed for deterministic output (optional)
"videoLength": "string", // Specifies the length of the video
"decodingTime": "integer", // Number of frames to decode at once
"motionBucketId": "integer", // Level of motion in the video
"sizingStrategy": "string", // Strategy for resizing the input image
"framesPerSecond": "integer", // FPS for video playback
"conditionAugmentation": "number" // Amount of noise added to input
}
Example Input:
{
"seed": 1223,
"inputImage": "https://replicate.delivery/pbxt/KR1x0vzRgIBdkXVa0yYhrJvr7D8NCJvUanS2DEg1lWgUIarI/%E6%88%AA%E5%B1%8F2024-02-20%2013.53.19.png",
"videoLength": "14_frames_with_svd",
"decodingTime": 14,
"motionBucketId": 127,
"sizingStrategy": "maintain_aspect_ratio",
"framesPerSecond": 6,
"conditionAugmentation": 0.02
}
Output:
When you successfully invoke this action, you will receive a URL to the generated video:
https://assets.cognitiveactions.com/invocations/d3f53dba-3e16-4af8-9fe8-633bc710f483/e6f6cfaa-503b-4850-a49f-e3c6f107d8f7.mp4
This URL points directly to the produced video animation, which you can use in your applications.
Conceptual Usage Example (Python):
Here’s a conceptual example of how you might call the Cognitive Actions execution endpoint to generate a stable video diffusion animation:
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 = "a387d40e-2938-4d5b-a462-5be4e2d569ed" # Action ID for Generate Stable Video Diffusion
# Construct the input payload based on the action's requirements
payload = {
"seed": 1223,
"inputImage": "https://replicate.delivery/pbxt/KR1x0vzRgIBdkXVa0yYhrJvr7D8NCJvUanS2DEg1lWgUIarI/%E6%88%AA%E5%B1%8F2024-02-20%2013.53.19.png",
"videoLength": "14_frames_with_svd",
"decodingTime": 14,
"motionBucketId": 127,
"sizingStrategy": "maintain_aspect_ratio",
"framesPerSecond": 6,
"conditionAugmentation": 0.02
}
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 YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action_id is set to the ID of the Generate Stable Video Diffusion action. The payload is structured according to the required input schema. Upon executing the request, the resulting video URL will be printed if successful.
Conclusion
The Stable Video Diffusion Cognitive Actions provide an innovative way to create animated videos from static images, allowing developers to enrich their applications with captivating visual content. By adjusting parameters such as motion levels and video length, you can tailor the generated outputs to fit your creative vision. Explore the possibilities of video generation and bring your applications to life!