Subtitles
ytdlp-nodejs allows you to download subtitles, including auto-generated captions, and optionally embed them into the video file.
Downloading Subtitles
To download subtitles alongside the video:
1await ytdlp.downloadAsync(url, {
2 writeSubs: true,
3 subLangs: ['en', 'es'], // Languages: English and Spanish
4});
This will save .vtt (default) files next to the video.
Embedding Subtitles
To embed the subtitles directly into the video container (e.g., MKV or MP4):
1await ytdlp.downloadAsync(url, {
2 writeSubs: true,
3 subLangs: ['en'],
4 embedSubs: true,
5 format: 'mergevideo', // Required for embedding in some containers like mp4
6});
Auto-Generated Captions
YouTube generates captions automatically. To download these:
1await ytdlp.downloadAsync(url, {
2 writeAutoSubs: true,
3 subLangs: ['en'],
4});
Subtitle Formats
You can specify the preferred subtitle format:
1await ytdlp.downloadAsync(url, {
2 writeSubs: true,
3 subFormat: 'srt', // Convert to SRT
4});
List Available Subtitles
You can check available subtitles in the video info:
1const info = await ytdlp.getInfoAsync(url);
2console.log('Manual subs:', Object.keys(info.subtitles || {}));
3console.log('Auto subs:', Object.keys(info.automatic_captions || {}));