It is possible to turn soft subtitles into hard subtitles by using libass, and I have tried it, it simply works. However it means we will have to reencode the video, which can be quite time consuming for large videos without optimization. In this article, I do not aim to be comprehensive, we will simply go through the gist of how I did it.

The magic word is:

ffmpeg -i input.mp4 \
    -vf "subtitles=sub.srt" \
    -c:v libx264 \
    -crf 20 \
    -c:a aac \
    -b:a 192k \
    output.mp4

Consider three files:

  • input.mp4: our original video file.
  • sub.srt: our subtitle file, can be other format such as sub.ass for ASS subtitle format.
  • output.mp4: the video with a hardcoded subtitle.

In the command above I use the following options:

  • -c:v libx264: selects the encoding to x264, but we can also use x265
  • -crf 20: select the CRF value, for x264 the default is 23, and 18-28 is a sane range, while for x265 the default is 28. You may want to read more about CRF.
  • -c:a aac: I selected AAC (advanced audio coding) for audio codec, which is a common and efficient audio compression format, and as far as I understand, is free for personal use.
  • -b:a 192k: sets the audio bitrate to 192 kilobits per second, which is a common bitrate for good quality stereo audio.

Source: