Skip to main content

Setup

To get started, we need an API key that can be obtained by creating an account at https://app.askvideos.com. Once that is done, the API can be accessed via:
  1. REST API
  2. Python client
For this tutorial, we will use the python client.
import askvideos as av
import requests

API_KEY = 'YOUR_API_KEY'
client = av.Client(API_KEY)
Follow these steps to get an API key: API keys

Creating an index

First, we will create an index to add videos to.
index_name = "test_index_add_videos"
client.create_index(index_name)

Adding videos from a file

# Path to video on local filesystem.
video_file = '/path/to/video_file.mp4'

# Optionally add transcripts in .vtt format.
transcript_path = '/path/to/transcript.vtt'

# Add metadata for this video.
metadata = {
    'title': 'Example video',
    'description': 'This is an example video',
    'info': {
        # Add any other info here. 
    }
}

client.index_video(index_name,
                    video_file=video_file,
                    transcript_path=transcript_path,
                    metadata=metadata)

Adding videos from a URL

# Path to video on local filesystem.
video_url = 'https://link.to/video.mp4'

# Add metadata for this video.
metadata = {
    'title': 'Example video',
    'description': 'This is an example video',
    'info': {
        # Add any other info here. 
    }
}

client.index_video(index_name,
                    video_url=video_url,
                    metadata=metadata)

Adding videos from YouTube

AskVideos provides convenience functions to index videos from YouTube. Please comply with your local laws for use of video content.
# Find videos of 'dogs'.
search_term = 'dogs'

# Only use top 10 search results
max_videos = 10

# Only index videos shorter than 10 mins.
max_duration = 600 

client.index_from_youtube_search(index_name,
                    search_term,
                    max_videos=max_videos,
                    max_duration=max_duration)
# Index this video from URL.
video_url = 'https://www.youtube.com/watch?v=video_id'

# Only use top 10 search results
max_videos = 10

# Only index videos shorter than 10 mins.
max_duration = 600 

client.index_from_youtube_url(index_name,
                    video_url,
                    max_videos=max_videos,
                    max_duration=max_duration)
# Index videos from this playlist.
playlist_url = 'https://www.youtube.com/playlist?list=playlist_url'

# Only use top 10 search results
max_videos = 10

# Only index videos shorter than 10 mins.
max_duration = 600 

client.index_from_youtube_playlist(index_name,
                    playlist_url,
                    max_videos=max_videos,
                    max_duration=max_duration)
# Index videos from this channel.
channel_url = 'https://www.youtube.com/channel/channel_id'

# Only use top 10 search results
max_videos = 10

# Only index videos shorter than 10 mins.
max_duration = 600 

client.index_from_youtube_channel(index_name,
                    channel_url,
                    max_videos=max_videos,
                    max_duration=max_duration)

Next steps

Now that the index contains a few videos, we can do some cool things with the index.

Search for moments

Search for specific moments in the video index.

Generate answers

Ask questions and generate answers from video content.