Actually this was already posted but it was lost on some migration... so here it is again
All the parsing and extraction is implemented by
mkvtoolnix, so first step is installing it...
sudo apt-get install mkvtoolnix
After this we can see the tracks in the file
|grep track it's better seen, for example
$ mkvinfo video.mkv |grep Track | + Track number: 1 (track ID for mkvmerge & mkvextract: 0) | + Track UID: 1 | + Track type: video | + Track number: 2 (track ID for mkvmerge & mkvextract: 1) | + Track UID: 6584684576 | + Track type: audio | + Track number: 3 (track ID for mkvmerge & mkvextract: 2) | + Track UID: 685789658 | + Track type: subtitles
In this case we're interested in track number 3 (or 2 for
mkvextract as the tool explains), so we'll extract it with
mkvextract tracks video.mkv 2:subtitles
During this process the interface points the subtitles type, so we may want to set the correct extension to the resulting file
$ mkvextract tracks video.mkv 2:subtitles Extracting track 2 with the CodecID 'S_TEXT/ASS' to the file 'subtitulos. Container format: SSA/ASS text subtitles Progress: 100% $ mv subtitles subtitles.ssa
And that's all, surely any track can be extracted, by exchanging the
1: we'd get the audio.