Transform Images into Animated Videos with Cognitive Actions

24 Apr 2025
Transform Images into Animated Videos with Cognitive Actions

In the world of multimedia content creation, the ability to seamlessly transform static images into dynamic animated videos is a powerful tool. The georgedavila/ltx-img2vid Cognitive Actions provide developers with a straightforward API to generate animated videos from images. By leveraging this technology, developers can create engaging visual content for applications ranging from social media to gaming.

Prerequisites

Before diving into the integration of Cognitive Actions, ensure you have the following:

  • API Key: You will need an API key to access the Cognitive Actions platform. This key should be included in the request headers to authenticate your API calls.
  • Basic Knowledge of API Usage: Familiarity with making HTTP requests and handling JSON data will be beneficial.

Authentication typically involves passing your API key in the headers of your requests, allowing you to securely interact with the Cognitive Actions API.

Cognitive Actions Overview

Generate Animated Video from Image

The Generate Animated Video from Image action allows you to transform a static image into a lively animated video by specifying various parameters, including scene elements and output quality controls.

  • Category: image-animation

Input

The input requires a JSON object conforming to the following schema:

{
  "seed": 12345,
  "myPrompt": "A woman in an astronaut suit stares defiantly into the camera. Behind her is a pink ballroom glittering from incoming sunlight. She winks to the camera then turns her head to face the room. The scene appears to be from a film or television show.",
  "imageSource": "https://replicate.delivery/pbxt/MIKcf8vo7vTEZeBqHcepMZjXtg7TTtwaslC8RSigXjbn5zpq/testimg1.jpg",
  "outputWidth": 864,
  "outputHeight": 480,
  "guidanceScale": 3,
  "negativePrompt": "low quality, worst quality, inconsistent motion, blurry, jittery, distorted",
  "numberOfFrames": 97,
  "numberOfOutputs": 1,
  "outputFramesPerSecond": 24,
  "numberOfInferenceSteps": 50,
  "decodeTimestepParameter": 0.03,
  "decodeNoiseScaleParameter": 0.025
}
  • Required Fields:
    • myPrompt (string): Describes the animated scene based on the input image.
    • imageSource (string): The URI of the source image.
  • Optional Fields:
    • seed (integer): Random seed for variability.
    • outputWidth (integer): Width of the output video (between 128 and 2048).
    • outputHeight (integer): Height of the output video (between 128 and 2048).
    • guidanceScale (number): Influences the input text's impact on image generation (0 to 10).
    • negativePrompt (string): Aspects to avoid in the output.
    • numberOfFrames (integer): Choose from predefined frame counts (e.g., 97, 129).
    • numberOfOutputs (integer): Number of variations to generate (1 to 4).
    • outputFramesPerSecond (integer): FPS for the animation.
    • numberOfInferenceSteps (integer): Denoising steps for image refinement (1 to 500).
    • decodeTimestepParameter (number): Influences decoding timestep (0.005 to 1).
    • decodeNoiseScaleParameter (number): Controls noise scale during decoding (0.0005 to 1).

Example Input:

{
  "myPrompt": "A woman in an astronaut suit stares defiantly into the camera. Behind her is a pink ballroom glittering from incoming sunlight. She winks to the camera then turns her head to face the room. The scene appears to be from a film or television show.",
  "imageSource": "https://replicate.delivery/pbxt/MIKcf8vo7vTEZeBqHcepMZjXtg7TTtwaslC8RSigXjbn5zpq/testimg1.jpg",
  "outputWidth": 864,
  "outputHeight": 480,
  "guidanceScale": 3,
  "negativePrompt": "low quality, worst quality, inconsistent motion, blurry, jittery, distorted",
  "numberOfFrames": 97,
  "outputFramesPerSecond": 24,
  "numberOfInferenceSteps": 50
}

Output

Upon successful execution, the action returns a URL pointing to the generated animated video.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/304e62fa-c4d5-4a65-8069-671f2b819f33/89dc8e26-e136-457d-945d-848bea7e0e0c.mp4"
]

Conceptual Usage Example (Python)

Here is a conceptual Python code snippet demonstrating how to call the Cognitive Actions execution 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 = "66f608c9-15f3-435b-9b7e-4a4d66bf5709" # Action ID for Generate Animated Video from Image

# Construct the input payload based on the action's requirements
payload = {
    "myPrompt": "A woman in an astronaut suit stares defiantly into the camera. Behind her is a pink ballroom glittering from incoming sunlight. She winks to the camera then turns her head to face the room. The scene appears to be from a film or television show.",
    "imageSource": "https://replicate.delivery/pbxt/MIKcf8vo7vTEZeBqHcepMZjXtg7TTtwaslC8RSigXjbn5zpq/testimg1.jpg",
    "outputWidth": 864,
    "outputHeight": 480,
    "guidanceScale": 3,
    "negativePrompt": "low quality, worst quality, inconsistent motion, blurry, jittery, distorted",
    "numberOfFrames": 97,
    "outputFramesPerSecond": 24,
    "numberOfInferenceSteps": 50
}

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 payload variable is structured according to the input schema outlined above. This example illustrates how to send a request to generate an animated video from the provided image and prompt.

Conclusion

The georgedavila/ltx-img2vid Cognitive Actions enable developers to easily create animated videos from images, perfect for enhancing user engagement in applications. By understanding the action's parameters and correctly structuring the input, you can unlock the potential of dynamic content creation. Consider exploring various prompts and images to see the breadth of creative possibilities this action provides!