Guides: How to setup auto-generated captions with the Mux video API
I'm Dave at Mux, and in this video, we're going
to talk about how you can automatically generate
subtitles for your videos using the Mux video API.
Let's jump right in and take a look at how it works.
So, if you've created a video with Mux before,
it's pretty simple.
What you can do is just send a POST request to the
Mux API with the endpoint at video v1 assets.
And in that, uh, JSON payload that you send, you will
have a input parameter that contains a URL where the
video is hosted currently.
Have a great day.
Bye.
And Mux will then basically ingest this video and create
the different renditions required to be able to play
this video back effectively on many different devices.
Now what you can pass right alongside the URL is this
generatedSubtitles parameter.
The parameter value is an array of objects
which contains a language code and a name for the
generatedSubtitles track that you're going to generate.
So here in this case, we are going to create a new subtitle
track with an English language code and the name, we're just
going to call it default.
So I'm going to go ahead and just send this API request
along with my access token and secret key, which are already
in the basic authentication for this request.
So here we're seeing a 201 created, uh,
which is good news.
That means that the request has completed
successfully and the video is getting, you see it here
in the preparing status.
The video is preparing.
Let's head over to our Mux dashboard to see what the
status is of this video.
Alright, I'm over in the Mux dashboard.
I'm just going to hit reload and, uh, We'll see that the
video is currently preparing.
We'll just give it a second here to finish up this job.
All right.
Looks like the asset is ready now.
And I'm going to click on this row just so we can see some
more information about it.
Okay.
We're looking at a video of younger me and I had a much
more prominent beard at the time, but we see now on this
video, there are these closed captions button is enabled.
So I'm going to go ahead and hit play to see what these
subtitles are looking like.
Hey, I'm Dave with Mux, and in this video, you'll
learn how to create shorter clips of videos that exist
in your Mux library using only the Mux Video API.
Let me show you a basic example of how this works.
I have this ex Just by creating that API request,
we are able to automatically generate subtitles Look
pretty good and really pretty accurate, and they
were applied automatically to this video playback.
So if you were really paying attention to this video
when it first started, you might have noticed that
we also have the ability to get the transcript
of this video as well.
And what we can do here at the top, we have stream.
mux.
com and we're going to insert the playback ID
first and then the track ID here in the second half.
So if we're in the dashboard, we can get that information
right under the details tab on the right hand side here.
I'm going to grab the public playback ID and copy it.
I'm going to replace this part of the URL
with the playback ID.
Then, down here further, we have the tracks that are
available on this video, and here's the subtitles
track that was generated.
If I open it up, we have an ID right in here that I can
also copy, head back over to the URL that we're building
here, and paste it right in, and that's all we need.
Now we're ready to send this request off.
So I'm going to go ahead and click on send.
And look what we have here.
The entire transcript for that video is now
available for us to use in whatever way we can dream
up within our application.
Uh, this text is automatically generated
and really pretty accurate.
So it's kind of nice to be able to fetch this on
demand with no further work needed on our end.
That's all there is to it.
I wish the video was longer, maybe, uh, It would give me
a little more job security, but that's all we have
to share with you today.
I appreciate you watching.
I would encourage you to turn on subtitles for your videos
and broaden that audience that becomes available for
watching your video content.
Until next time, see you later.