I had to convert some MKV video files into MP4 format with embedded (rendered) subtitles. This would not be a problem if not the external ASS subs that I had. HandBrakeCLI can easily convert between those formats but it can use embedded ASS file (from MKV video) or provided SRT. There is no way to use an external ASS subtitles file. Luckily there is a quite simple solution for that issue: we can just remove original MKV video subtitles, add ours and then use HandBrakeCLI to convert the video.
Replacing the ASS MKV subtitles with our own
First we need to remove the original ASS subtitles that are stored in MKV file:
mkvmerge --no-subtitles source.mkv -o target.mkv
This will copy MKV file but will remove subtitles.
After that, we need to add our ow ASS file (subtitles.ass):
mkvmerge -o target_with_subs.mkv target.mkv -D -A subtitles.ass
Now we have a MKV file with our ASS subtitles, that we can use to create MP4 file.
Creating MP4 file with embedded (hardcoded) subtitles
Convertion is really simple:
HandBrakeCLI -i target_with_subs.mkv -o result.mp4 -e x264 -q 20 -B 160\ --x264-preset medium --two-pass -O --turbo --subtitle "1" \ --subtitle-burn "1" --srt-codeset utf8
Simple one line long command and 30 minutes later you have your MP4 file with hardsubs.