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.
. ( 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")
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.
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()
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 timelineof 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
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
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>")
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.semanticPerfect for question answer kind of queries. This is also the default type of search.
SearchType.keywordIt 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.sceneIt search the visual information of the video, Index the video using index_scenesfunction.
IndexType.spoken_wordIt search the spoken information of the video, Index the video using index_spoken_wordsfunction.
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
VideoDBcan 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
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.
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