Guides: How to setup auto-generated captions with the Mux video API

0:00

I'm Dave at Mux, and in this video, we're going

0:02

to talk about how you can automatically generate

0:05

subtitles for your videos using the Mux video API.

0:09

Let's jump right in and take a look at how it works.

0:13

So, if you've created a video with Mux before,

0:16

it's pretty simple.

0:17

What you can do is just send a POST request to the

0:20

Mux API with the endpoint at video v1 assets.

0:25

And in that, uh, JSON payload that you send, you will

0:30

have a input parameter that contains a URL where the

0:36

video is hosted currently.

0:37

Have a great day.

0:38

Bye.

0:38

And Mux will then basically ingest this video and create

0:41

the different renditions required to be able to play

0:44

this video back effectively on many different devices.

0:48

Now what you can pass right alongside the URL is this

0:52

generatedSubtitles parameter.

0:54

The parameter value is an array of objects

0:57

which contains a language code and a name for the

1:00

generatedSubtitles track that you're going to generate.

1:03

So here in this case, we are going to create a new subtitle

1:07

track with an English language code and the name, we're just

1:11

going to call it default.

1:12

So I'm going to go ahead and just send this API request

1:15

along with my access token and secret key, which are already

1:20

in the basic authentication for this request.

1:24

So here we're seeing a 201 created, uh,

1:27

which is good news.

1:28

That means that the request has completed

1:30

successfully and the video is getting, you see it here

1:34

in the preparing status.

1:36

The video is preparing.

1:38

Let's head over to our Mux dashboard to see what the

1:40

status is of this video.

1:42

Alright, I'm over in the Mux dashboard.

1:44

I'm just going to hit reload and, uh, We'll see that the

1:47

video is currently preparing.

1:48

We'll just give it a second here to finish up this job.

1:51

All right.

1:52

Looks like the asset is ready now.

1:54

And I'm going to click on this row just so we can see some

1:57

more information about it.

1:59

Okay.

2:00

We're looking at a video of younger me and I had a much

2:04

more prominent beard at the time, but we see now on this

2:09

video, there are these closed captions button is enabled.

2:12

So I'm going to go ahead and hit play to see what these

2:15

subtitles are looking like.

2:17

Hey, I'm Dave with Mux, and in this video, you'll

2:20

learn how to create shorter clips of videos that exist

2:23

in your Mux library using only the Mux Video API.

2:27

Let me show you a basic example of how this works.

2:31

I have this ex Just by creating that API request,

2:34

we are able to automatically generate subtitles Look

2:37

pretty good and really pretty accurate, and they

2:40

were applied automatically to this video playback.

2:43

So if you were really paying attention to this video

2:46

when it first started, you might have noticed that

2:48

we also have the ability to get the transcript

2:51

of this video as well.

2:53

And what we can do here at the top, we have stream.

2:56

mux.

2:56

com and we're going to insert the playback ID

2:59

first and then the track ID here in the second half.

3:04

So if we're in the dashboard, we can get that information

3:07

right under the details tab on the right hand side here.

3:11

I'm going to grab the public playback ID and copy it.

3:16

I'm going to replace this part of the URL

3:19

with the playback ID.

3:21

Then, down here further, we have the tracks that are

3:24

available on this video, and here's the subtitles

3:27

track that was generated.

3:29

If I open it up, we have an ID right in here that I can

3:32

also copy, head back over to the URL that we're building

3:37

here, and paste it right in, and that's all we need.

3:41

Now we're ready to send this request off.

3:43

So I'm going to go ahead and click on send.

3:46

And look what we have here.

3:49

The entire transcript for that video is now

3:51

available for us to use in whatever way we can dream

3:54

up within our application.

3:56

Uh, this text is automatically generated

3:58

and really pretty accurate.

4:00

So it's kind of nice to be able to fetch this on

4:03

demand with no further work needed on our end.

4:07

That's all there is to it.

4:08

I wish the video was longer, maybe, uh, It would give me

4:11

a little more job security, but that's all we have

4:13

to share with you today.

4:14

I appreciate you watching.

4:16

I would encourage you to turn on subtitles for your videos

4:19

and broaden that audience that becomes available for

4:23

watching your video content.

4:25

Until next time, see you later.