Create Stunning Videos from Images and Audio with lucataco/img-and-audio2video Cognitive Actions

22 Apr 2025
Create Stunning Videos from Images and Audio with lucataco/img-and-audio2video Cognitive Actions

In the realm of multimedia content creation, the capability to seamlessly combine visual and audio elements can transform the storytelling experience. The lucataco/img-and-audio2video Cognitive Actions empower developers to easily generate engaging video clips from still images and audio files. This capability not only enhances user engagement but also streamlines the content creation process, allowing for quick and effective multimedia presentations.

Prerequisites

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

  • An API key for accessing the Cognitive Actions platform.
  • Basic knowledge of making HTTP requests and handling JSON data.
  • A working development environment with Python and the requests library installed.

Authentication typically involves passing your API key in the request headers, allowing you to securely access and execute the Cognitive Actions.

Cognitive Actions Overview

Create Video from Image and Audio

Description: This action allows you to create a video clip by combining a still grayscale image with an audio file. The duration of the resulting video will match the length of the audio file, utilizing the moviepy library for processing.

  • Category: Video Generation

Input

The input for this action requires a JSON object that includes the following fields:

  • audioFile: A string representing the URL of the audio file in MP3 format. This is a required input.
  • grayscaleImage: A string representing the URL of the grayscale image file in PNG format. This is also a required input.

Example Input:

{
  "audioFile": "https://replicate.delivery/pbxt/KIpZhWai4JINPqvvSVvaiHoRv343DDcQ92fjhW3RuxdPMBDY/paragraph1.mp3",
  "grayscaleImage": "https://replicate.delivery/pbxt/KIpZgwRxVGyZzhP04jWuNa89Buabz93MPVzLACtm7uvIOGpH/replicate-prediction-rlbxrodbhskvpbtmsnsugr4nwm.png"
}

Output

Upon successful execution, the action returns a URL pointing to the generated video file. This video will contain the provided audio and the still image as its visual content.

Example Output:

https://assets.cognitiveactions.com/invocations/3f7a5093-0710-4775-ab58-936d9759e787/2e00f825-0d35-4350-9038-ede64c7aea84.mp4

Conceptual Usage Example (Python)

Here’s a conceptual example of how you might call this 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 = "c9a41127-8bd8-4e6f-b5b5-652520a6714b"  # Action ID for Create Video from Image and Audio

# Construct the input payload based on the action's requirements
payload = {
    "audioFile": "https://replicate.delivery/pbxt/KIpZhWai4JINPqvvSVvaiHoRv343DDcQ92fjhW3RuxdPMBDY/paragraph1.mp3",
    "grayscaleImage": "https://replicate.delivery/pbxt/KIpZgwRxVGyZzhP04jWuNa89Buabz93MPVzLACtm7uvIOGpH/replicate-prediction-rlbxrodbhskvpbtmsnsugr4nwm.png"
}

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, you will replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID and input payload are structured based on the requirements detailed above.

Conclusion

The lucataco/img-and-audio2video Cognitive Actions simplify the process of video generation by allowing developers to combine images and audio effortlessly. By integrating these actions into your applications, you can enhance user experiences and create dynamic multimedia content quickly. Consider exploring additional use cases such as automated video presentations or creative storytelling projects using these powerful tools!