Seamlessly Combine Multiple Videos with Video Merge Actions

26 Apr 2025
Seamlessly Combine Multiple Videos with Video Merge Actions

In the era of content creation, video has become a dominant medium for communication, storytelling, and marketing. The "Video Merge" service offers a powerful set of Cognitive Actions that allow developers to combine multiple video files into a single cohesive piece. This capability not only simplifies the video editing process but also enhances the efficiency of content production workflows. With the ability to merge videos effortlessly, developers can cater to a wide range of use cases, from creating promotional materials to compiling user-generated content.

Imagine a scenario where you need to create a highlight reel from various video clips or compile a series of tutorial videos into one comprehensive guide. The Video Merge service addresses these needs, enabling you to streamline your video production efforts and deliver polished final products faster than ever before.

Prerequisites

To get started with the Video Merge service, you'll need a Cognitive Actions API key and a basic understanding of how to make API calls.

Merge Videos

The "Merge Videos" action is designed to combine several video files into a single video file using a collection of provided video URIs. This action is particularly useful for developers looking to create seamless video experiences without the need for complex editing software.

Input Requirements

The input for this action requires a structured object that includes an array of video URIs. Each video must be specified as a valid URI to ensure successful merging.

Example Input:

{
  "videos": [
    "https://replicate.delivery/pbxt/LbBcDCMewRMGZd6mEYJzUjhyEiyd3xJTLMi17aZOWWgcXI7k/5dfacc1a-b483-4328-9948-25ae150b7d23.mp4",
    "https://replicate.delivery/pbxt/LbBcDbYjtTc4JcVZgDfmhjXGk0TgL5wrAHf5QXIi5P4OrJLP/5ed39370-0012-4efc-8221-cf13d94b0581.mp4"
  ]
}

Expected Output

Upon successful execution, the output will be a single video file URI that combines all the input videos into one seamless video.

Example Output:

https://assets.cognitiveactions.com/invocations/f20c6182-0538-406d-bb48-288a8d05e628/f134ca18-1126-4584-9bb4-ef26ef0eae5c.mp4

Use Cases for this Specific Action

  • Content Creation: Ideal for video editors and content creators who need to compile multiple clips into a single presentation.
  • Event Recaps: Perfect for businesses or organizations looking to create recap videos from various event footage.
  • Tutorials and Demonstrations: Combine several instructional videos into one comprehensive tutorial for easier viewer consumption.
  • User-Generated Content: Aggregate user submissions or testimonials into a single video for promotional purposes.
import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "2433494c-eefc-453f-884b-5f3fb1b48506" # Action ID for: Merge Videos

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "videos": [
    "https://replicate.delivery/pbxt/LbBcDCMewRMGZd6mEYJzUjhyEiyd3xJTLMi17aZOWWgcXI7k/5dfacc1a-b483-4328-9948-25ae150b7d23.mp4",
    "https://replicate.delivery/pbxt/LbBcDbYjtTc4JcVZgDfmhjXGk0TgL5wrAHf5QXIi5P4OrJLP/5ed39370-0012-4efc-8221-cf13d94b0581.mp4"
  ]
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    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 (non-JSON): {e.response.text}")
    print("------------------------------------------------")

Conclusion

The Video Merge service offers developers a straightforward and efficient way to combine multiple videos into a single file, streamlining the video production process. Whether you’re looking to create promotional content, compile tutorials, or produce event recaps, the "Merge Videos" action can significantly enhance your workflow. Start integrating this service today to elevate your video content creation capabilities and deliver polished, professional results.