How to embed VTT captions (custom subtitles) on YouTube Player videos?

398 views Asked by At

I checked the documentation of YouTube Player API Reference, but it does not specify any parameters to add a path to our own VTT file for captions.

I also came across Plyr.JS, but I am not sure if it can be used to achieve the same.

So, is there any way to play our own subtitle on YouTube videos?

1

There are 1 answers

1
Gokul NC On

I found an indirect temporary way to do it.

  1. Call this endpoint to get the direct link for the YouTube video:
    https://maadhav-ytdl.herokuapp.com/video_info.php?url=https://www.youtube.com/watch?v=BaW_jenozKc

(Source code for this server: https://github.com/Maadhav/youtube-downloader-API )

  1. decodeURIComponent() the link that you get.
  2. Then embed the video link and your captions track in tag as described here.

Works as on December 2020.