Tutorial: Analyze Video
Overview
This tutorial provides a step-by-step guide on how to analyze a video using the Aana API. The analysis process involves creating a background task that processes the video and generates an scene- and video-level summaries of the video.
The analyze endpoint is intended for users who prefer to manage their video archives manually.
For a complete search experience, including advanced indexing and retrieval features, please use the POST /index endpoint. Refer to the Index & Search Tutorial for detailed guidance.
The analysis process is asynchronous, meaning that once you submit a video for analysis, the API will return a task ID. You can use this ID to check the status of the analysis or retrieve the results once they are ready. If you want to be notified when the analysis is complete, consider setting up a webhook.
Step 1: Create Analyze Task
To analyze a video, send a request to POST /analyze. This endpoint transforms videos into summaries, allowing you to understand the content of the video.
import json, requests
payload = {'video': {'media_id': '12345',
'url': 'https://example.com/video_12345.mp4'}}
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"x-api-key": "YOUR_API_KEY_HERE"
}
response = requests.post("https://v1.api.aana.ai/analyze",
headers=headers,
data={"body": json.dumps(payload)}
)
data = response.json()
print(data)
The response will contain a task_id
that you can use to check the status of the indexing process.
{"task_id": "175e1c97-1e18-4afe-906b-9e4897450c6e"}
Step 2: Retrieve Task Status
When you call POST /analyze, a new task is created and runs asynchronously. To check the status of this task:
- Use the GET /tasks/{task_id} endpoint if you have the task ID.
- Use webhooks to get notified when the task is completed. See Webhooks for more details.
import requests
task_id = "YOUR_TASK_ID"
url = f"https://v1.api.aana.ai/tasks/{task_id}"
headers = {"x-api-key": "YOUR_API_KEY_HERE"}
response = requests.get(url, headers=headers)
print(response.json())
Example response:
{
"id": "175e1c97-1e18-4afe-906b-9e4897450c6e",
"endpoint": "/analyze",
"data": {"video": {"media_id": "12345", "url": "https://example.com/video_12345.mp4"}},
"status": "running",
"results": null
}
If the task is running
, you can wait or poll until it is completed
or failed
.
Once the task is completed, the results will be available in the results
field of the task object.
The successful response will look like this:
{
"id": "175e1c97-1e18-4afe-906b-9e4897450c6e",
"endpoint": "/analyze",
"data": {
"video": {
"path": null,
"url": "https://example.com/video_12345.mp4",
"content": null,
"media_id": "12345",
"additional_metadata": {}
}
},
"status": "completed",
"result": {
"audio_summary": {
"segment": {
"end": {
"seconds": 2.0
},
"segment_id": 0,
"start": {
"seconds": 0.0
}
},
"text": "..."
},
"episodic_summary": {
"audio": [],
"end": {
"seconds": 70.68
},
"faces": null,
"start": {
"seconds": 66.56
},
"summary": "The video ...",
"thumbnail": "...",
"visual": [
{
"end": 70.68,
"start": 66.56,
"summary": "The video features ...",
}
]
},
"video_duration": 70.68,
"video_summary": "This video highlights ...",
"visual_summary": {
"segment": {
"end": {
"seconds": 70.68
},
"segment_id": 6,
"start": {
"seconds": 66.56
}
},
"text": "The video features ..."
}
}
}