Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to add subtitles to video file using MKVMerge

📅 2015-Jan-24 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ mkv, mkvmerge, srt, subtitles ⬩ 📚 Archive

If you like to watch videos with subtitles, you have two options. First, you have an external subtitles file and your player can pick it up while playing the video file. Second, you have a video file with an embedded subtitles stream. You may be forced to use the second option for certain video players or for streaming video content using media servers, like MiniDLNA for example.

It is possible to embed a subtitles file, for example a SubRip .srt file, into a video file to output a video file that has the subtitles stream embedded in it. The easiest method to achieve this is to output to a Matroska Multimedia Container (MKV) file. This is a commonly used container format for video files that can hold multiple streams: video, audio and subtitles. So, we create a MKV file containing the original video file (of any format) and a subtitles stream to be used along with it. The only limitation is that you will need a player that supports MKV to replay this back.

To deal with MKV files, we need the mkvtoolnix package:

$ sudo apt-get install mkvtoolnix

We use the mkvmerge tool from this package to merge a SubRip SRT file into an existing video file:

$ mkvmerge -o out.mkv in.avi in.srt

Note:

Tried with: MKVToolNix 6.7.0-1 and Ubuntu 14.04


© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧