Streamline Video Processing with the FOFR Toolkit Cognitive Actions

In today's digital landscape, video content is king, and processing it efficiently can save time and enhance user experience. The FOFR Toolkit offers a powerful set of Cognitive Actions specifically designed for video processing tasks. With these pre-built actions, developers can easily integrate video conversion, audio extraction, and frame manipulation into their applications, streamlining workflows and reducing development time.
Prerequisites
Before diving into the Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform. This will be necessary for authentication when making requests.
- Familiarity with making HTTP requests and handling JSON data in your preferred programming language.
Authentication typically involves passing the API key in the request headers, allowing secure access to the Cognitive Actions.
Cognitive Actions Overview
Execute Video Toolkit Tasks
The Execute Video Toolkit Tasks action allows you to perform a variety of video processing tasks such as converting videos to MP4 or GIF format, extracting audio as MP3, and creating videos or GIFs from image frames using a CPU-based ffmpeg model. This action falls under the video-processing category.
Input
To invoke this action, you need to structure your input according to the following schema:
- inputFile: (string, required) A URI pointing to the file to be processed. Supported formats include zip, image, or video files.
- taskToPerform: (string, required) Specifies the task to be performed on the provided input file. Choose from tasks like converting input to MP4 or GIF, extracting audio, etc.
- framesPerSecond: (integer, optional) The frame rate for video processing when applicable. Use 0 to maintain the original frame rate or apply a default.
Here’s an example of a JSON payload for this action:
{
"inputFile": "https://replicate.delivery/pbxt/K4PoZN3Q6JIiG61inQLKTxIYVpOVoAYCfxwQksNGTfnmGLUf/video%20%282%29.mp4",
"taskToPerform": "convert_input_to_gif",
"framesPerSecond": 0
}
Output
The action typically returns a URL pointing to the processed file. For example:
[
"https://assets.cognitiveactions.com/invocations/8fa90858-360b-487c-8e50-cbc5af695825/a76fe074-d3f9-426d-888b-14599de71c95.gif"
]
This URL will lead you to the newly created GIF from the input video.
Conceptual Usage Example (Python)
Here’s how you might call the Execute Video Toolkit Tasks action using Python. This conceptual example demonstrates how to structure the input payload and make the request:
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 = "3318aa6e-0200-448c-9398-75299b3d0a34" # Action ID for Execute Video Toolkit Tasks
# Construct the input payload based on the action's requirements
payload = {
"inputFile": "https://replicate.delivery/pbxt/K4PoZN3Q6JIiG61inQLKTxIYVpOVoAYCfxwQksNGTfnmGLUf/video%20%282%29.mp4",
"taskToPerform": "convert_input_to_gif",
"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 code snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload variable contains the structured input necessary for the action, and the request is sent to the hypothetical endpoint.
Conclusion
The FOFR Toolkit's Cognitive Actions provide developers with powerful capabilities to streamline video processing tasks. By utilizing these pre-built actions, you can enhance your applications with features like video conversion and audio extraction without extensive development overhead. Explore the possibilities and consider integrating these actions into your workflows to improve efficiency and user experience. Happy coding!