videodb
VideoDB Documentation
videodb
VideoDB Documentation
This notebook is designed to help you get started with VideoDB. Advance concepts are linked in between for deep dive.

Setup

🔧 Installing VideoDB in your environment

VideoDB is available as
!pip install videodb

🔗 Setting Up a connection to db

To connect to VideoDB, simply get the API and create a connection. This can be done by either providing your VideoDB API key directly to the constructor or by setting the VIDEO_DB_API_KEY environment variable with your API key.
light
Get your API key from . ( Free for first 50 uploads, No credit card required ) 🎉
import videodb
conn = videodb.connect(api_key="YOUR_API_KEY")

Working with Single Video

⬆️ Uploading a video

Now that you have established a connection to VideoDB , you can upload your videos using conn.upload()
You can upload your media by a url or from your local file system
upload method returns a Video object.
# Upload a video by url
video = conn.upload(url="https://www.youtube.com/watch?v=WDv4AWk0J3U")

# Upload a video from file system
video_f = conn.upload(file_path="./my_video.mp4")
light
VideoDB simplifies your upload by supporting links from Youtube, S3 or any Public URL with video

Pro Tip

If you wish to upload only the audio from a video file, just specify in the "media_type" field. For instance, you can obtain audio from a YouTube video by doing so.
from videodb import MediaType

audio = conn.upload(url="https://youtu.be/IoDVfXFq5cU?si=BCU7ghvqY3YdCS78", media_type=MediaType.audio)
The types of media that can be uploaded are defined in the MediaType class.

📺 Viewing your video

Your video is instantly available for viewing 720p resolution ⚡️
Generate a streamable url for video using video.generate_stream()
Preview the video using video.play(). This will open the video in your default browser/notebook
video.generate_stream()
video.play()
filled-star
Note: if you are viewing this notebook on github, you won't be able to see iframe player, because of security restrictions. Please open the printed link of player in your browser
Load content from console.videodb.io?
Loading external content may reveal information to 3rd parties. Learn more
Allow

⛓️ Stream Specific Sections of videos

You can easily clip specific sections of a video by passing timeline of start and end sections. It accepts seconds. For example Here’s we are streaming only first 10 seconds and then 120 to 140 second of a video
stream_link = video.generate_stream(timeline=[(0,10), (120,140)])
play_stream(stream_link)

🗂️ Indexing a Video

To search bits inside a video, you have to first index the video. This can be done by a invoking the index function on the video object. VideoDB offers two type of indexes currently.
index_spoken_words: Indexes spoken words in the video. It automatically generate the transcript and makes it ready for search. Checkout to index different language content.
index_scenes: Indexes visual concepts and events of the video. Perfect for building security monitoring, drone, and other camera footage. Refer
Checkout for unlocking multimodal search in your video library.
# best for podcasts, elearning, news, etc.
video.index_spoken_words()
# best for camera feeds, moderation usecases etc.
video.index_scenes(prompt="<your prompt to describe the scenes>")
rocket
Upcoming:
Faces : Upload image of the person and find them in a video.
Specific domain Index like Football, Baseball, Drone footage, Cricket etc.
⏱️ Indexing may take some time for longer videos, structure it as a batch job with callback in your application.

🔍 Search Inside a Video

Search the segments inside a video. While searching you have options to choose the type of search and index. VideoDB offers following types of search :
SearchType.semantic Perfect for question answer kind of queries. This is also the default type of search.
SearchType.keyword It matches the exact occurrence of word or sentence you pass in the query parameter of the search function. keyword search is only available to use with single videos.
IndexType.scene It search the visual information of the video, Index the video using index_scenes function.
IndexType.spoken_word It search the spoken information of the video, Index the video using index_spoken_words function.
from videodb import SearchType
from videodb import IndexType

result = video.search(query = "What are the benefits of morning sunlight?",
search_type = SearchType.semantic,
index_type =IndexType.spoken_word)
result.play()

Viewing Search Results :
video.search() will return a SearchResults object, which contains the sections/shots of videos which semantically match your search query
result.get_shots() - Returns a list of Shot that matched search query
result.play() - Returns a playable url for video (similar to video.play() you can open this link in browser, or embed it into your website using iframe)

RAG: Search Inside Multiple Videos

VideoDB can store and search inside multiple videos with ease. By default, videos are uploaded to your default collection and you have freedom to create and manage more collections, checkout our doc for more details.
If you are an existing llamaIndex user, trying to build RAG pipeline on your video data. You can also use VideoDB retriever. Checkout llama docs ⬇️
🔄 Using Collection to upload multiple Videos
# Get the default collection
coll = conn.get_collection()

# Upload Videos to a collection
coll.upload(url="https://www.youtube.com/watch?v=lsODSDmY4CY")
coll.upload(url="https://www.youtube.com/watch?v=vZ4kOr38JhY")
coll.upload(url="https://www.youtube.com/watch?v=uak_dXHh6s4")

conn.get_collection() : Returns Collection object, the default collection
coll.get_videos() : Returns list of Video, all videos in collections
coll.get_video(video_id): Returns Video, respective video object from given video_id
coll.delete_video(video_id): Deletes the video from Collection

📂 Search inside multiple videos in a collection

You can simply index all the videos in a collection and use search method on collection to find relevant results. Here we are indexing spoken content of a collection and searching
# Index all videos in collection
for video in coll.get_videos():
video.index_spoken_words()

Semantic Search in the collection
# search in the collection of videos
results = coll.search(query = "What is Dopamine?")
results.play()

Let’s try one more search:
results = coll.search(query = "What's the benefit of morning sunlight?")
results.play()
The result here has all the matching bits in a single video stream from your collection. You can use these results in your application right away.
light
As you can see VideoDB fundamentally removes the limitation of files and gives you power to access and stream videos in a very seamless way. Stay tuned for exciting features in our upcoming version and keep building awesome stuff with VideoDB 🤘

🌟 Explore more with Video object

There are multiple methods available on a Video Object, that can be helpful for your use-case.

Access Transcript

# get text of the spoken content
text_json = video.get_transcript()
text = video.get_transcript_text()
print(text)

Add Subtitle to a video
It returns a new stream instantly with subtitle added into the video. Subtitle functions has many styling parameters like font, size, background color etc. Check and for details.
new_stream = video.add_subtitle()
play_stream(new_stream)
Get Thumbnail of Video :
video.generate_thumbnail() : Returns a thumbnail image of video.
Delete a video :
video.delete() : Delete a video.

👉🏼 Checkout to understand how you can modify the video streams in real-time. This opens doors for many usecases that were never possible with videos.⚡️
👉🏼 Checkout more examples and tutorials 👉 to explore what you can build with VideoDB

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.