videodb
VideoDB Documentation
videodb
VideoDB Documentation
Examples and Tutorials

icon picker
AI Generated Ad Films for Product Videography: Wellsaid, Open AI & VideoDB

Automatically Creating a professional quality advertisement from product videography B-Roll

Overview

Crafting AI content and blending results from multiple tools can be incredibly powerful and time-efficient. Manual execution of these tasks is often cumbersome and time-consuming. However, with the right tools and techniques, you can automate various processes to achieve remarkable results effortlessly.
In this tutorial, we will explore how to leverage the seamless integration between , and to create captivating voiceovers for product advertisements. By harnessing the advanced capabilities of these platforms, you can enhance the storytelling and engagement of your product videos with AI-generated voiceovers; all within a single environment.
For this tutorial, we’ll be using product footage from from Youtube and converting it into a professionally made advertisement for a jewellery brand; all using prompts and programmatic scripting 😎.

image.png

Setup

📦 Installing packages

Ensure you have the necessary packages installed:
%pip install openai
%pip install videodb

🔑 API Keys

Ensure you have access to , and API keys. If you haven't already, sign up for API access on the respective platforms.
light
Get your API key from . ( Free for first 50 uploads, No credit card required ) 🎉
import os

os.environ["OPENAI_API_KEY"] = ""
os.environ["WELLSAID_API_KEY"] = ""
os.environ["VIDEO_DB_API_KEY"] = ""

🎙️ Wellsaid's Voice Avatar

You will also need Wellsaid's Voice Avatar that you want to use to generate your voiceover.
For this demo, we’ll choose a slick, professional ads voiceover artist’s voice. Wellsaid has a wide range of options to choose from- you can check them out by signing up on their platform and accessing their. Once finalized, copy the Speaker ID from Wellsaid and link it here.
voiceover_artist_id = "109"


Implementation


🌐 Step 1: Connect to VideoDB

Begin by establishing a connection to VideoDB using your API key.
from videodb import connect

# Connect to VideoDB using your API key
conn = connect()
coll = conn.get_collection()

🎥 Step 2: Upload Video

Upload your product video to VideoDB using its URL or file path.
# Upload a video by URL (replace the url with your video)
video = conn.upload('https://www.youtube.com/watch?v=2DcAMbmmYNM')

🔍 Step 3: Analyze Scenes and Generate Scene Descriptions

Analyze the scenes within your product video using VideoDB’s scene indexing capabilities. This will provide context for the script prompt.
video.index_scenes()

Let's view the description of first scene from the video
scenes = video.get_scenes()
print(f"{scenes[0]['start']} - {scenes[0]['end']}")
print(scenes[0]["response"])
Output:
[{'end': '0.5338666666666667', 'response': 'The jewellery is a beautiful and delicate piece that would be perfect for any occasion. The necklace is made of a thin gold chain with a small diamond pendant, and the earrings are made of the same gold with a small diamond stud. The bracelet is made of the same gold and has a small diamond charm. The ring is made of the same gold and has a small diamond solitaire.', 'start': '0'},

🎤 Step 4: Generate Voiceover Script with LLM

Combine scene descriptions with a script prompt, instructing LLM (OpenAI) to create a suitable voiceover for your product advertisement.
This script prompt can be refined and tweaked to generate the most suitable output. Check out to explore more use cases.
import openai

client = openai.OpenAI()

script_prompt = "Here's the data from a scene index for a video from a jewellery product photoshoot. Study this and then generate a synced script based on the description below. Make sure the script is in the language, voice and style of a professional voiceover artist skilled at weaving beautiful storytelling in advertisements.\n \n"

full_prompt = script_prompt

# run this prompt for each scene
for scene in scenes:
full_prompt += f"- {scene}\n"

openai_res = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "system", "content": full_prompt}],
)
voiceover_script = openai_res.choices[0].message.content

# Truncate first 1000 characters of script
# If you have Wellsaid's paid plan remove this
voiceover_script = voiceover_script[:1000]

🎤 Step 5: Generate Voiceover Audio with Wellsaid

Utilize the generated script to synthesize a professional voiceover for your product advertisement using Wellsaid's API.
import requests
import time


# Call Wellsaid API to generate voiceover
url = "https://api.wellsaidlabs.com/v1/tts/stream"
headers = {
"accept": "application/json",
"content-type": "application/json",
"X-Api-Key": os.environ.get("WELLSAID_API_KEY")
}

# Initiate TTS Job for each Chunk
payload = {
"text": voiceover_script,
"speaker_id": speaker_id
}
wellsaid_res = requests.request("POST", url, json=payload, headers=headers)

# Save the audio file
audio_file = "audio.mp3"
CHUNK_SIZE = 1024
with open(audio_file, 'wb') as f:
for chunk in wellsaid_res.iter_content(chunk_size=CHUNK_SIZE):
if chunk:
f.write(chunk)


🎬 Step 6: Add Voiceover to Video with VideoDB

Upload the generated audio file (voiceover) to VideoDB and add it to the original product video using the :
audio = conn.upload(file_path=audio_file)
from videodb.timeline import Timeline
from videodb.asset import VideoAsset, AudioAsset

# Create a timeline object
timeline = Timeline(conn)

# Add the video asset to the timeline for playback
video_asset = VideoAsset(asset_id=video.id)
timeline.add_inline(asset=video_asset)

# Add the audio asset to the timeline for playback
audio_asset = AudioAsset(asset_id=audio.id)
timeline.add_overlay(start=0, asset=audio_asset)

🪄 Step 7: Review and Share

Preview the product video with the integrated voiceover to ensure it aligns with your vision. Once satisfied, share the video to showcase your product effectively.
from videodb import play_stream

stream_url = timeline.generate_stream()
play_stream(stream_url)

Output:
For more such explorations, refer to the and join the VideoDB community on or for support and collaboration.
Feel free to share your creations via social media or other platforms to inspire others in the community. Join us on , or
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.