Seamlessly Combine Video Files with the bfirsh/concatenate-videos Cognitive Actions

In today's digital landscape, video content is essential for engaging users and conveying information effectively. The bfirsh/concatenate-videos Cognitive Actions provide developers with powerful capabilities to manipulate video files effortlessly. In this blog post, we will explore how to use these actions, specifically focusing on stitching multiple video files together into a single cohesive piece.
Prerequisites
Before diving into the Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform.
- Familiarity with making API requests, particularly in JSON format.
When integrating these actions, you will typically pass your API key in the request headers for authentication purposes.
Cognitive Actions Overview
Stitch Videos Together
The Stitch Videos Together action allows you to combine multiple video files into a single video by stitching them together. This operation is particularly useful for creating compilations or merging clips from different sources.
Input
The input for this action requires the following schema:
- videos (array): An array of URI strings that point to the video resources you want to combine. This field is mandatory.
Here’s an example of the JSON payload required to invoke this action:
{
"videos": [
"https://replicate.delivery/pbxt/MglaHBsUv4UO9BKoNIGjouYDVb9gIl7Nda5IHX6A1AL27OHF/output.0.mp4",
"https://replicate.delivery/pbxt/MglaHUlSnU1j3py0oIlrQTiectZ0BV0XCpJNuy0VGY2m9r78/output.1.mp4",
"https://replicate.delivery/pbxt/MglaHLWwSR9IclZ5fLvpOn7PIpj3D0u0Q5k1CJ6gQaKHHR7p/output.2.mp4",
"https://replicate.delivery/pbxt/MglaH9OuLAEG7jh6ehGIqtMl8i5ewGLDkrYIR44Lrabl1NGT/output.3.mp4"
]
}
Output
Upon successful execution, the action returns a URI pointing to the newly created video file. Here’s an example of what that output might look like:
https://assets.cognitiveactions.com/invocations/a2b05a9d-ffc9-4fd5-96e0-6ccce43ad786/212edd92-31b2-4fbf-af35-7f19c92b114d.mp4
Conceptual Usage Example (Python)
To illustrate how you might call the Stitch Videos Together action using Python, consider the following code snippet:
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 = "742db4e1-e809-47a1-bdc7-62a92906ed4f" # Action ID for Stitch Videos Together
# Construct the input payload based on the action's requirements
payload = {
"videos": [
"https://replicate.delivery/pbxt/MglaHBsUv4UO9BKoNIGjouYDVb9gIl7Nda5IHX6A1AL27OHF/output.0.mp4",
"https://replicate.delivery/pbxt/MglaHUlSnU1j3py0oIlrQTiectZ0BV0XCpJNuy0VGY2m9r78/output.1.mp4",
"https://replicate.delivery/pbxt/MglaHLWwSR9IclZ5fLvpOn7PIpj3D0u0Q5k1CJ6gQaKHHR7p/output.2.mp4",
"https://replicate.delivery/pbxt/MglaH9OuLAEG7jh6ehGIqtMl8i5ewGLDkrYIR44Lrabl1NGT/output.3.mp4"
]
}
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 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. Note that the endpoint URL is purely illustrative and should be replaced with the actual execution URL for the Cognitive Actions.
Conclusion
The bfirsh/concatenate-videos Cognitive Actions empower developers to effortlessly stitch together multiple video files into a single output. By leveraging the straightforward API and the provided Python examples, you can easily integrate this functionality into your applications, whether for video editing, content creation, or compiling user-generated content. Explore these actions further and consider how they might enhance your video processing workflows!