Furkan Gözükara
Furkan Gözükara

Reputation: 23830

How to burn / hardcode subtitle to the downloaded youtube video with youtube-dl

This command downloads the video and embed the auto-generated youtube subtitle to the file

youtube-dl.exe -ci -f "bestvideo[ext=mp4]"+"bestaudio[ext=m4a]" --write-auto-sub  --embed-subs --merge-output-format mp4 https://www.youtube.com/watch?v=k4rCdHsdiss

However the subtitle is only embedded. I want it to be burned/hardcoded so that it can be played on non-embed supporting platforms such as treadmill

I am using windows 10

Upvotes: 4

Views: 5915

Answers (1)

Yury Surzhynsky
Yury Surzhynsky

Reputation: 56

youtube-dl cannot burn the subtitles by itself. You need to use postprocessors like FFmpeg or avconv for it. youtube-dl use them internally for some tasks. As you successfully used bestvideo+bestaudio argument, you already have installed one of these in your system. avconv is a fork of FFmpeg, so they accept mostly the same arguments. I'll show the FFmpeg case here.

youtube-dl has a feature to add arguments to the postprocessors but I can't see how to use it to solve this task.

Other possibility is using --exec flag. Regretfully, I have not a Windows machine now so I wrote only Linux variant.

youtube-dl -f "[height=360][ext=mp4]+bestaudio[ext=m4a]" --write-sub --write-autosub --embed-subs --exec "mkdir temp && ffmpeg -i {} -vf subtitles={}:force_style='FontName=Arial' -acodec copy temp/{} && mv -f temp/{} {} && rm -r temp" --restrict-filenames AO4In7d6X-c

This is a one-line command but it has several flaws:

  1. You must use --restrict-filenames to make it work. No more nice filenames.
  2. I see no way to have more than one option for subtitle style, i. e. font name, font color and font size.
  3. Very cumbersome.

So my best guess is using FFmpeg manually or with a batch script after downloading the video with youtube-dl. Not tested on Windows but it should work well.

ffmpeg.exe -i "input.mp4" -vf subtitles="filename='input.mp4':force_style='FontSize=20,FontName=Arial'" -c:v libx264 -x264-params crf=22 -preset fast -profile:v high "output.mp4"
  1. input.mp4 must be a file with embedded subtitles.
  2. FFmpeg must be compiled with the support of libass. Type ffmpeg.exe without arguments and look for --enable-libass. libx264 is recommended too.
  3. To tune the speed of encoding you may use a different preset. Allowed values are ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo. Faster presets mean bigger file size.
  4. To tune quality use crf parameter. The smaller the number the better quality but also the bigger file size. Numbers from 16 to 30 are optimal.
  5. If the file fails to play on some old players, you may try to use the profile baseline and lower the level.

Upvotes: 4

Related Questions