Skip to content

Commit 16b3fe2

Browse files
committed
add video subtitles demo.
1 parent 73356b2 commit 16b3fe2

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.env
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "Adding Subtitles to Vidoes",
3+
"tech": "nodejs"
4+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "node-video-subtitles",
3+
"version": "1.0.0",
4+
"type": "commonjs",
5+
"description": "",
6+
"main": "index.js",
7+
"scripts": {},
8+
"author": "",
9+
"license": "ISC",
10+
"dependencies": {
11+
"cloudinary": "^2.5.1"
12+
},
13+
"devDependencies": {
14+
"dotenv": "^16.4.7"
15+
}
16+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
require('dotenv').config()
2+
3+
const cloudinary = require('cloudinary').v2;
4+
const path = require('node:path');
5+
6+
cloudinary.config({
7+
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
8+
api_key: process.env.CLOUDINARY_API_KEY,
9+
api_secret: process.env.CLOUDINARY_API_SECRET,
10+
})
11+
12+
// PART ONE - Adding existing subtitles
13+
14+
const video = cloudinary.url("examples/first", {
15+
resource_type: "video",
16+
overlay: {
17+
resource_type: "subtitles",
18+
public_id: "examples/first.transcript",
19+
},
20+
})
21+
22+
console.log(video)
23+
24+
// PART TWO - Adding generated subtitles
25+
26+
const videoPath = path.resolve("./examples/second.mp4")
27+
28+
await cloudinary.uploader.upload(videoPath, {
29+
public_id: "second",
30+
folder: "examples",
31+
resource_type: "video",
32+
raw_convert: "google_speech:srt:vtt",
33+
})
34+
35+
const uploadedVideo = cloudinary.url("examples/second", {
36+
resource_type: "video",
37+
overlay: {
38+
resource_type: "subtitles",
39+
public_id: "examples/second.transcript",
40+
},
41+
})
42+
43+
console.log(uploadedVideo)

0 commit comments

Comments
 (0)