Transform Images and Audio into Engaging Videos with hexiaochun/img2video Cognitive Actions

In today's digital landscape, the ability to create engaging video content is essential for developers and content creators alike. The hexiaochun/img2video Cognitive Actions provide a powerful solution for generating videos from static images and audio files. By utilizing pre-built actions, developers can streamline the video creation process, saving time and resources while delivering captivating multimedia experiences.
Prerequisites
To get started with the Cognitive Actions, you will need to have an API key for the Cognitive Actions platform. Authentication typically involves passing this key in the headers of your API requests. Ensure you have the necessary permissions and access to use the actions effectively.
Cognitive Actions Overview
Create Keyframe Video from Image and Audio
The Create Keyframe Video from Image and Audio action generates a video by merging an input image and audio. It utilizes keyframe animations based on specified motion directions, allowing for dynamic visual storytelling.
- Category: Video Generation
Input
The input schema for this action requires the following fields:
- audio (required): A URI pointing to an input audio file in MP3 format.
- image (required): A URI pointing to an input image file in PNG format.
- videoDirection (optional): The direction of keyframe motion in the video. Options include:
left_rightright_lefttop_downdown_topupscaledownscale
The default value isleft_right.
Example Input:
{
"audio": "https://lf-bot-studio-plugin-resource.coze.cn/obj/bot-studio-platform-plugin-tos/sami/tts/3b1224641f2844a2baee0ea90e0f4311.mp3",
"image": "https://replicate.delivery/pbxt/Lb9isXusB16LpfAF3YAMtYP7sTKQNZyrsIaSDZUeuHBF9WPT/image.png",
"videoDirection": "left_right"
}
Output
Upon successful execution, this action returns a URI link to the generated video in MP4 format.
Example Output:
https://assets.cognitiveactions.com/invocations/9f3f231a-90ab-41f6-9087-e0091bcc7938/1e8426e3-c348-461a-a5c0-599351c41273.mp4
Conceptual Usage Example (Python)
Here's a conceptual example of how to call the Create Keyframe Video from Image and Audio action using Python. This snippet demonstrates how to structure your input JSON payload correctly.
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 = "a7b8b38e-b823-48ab-a536-f90ae5bb084b" # Action ID for Create Keyframe Video from Image and Audio
# Construct the input payload based on the action's requirements
payload = {
"audio": "https://lf-bot-studio-plugin-resource.coze.cn/obj/bot-studio-platform-plugin-tos/sami/tts/3b1224641f2844a2baee0ea90e0f4311.mp3",
"image": "https://replicate.delivery/pbxt/Lb9isXusB16LpfAF3YAMtYP7sTKQNZyrsIaSDZUeuHBF9WPT/image.png",
"videoDirection": "left_right"
}
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'll need to replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID and input payload are structured according to the requirements outlined above. The endpoint URL and request structure are illustrative, so ensure you adapt them according to the actual API documentation.
Conclusion
The hexiaochun/img2video Cognitive Actions provide a robust solution for developers looking to integrate video generation capabilities into their applications. By leveraging these actions, you can create engaging content that combines images and audio seamlessly. Explore various use cases, from educational videos to marketing materials, and unlock the potential of multimedia storytelling in your projects. Happy coding!