Skip to content

video-db/videodb-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyPI version Stargazers Issues Website


Logo

VideoDB Python SDK

Video Database for your AI Applications
Explore the docs »

View Demo · Report Bug · Request Feature

VideoDB Python SDK

VideoDB Python SDK allows you to interact with the VideoDB serverless database. Manage videos as intelligent data, not files. It's scalable, cost-efficient & optimized for AI applications and LLM integration.

Installation

To install the package, run the following command in your terminal:

pip install videodb

Quick Start

Creating a Connection

Get an API key from the VideoDB console. Free for first 50 uploads (No credit card required).

import videodb
conn = videodb.connect(api_key="YOUR_API_KEY")

Working with a Single Video


⬆️ Uploading a Video

Now that you have established a connection to VideoDB, you can upload your videos using conn.upload(). You can directly upload from youtube, any public url, S3 bucket or a local file path. A default collection is created when you create your first connection.

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")

📺 View your Video

Once uploaded, your video is immediately available for viewing in 720p resolution. ⚡️

  • Generate a streamable url for the 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()

⛓️ Stream Specific Sections of Videos

You can easily clip specific sections of a video by passing a timeline of the start and end timestamps (in seconds) as a parameter. For example, this will generate and play a compilation of the first 10 seconds and the clip between the 120th and the 140th second.

stream_link = video.generate_stream(timeline=[[0,10], [120,140]])
play_stream(stream_link)

🔍 Search Inside a Video

To search bits inside a video, you have to index the video first. This can be done by a simple command. P.S. Indexing may take some time for longer videos.

video.index_spoken_words()
result = video.search("Morning Sunlight")
result.play()
video.get_transcript()

Videodb is launching more indexing options in upcoming versions. As of now you can try the semantic index - Index by spoken words.

In the future you'll be able to index videos using:

  1. Scene - Visual concepts and events.
  2. Faces.
  3. Specific domain Index like Football, Baseball, Drone footage, Cricket etc.

Viewing Search Results

video.search() returns a SearchResults object, which contains the sections or as we call them, shots of videos which semantically match your search query.

  • result.get_shots() Returns a list of Shot(s) that matched the search query.
  • result.play() Returns a playable url for the video (similar to video.play(); you can open this link in the browser, or embed it into your website using an 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.

🔄 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 a Collection object; the default collection.
  • coll.get_videos() : Returns a list of Video objects; all videos in the collections.
  • coll.get_video(video_id): Returns a Video object, corresponding video from the provided video_id.
  • coll.delete_video(video_id): Deletes the video from the Collection.

📂 Search Inside Collection

You can simply Index all the videos in a collection and use the search method to find relevant results. Here we are indexing the spoken content of a collection and performing semantic search.

# Index all videos in collection
for video in coll.get_videos():
    video.index_spoken_words()

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

The result here has all the matching bits in a single stream from your collection. You can use these results in your application right away.

🌟 Explore the Video object

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

Get the Transcript

# words with timestamps
text_json = video.get_transcript()
text = video.get_transcript_text()
print(text)

Add Subtitles to a video

It returns a new stream instantly with subtitles added to the video.

new_stream = video.add_subtitle()
play_stream(new_stream)

Get Thumbnail of a Video:

video.generate_thumbnail(): Returns a thumbnail image of video.

Delete a video:

video.delete(): Deletes the video.

Checkout more examples and tutorials 👉 Build with VideoDB to explore what you can build with VideoDB.


Roadmap

  • Adding More Indexes : Face, Scene, Security, Events, and Sports
  • Give prompt support to generate thumbnails using GenAI.
  • Give prompt support to access content.
  • Give prompt support to edit videos.
  • See the open issues for a list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request