Create Stunning Black and White Dotted Videos with lucataco/dotted-video Cognitive Actions

The lucataco/dotted-video API offers a powerful Cognitive Action that allows developers to transform regular videos into striking black and white dotted versions. This effect, which can be customized in terms of dot size and pixel intensity, brings a unique aesthetic to video content, making it ideal for creative projects, presentations, or artistic explorations. In this article, we will explore the "Apply Dotted Video Effect" action, its inputs and outputs, and how to integrate it seamlessly into your applications.
Prerequisites
Before you can start using the Cognitive Actions, you will need to set up an account to obtain your API key. This key is essential as it authenticates your requests to the Cognitive Actions platform. You will typically include your API key in the request headers when making calls to the API.
Cognitive Actions Overview
Apply Dotted Video Effect
The Apply Dotted Video Effect action transforms a video into a black and white dotted version. It allows for customization of dot size, inverse effects, and pixel intensity thresholds, enabling you to fine-tune the aesthetics of the output video.
Input
The input for this action requires a JSON object with the following fields:
- video (required): A valid URI pointing to the input video file.
- dotSize (optional): An integer specifying the size of the dots in pixels (default is 4, valid range is 4 to 50).
- inverse (optional): A boolean indicating if the effect should create black dots on a white background (default is false).
- threshold (optional): An integer for the pixel intensity threshold (default is 128, valid range is 0 to 255).
- inverseThreshold (optional): A boolean that determines the light setting where dots appear (default is false).
Example Input:
{
"video": "https://replicate.delivery/pbxt/MTamh4TnpSDNhaYQgXVHuemLCjboaeajxWtX4hjMyNMFy02h/jelly.mp4",
"dotSize": 4,
"inverse": false,
"threshold": 128,
"inverseThreshold": false
}
Output
Upon successful execution, this action returns a URL to the processed video that features the dotted effect.
Example Output:
https://assets.cognitiveactions.com/invocations/ef99777a-8610-48e3-b477-c25176ff8031/9ca2bb24-d0bb-4d5f-865e-1788a7f1340f.mp4
Conceptual Usage Example (Python)
Here’s how you might implement a call to the Apply Dotted Video Effect action using Python. This example shows how to structure your request, focusing on the input JSON payload construction.
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 = "e7d7e96a-d77b-469c-9826-6b0ff2c60226" # Action ID for Apply Dotted Video Effect
# Construct the input payload based on the action's requirements
payload = {
"video": "https://replicate.delivery/pbxt/MTamh4TnpSDNhaYQgXVHuemLCjboaeajxWtX4hjMyNMFy02h/jelly.mp4",
"dotSize": 4,
"inverse": false,
"threshold": 128,
"inverseThreshold": false
}
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 Python snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload variable is constructed according to the action's requirements, and the request is sent to the hypothetical endpoint.
Conclusion
Integrating the Apply Dotted Video Effect action into your applications can enhance your video content by adding a visually appealing transformation. With customizable options for dot size, inverse effects, and pixel intensity thresholds, you have the flexibility to achieve the desired aesthetic. Start experimenting with this Cognitive Action today, and explore the artistic possibilities it unlocks!