Transform Your Videos Effortlessly with the fofr/video-morpher Cognitive Actions

22 Apr 2025
Transform Your Videos Effortlessly with the fofr/video-morpher Cognitive Actions

In the ever-evolving world of digital content creation, video morphing has gained significant traction as a captivating way to engage audiences. The fofr/video-morpher API provides developers with a powerful toolset to generate stunning morphing videos between different subject images. By leveraging the pre-built Cognitive Actions, you can create videos that combine visual creativity with style customization, all while simplifying the integration process into your applications.

Prerequisites

Before you dive into using the Cognitive Actions, ensure you have:

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Basic familiarity with JSON and RESTful API concepts.

To authenticate, you will typically pass your API key in the request headers, allowing you to securely access the Cognitive Actions functionalities.

Cognitive Actions Overview

Generate Video Morph with Style

Description: This action allows you to generate a video that smoothly morphs between multiple subject images while applying a specified style. The outcome can be tailored in terms of resolution and duration, with options for style intensity, aspect ratio, and checkpoint selection.

Category: Video Generation

Input

The Generate Video Morph with Style action requires a JSON object structured according to the following schema:

  • PrimarySubjectImage (string, required): URI to the primary image driving the video content.
  • SecondarySubjectImage (string, required): URI to the secondary image functioning alongside the primary image.
  • TertiarySubjectImage (string, required): URI to the tertiary image that complements the primary and secondary images.
  • QuaternarySubjectImage (string, required): URI to the quaternary image providing additional context.
  • Mode (string, optional): Specifies the quality and length of the video (default is "medium").
  • Prompt (string, optional): A textual prompt influencing the video's style.
  • ModelType (string, optional): Type of model used for video generation (default is "realistic").
  • StyleSourceImage (string, optional): URI to an image whose style will be applied throughout the video.
  • VideoAspectRatio (string, optional): The aspect ratio of the video (default is "2:3").
  • ExcludeElementsPrompt (string, optional): A textual prompt specifying elements to avoid.
  • EnableGeometricGuidance (boolean, optional): Flag to enable or disable geometric guidance (default is true).
  • StyleApplicationStrength (number, optional): Intensity of style application from the style source image (default is 1).

Example Input:

{
  "mode": "upscaled-and-interpolated",
  "prompt": "bright, vibrant, high contrast",
  "modelType": "3D",
  "styleSourceImage": "https://replicate.delivery/pbxt/KnxLVfe6BRRu2zHc3gT99mnwaemKfR4JzaZWxMCLsZYSTKzp/2024-03-05--06-47-29-u-q1-fofr_tropical_purple_beksinski_aaad09f0-d194-4e40-b312-51054fc4ebbf.png",
  "videoAspectRatio": "3:4",
  "primarySubjectImage": "https://replicate.delivery/pbxt/KnxLX9qnA82YKCkScCJZf5VCX6hy5RuprGwLEAVjp3vu6Oh1/1.webp",
  "tertiarySubjectImage": "https://replicate.delivery/pbxt/KnxLWU6aHjc6kVW2QOF0xC4oen8zuPnlsK2o24GtOV2bJEn8/4.webp",
  "excludeElementsPrompt": "dark, gloomy",
  "secondarySubjectImage": "https://replicate.delivery/pbxt/KnxLWqPg086DnRTUvxDM7gCBYi3W3coIbn3Q8jXnTJsfvZzt/2.webp",
  "quaternarySubjectImage": "https://replicate.delivery/pbxt/KnxLVg54ySFfg8s78YyfzK0Qgse8YdTbSmEZKpnkFkmSFlsf/4.webp",
  "enableGeometricGuidance": true,
  "styleApplicationStrength": 0.5
}

Output

The action will return a list of video URLs of the generated morphing content. Each URL leads to a distinct video file that showcases the morphing effects applied.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/73931d8b-f37f-46da-b53c-c52c6cfdc1ed/517f787d-40d0-4223-8a61-a62950030ab3.mp4",
  "https://assets.cognitiveactions.com/invocations/73931d8b-f37f-46da-b53c-c52c6cfdc1ed/59342ab9-c552-4f02-8f5b-52bd02a13f99.mp4",
  "https://assets.cognitiveactions.com/invocations/73931d8b-f37f-46da-b53c-c52c6cfdc1ed/c4b6b4a0-55aa-4e80-a96a-3ff1f4072469.mp4",
  "https://assets.cognitiveactions.com/invocations/73931d8b-f37f-46da-b53c-c52c6cfdc1ed/272a9006-65b9-4be5-9173-ffd80a501d3a.mp4"
]

Conceptual Usage Example (Python)

Here is how you might call the Generate Video Morph with Style 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 = "3fbb26a8-b50f-45dd-bfce-b6af8a643b80"  # Action ID for Generate Video Morph with Style

# Construct the input payload based on the action's requirements
payload = {
    "mode": "upscaled-and-interpolated",
    "prompt": "bright, vibrant, high contrast",
    "modelType": "3D",
    "styleSourceImage": "https://replicate.delivery/pbxt/KnxLVfe6BRRu2zHc3gT99mnwaemKfR4JzaZWxMCLsZYSTKzp/2024-03-05--06-47-29-u-q1-fofr_tropical_purple_beksinski_aaad09f0-d194-4e40-b312-51054fc4ebbf.png",
    "videoAspectRatio": "3:4",
    "primarySubjectImage": "https://replicate.delivery/pbxt/KnxLX9qnA82YKCkScCJZf5VCX6hy5RuprGwLEAVjp3vu6Oh1/1.webp",
    "tertiarySubjectImage": "https://replicate.delivery/pbxt/KnxLWU6aHjc6kVW2QOF0xC4oen8zuPnlsK2o24GtOV2bJEn8/4.webp",
    "excludeElementsPrompt": "dark, gloomy",
    "secondarySubjectImage": "https://replicate.delivery/pbxt/KnxLWqPg086DnRTUvxDM7gCBYi3W3coIbn3Q8jXnTJsfvZzt/2.webp",
    "quaternarySubjectImage": "https://replicate.delivery/pbxt/KnxLVg54ySFfg8s78YyfzK0Qgse8YdTbSmEZKpnkFkmSFlsf/4.webp",
    "enableGeometricGuidance": True,
    "styleApplicationStrength": 0.5
}

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 replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key and utilize the specified action ID. The JSON payload is constructed according to the defined schema, and the response is handled to retrieve and display the generated video URLs.

Conclusion

The fofr/video-morpher Cognitive Actions provide a robust solution for developers looking to enhance their applications with dynamic video morphing capabilities. By following the guidelines outlined in this post, you can effortlessly integrate these actions into your projects, opening up a world of creative possibilities. Whether you're creating engaging social media content or innovative visual storytelling experiences, the video morphing capabilities of this API can significantly elevate your multimedia projects. Happy coding!