Converting MKV video file to MP4 with hardsubs (embedded subtitles) on Linux (Ubuntu)

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.

Categories: Linux, Other, Software

3 Comments

  1. growingmature

    July 29, 2014 — 07:57

    I use iDealshare VideoGo to add subtitles to MP4, it also helps to add subtitles to other video like AVI, MKV, WMV, MOV, VOB and etc.

    Just google Step by step guide to add subtitles to MP4 with iDealshare VideoGo, you will find a detailed tutorial.

    It has both Mac version and Windows version.

    It even has the feature of extract subtitles from video or removing subtitles from video

  2. You can use Avdshare Video Converter to Add subtitles, like SRT, ASS, SUB, SSA, IDX to MKV for playing on various MKV devices.

  3. its not working for me, i have done every step but at the end my file has no subtitles

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Copyright © 2024 Closer to Code

Theme by Anders NorenUp ↑