Setup
Create an API key
First create an API key using the instructions in API keys
Install the client
Next install the AskVideos client if using Python. Or consult the REST API reference for other frameworks.
Create an index
Next, create an index. For this tutorial, we will use an index with the name ‘test_index’
Add some videos
Next, add some videos to the index. Now we are ready to get started with searching!
Search using text
index_name = 'test_index'
query = 'dogs running around'
top_k = 30 # Number of results to return.
results = client.search_videos(
index_name,
query,
top_k=top_k)
The returned results look like this:
{
"6689571-hd_1280_720_25fps": [
{
"score": 0.09953739908006456,
"start_seconds": 0,
"end_seconds": 18
}
],
"855386-hd_1280_720_25fps": [
{
"score": 0.10187351703643799,
"start_seconds": 0,
"end_seconds": 2
},
{
"score": 0.08336693048477173,
"start_seconds": 2,
"end_seconds": 6
},
{
"score": 0.10038037598133087,
"start_seconds": 6,
"end_seconds": 10
}
]
...
}
Where the results are a dictionary of lists where the key of the dictionary is the video_id
and the list items are segments of the video that are in the top_k
results.
Each segment contains a score representing how close of a match the segment is to the query and the start and end timestamps within the video.
Search using an image
index_name = 'test_index'
image_path = '/path/to/image.jpg'
top_k = 30 # Number of results to return.
results = client.search_by_image(
image_path,
query,
top_k=top_k)
Search using a video
index_name = 'test_index'
video_path = '/path/to/video.mp4'
top_k = 30 # Number of results to return.
results = client.search_by_video(
index_name,
video_path,
top_k=top_k)
Next steps
In addition to finding moments, AskVideos can also answer questions based on the videos in the index.