1

How to Bulk Merge MKV and ASS Subtitle Files

Posted in Linux

Today I had a folder of files like so:

1
2
3
4
5
6
7
My Video - 01.ass
My Video - 01.mkv
My Video - 02.ass
My Video - 02.mkv
My Video - 03.ass
My Video - 03.mkv
...

I wanted to add the .ass subtitle files to my .mkv containers but I had about 100 videos and didn’t want to do each one manually.

Using mkvtoolnix you can combine the video and subtitles like so (courtesy of Super User):

1
mkvmerge -o output.mkv input.mkv subs.srt

Because our files are all nicely named we can use a for loop to iterate this command over them all simply replacing the .mkv extension with .ass in the third argument (See How can I rename all my *.foo files to *.bar, or convert spaces to underscores, or convert upper-case file names to lower case?):

1
for f in *.mkv; do mkvmerge -o "./muxed/$f" "$f" "${f%.mkv}.ass"; done

and that’s it! The fixed up files will be in your muxed subdirectory.

  • pengyout

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