Transform Your Videos with Background Change Using Video Utils

26 Apr 2025
Transform Your Videos with Background Change Using Video Utils

In today's digital landscape, video content is king. Whether you're creating marketing materials, social media posts, or educational content, the ability to modify your video backgrounds can elevate your projects significantly. The "Video Utils" service provides powerful Cognitive Actions that simplify video processing tasks, enabling developers to enhance their video content effortlessly. One key feature is the ability to convert video backgrounds, offering flexibility in how your videos are presented.

Imagine needing to create engaging video content quickly. With the background conversion feature, you can easily change the background to a blurred effect for a professional look or a simple black background for a more minimalist approach. This capability is particularly useful for businesses looking to maintain brand consistency or for content creators aiming to focus viewer attention on the subject of the video.

Prerequisites

To get started with Video Utils, you'll need a Cognitive Actions API key and a basic understanding of making API calls.

Convert Video Background

The "Convert Video Background" action allows users to change the background of a video to either a blurred or black type. This operation is designed to simplify the background alteration process, providing a default setting for a black background, while also allowing for a blurred background option.

Input Requirements

To utilize this action, you need to provide a valid URL for the input video. Additionally, you can specify the type of background you want, either "blur" for a blurred effect or "black" for a solid black background. The default option is set to "black".

  • Input Example:
    {
      "video": "https://replicate.delivery/pbxt/Lb84At9D6TdQi7rjnUiTrZelkQqGKq9Nbpf6nyse3fkJWKuD/input.mp4",
      "videoType": "black"
    }
    

Expected Output

Upon successful processing, the output will be a URL link to the modified video with the chosen background.

  • Output Example:
    https://assets.cognitiveactions.com/invocations/b9d32649-84cd-4ac5-a2e1-e5f4dc22c3b8/d810339d-3cd0-404c-b386-f0bb96868d42.mp4
    

Use Cases for this Action

  • Marketing Videos: Create impactful advertisements by changing the background to match your brand colors or themes.
  • Educational Content: Focus learner attention on the instructor or content by using a blurred background that minimizes distractions.
  • Social Media Posts: Quickly adapt video backgrounds for various platforms, ensuring your content stands out in feeds.
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 = "3bc10dcf-340b-43c9-8591-98aec2fd17be" # Action ID for: Convert Video Background

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "video": "https://replicate.delivery/pbxt/Lb84At9D6TdQi7rjnUiTrZelkQqGKq9Nbpf6nyse3fkJWKuD/input.mp4",
  "videoType": "black"
}

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 ability to change video backgrounds with Video Utils not only enhances the visual appeal of your content but also saves time and effort in video editing. Whether you’re a developer building applications that require video processing or a content creator looking to improve your video quality, this action opens up a world of possibilities. Start integrating the Convert Video Background action into your projects today and elevate your video content to new heights!