Seamlessly Merge Video Snippets with lucataco/video-merge Cognitive Actions

23 Apr 2025
Seamlessly Merge Video Snippets with lucataco/video-merge Cognitive Actions

In today's digital landscape, video content is more prevalent than ever. Whether you are creating promotional materials, vlogs, or educational content, the ability to manipulate video files efficiently is essential. The lucataco/video-merge API provides developers with a powerful toolset to merge multiple video snippets into a single cohesive output. With pre-built Cognitive Actions, you can easily integrate advanced video processing capabilities into your applications without extensive overhead.

Prerequisites

Before diving into the integration, ensure you have the following:

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Familiarity with JSON structure, as you'll be sending and receiving data in this format.

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

Cognitive Actions Overview

Merge Video Snippets

The Merge Video Snippets action is designed to allow users to concatenate multiple video files into one. You can specify various parameters such as output dimensions, audio retention, and frames per second, making it a versatile tool for video processing.

Input

To successfully execute the Merge Video Snippets action, you need to provide the following input parameters:

  • videoFiles (required): An array of URIs pointing to the video files you want to merge.
  • width (optional): Specifies the width of the output video in pixels. Defaults to the width of the first video if not specified.
  • height (optional): Specifies the height of the output video in pixels. Defaults to the height of the first video if not specified.
  • keepAudio (optional): A boolean that indicates whether to retain audio in the output video. Defaults to true.
  • framesPerSecond (optional): Sets the frame rate of the output video. Defaults to the frame rate of the first video if not specified.

Example Input:

{
  "width": 0,
  "height": 0,
  "keepAudio": true,
  "videoFiles": [
    "https://replicate.delivery/pbxt/MJTeIs25n8qaOVWQdlCmXZtf7UDO3DCIsl6QKReMHvSj45hB/liberty-day.mp4",
    "https://replicate.delivery/pbxt/MJTeIinBMvBBUF4xu9ndmsEzfoALtSW8OxoSnsBqThnBAd6b/liberty-night.mp4"
  ],
  "framesPerSecond": 0
}

Output

The action returns a URI pointing to the merged video file. This allows you to easily access and utilize the newly created video in your application.

Example Output:

https://assets.cognitiveactions.com/invocations/8648d3ca-1f6e-4abb-a556-4f3b0e0c139f/91074ba4-f279-4c1d-8e69-0795a9749fe9.mp4

Conceptual Usage Example (Python)

Here’s how you can integrate the Merge Video Snippets action into your application 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 = "f3643a08-7164-4177-b195-04f6a1d64fb0" # Action ID for Merge Video Snippets

# Construct the input payload based on the action's requirements
payload = {
    "width": 0,
    "height": 0,
    "keepAudio": true,
    "videoFiles": [
        "https://replicate.delivery/pbxt/MJTeIs25n8qaOVWQdlCmXZtf7UDO3DCIsl6QKReMHvSj45hB/liberty-day.mp4",
        "https://replicate.delivery/pbxt/MJTeIinBMvBBUF4xu9ndmsEzfoALtSW8OxoSnsBqThnBAd6b/liberty-night.mp4"
    ],
    "framesPerSecond": 0
}

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 example, you'd replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action_id is set to the ID of the Merge Video Snippets action, and the payload is constructed according to the specified input schema.

Conclusion

The lucataco/video-merge Cognitive Action simplifies the process of merging video snippets, making it an invaluable tool for developers looking to enhance their applications with video processing capabilities. By leveraging these actions, you can save time and resources, allowing you to focus on creating innovative features for your users. Explore potential use cases such as compiling highlight reels, creating tutorials, or generating promotional content with ease!