Create Stunning Videos from Images with Stable Video Diffusion Cognitive Actions

24 Apr 2025
Create Stunning Videos from Images with Stable Video Diffusion Cognitive Actions

In the rapidly evolving landscape of multimedia content creation, the ability to generate dynamic videos from static images can significantly enhance user engagement and creativity. The Stable Video Diffusion API provides developers with powerful Cognitive Actions to leverage image diffusion techniques for video generation. This article will guide you through the capabilities of these actions and show you how to integrate them into your applications effectively.

Prerequisites

Before you start using the Cognitive Actions, ensure you have:

  • An API key for the Cognitive Actions platform, which will be used for authentication.
  • Basic knowledge of JSON and RESTful API concepts.

To authenticate your requests, you will typically pass your API key in the request headers.

Cognitive Actions Overview

Generate Stable Video from Image

This action allows you to create a video from an input image using advanced image diffusion techniques. It offers options for customizing video length, resizing strategies, and motion levels, ensuring high-quality video outputs.

Input

The input for this action is structured as follows:

  • inputImageUri (required): The URI of the input image in a valid format.
  • videoLength (optional): Determines the number of frames in the generated video (default: 14_frames_with_svd).
  • decodingFrames (optional): Number of frames to decode at a time (default: 14).
  • motionBucketId (optional): Level of motion applied to the video (default: 127).
  • sizingStrategy (optional): How to resize the image (default: maintain_aspect_ratio).
  • framesPerSecond (optional): Controls frames displayed per second (default: 6).
  • conditionalAugmentation (optional): Amount of noise added to augment the image (default: 0.02).

Example Input:

{
  "videoLength": "14_frames_with_svd",
  "inputImageUri": "https://replicate.delivery/pbxt/KcAKZ1wW2WJmjM0Xov9I0VCvjNwCmau64PkNnJUVVWk67Q6d/2261702010499_.pic.jpg",
  "decodingFrames": 14,
  "motionBucketId": 127,
  "sizingStrategy": "maintain_aspect_ratio",
  "framesPerSecond": 6,
  "conditionalAugmentation": 0.02
}

Output

Upon successful execution, the action typically returns a URI pointing to the generated video.

Example Output:

https://assets.cognitiveactions.com/invocations/3e67fc02-29a8-4bd9-9927-2b4d97a9bf52/0387a738-dce1-4396-8e23-a75712f45856.mp4

Conceptual Usage Example (Python)

Here’s how you might structure your Python code to call 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 = "6586b5b0-b39d-425c-8bcb-e0f7da7dba13"  # Action ID for Generate Stable Video from Image

# Construct the input payload based on the action's requirements
payload = {
    "videoLength": "14_frames_with_svd",
    "inputImageUri": "https://replicate.delivery/pbxt/KcAKZ1wW2WJmjM0Xov9I0VCvjNwCmau64PkNnJUVVWk67Q6d/2261702010499_.pic.jpg",
    "decodingFrames": 14,
    "motionBucketId": 127,
    "sizingStrategy": "maintain_aspect_ratio",
    "framesPerSecond": 6,
    "conditionalAugmentation": 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 the placeholder for the API key and endpoint with your actual values.
  • The action ID and input payload are structured based on the requirements detailed above.

Conclusion

The Stable Video Diffusion Cognitive Actions provide a robust solution for developers looking to create dynamic video content from images. By leveraging the flexibility of these actions, you can easily integrate video generation capabilities into your applications. Consider exploring the various input options to customize the output according to your project's needs. Start creating captivating video content today!