Skip to content

Commit bc1a6b2

Browse files
committed
nb update inserting clips
1 parent 206a51c commit bc1a6b2

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed

examples/inserting_clips.ipynb

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"### Overview\n",
8+
"\n",
9+
"<a href=\"https://colab.research.google.com/github/video-db/videodb-cookbook/blob/main/examples/ad_insertion_part1.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>\n",
10+
"\n",
11+
"In this tutorial we're going to whip up some multimedia magic. ✨\n",
12+
"\n",
13+
"We are going to use videodb to insert a simple advertisment in a video.\n",
14+
"\n",
15+
"Say goodbye to the cumbersome tools of traditional video editing – we're doing things the VideoDb way!\n",
16+
"\n"
17+
]
18+
},
19+
{
20+
"cell_type": "markdown",
21+
"metadata": {},
22+
"source": [
23+
"### Setup\n",
24+
"\n",
25+
"To get started, we need to install videodb to our python environment:"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": null,
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"!pip install videodb"
35+
]
36+
},
37+
{
38+
"cell_type": "markdown",
39+
"metadata": {},
40+
"source": [
41+
"##### 🔗 Setting Up a connection to db\n",
42+
"To connect to VideoDB, simply create a `Connection` object. \n",
43+
"\n",
44+
"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. \n",
45+
"\n",
46+
">💡\n",
47+
">Get your API key from [VideoDB Console](https://console.videodb.io). ( Free for first 50 uploads, No credit card required ) 🎉."
48+
]
49+
},
50+
{
51+
"cell_type": "code",
52+
"execution_count": 2,
53+
"metadata": {},
54+
"outputs": [],
55+
"source": [
56+
"from videodb import connect, play_stream\n",
57+
"conn = connect(api_key=\"\")"
58+
]
59+
},
60+
{
61+
"cell_type": "markdown",
62+
"metadata": {},
63+
"source": [
64+
"### Uploading our videos to videodb\n",
65+
"\n",
66+
"We have a base video into which we intend to insert an advertisement. \n",
67+
"\n",
68+
"Additionally, we have a separate video that serves as our target advertisement. Our goal is to embed this advertisement into the base video at a specific timestamp. \n",
69+
"\n",
70+
"For this process, we will need to upload both videos to VideoDB"
71+
]
72+
},
73+
{
74+
"cell_type": "code",
75+
"execution_count": 8,
76+
"metadata": {},
77+
"outputs": [],
78+
"source": [
79+
"base_video_url = \"https://www.youtube.com/watch?v=e1cf58VWzt8\"\n",
80+
"ad_video_url = \"https://www.youtube.com/watch?v=--khbXchTeE\"\n",
81+
"\n",
82+
"base_vid = conn.upload(url=base_video_url)\n",
83+
"ad_video = conn.upload(url=ad_video_url)"
84+
]
85+
},
86+
{
87+
"cell_type": "markdown",
88+
"metadata": {},
89+
"source": [
90+
"### Inserting ad video to base_video\n",
91+
"\n",
92+
"Inserting a video into another video becomes incredibly straightforward using VideoDB.\n",
93+
"\n",
94+
"For instance, let's say we wish to insert our clip at the 10-second mark in the video's timeline.\n",
95+
"\n",
96+
"In the resulting video, the inserted clip will begin to play at 10 seconds into the base video's timeline.\n"
97+
]
98+
},
99+
{
100+
"cell_type": "code",
101+
"execution_count": null,
102+
"metadata": {},
103+
"outputs": [],
104+
"source": [
105+
"insert_timestamp = 10\n",
106+
"stream_link = base_vid.insert_video(ad_video, insert_timestamp)"
107+
]
108+
},
109+
{
110+
"cell_type": "markdown",
111+
"metadata": {},
112+
"source": [
113+
"### Playing our resulting video.\n",
114+
"\n",
115+
"You can play your videos directly on videodb Player. "
116+
]
117+
},
118+
{
119+
"cell_type": "code",
120+
"execution_count": null,
121+
"metadata": {},
122+
"outputs": [],
123+
"source": [
124+
"play_stream(stream_link)"
125+
]
126+
},
127+
{
128+
"cell_type": "markdown",
129+
"metadata": {},
130+
"source": [
131+
"You can also open the final video in your browser "
132+
]
133+
}
134+
],
135+
"metadata": {
136+
"kernelspec": {
137+
"display_name": "venv",
138+
"language": "python",
139+
"name": "python3"
140+
},
141+
"language_info": {
142+
"codemirror_mode": {
143+
"name": "ipython",
144+
"version": 3
145+
},
146+
"file_extension": ".py",
147+
"mimetype": "text/x-python",
148+
"name": "python",
149+
"nbconvert_exporter": "python",
150+
"pygments_lexer": "ipython3",
151+
"version": "3.9.12"
152+
}
153+
},
154+
"nbformat": 4,
155+
"nbformat_minor": 2
156+
}

0 commit comments

Comments
 (0)