Extraire les sous-titres d’un fichier mkv

Install MKVToolNix (create, alter and inspect mkv) :

sudo apt-get install mkvtoolnix

Find the subtitle track number and the attachment IDs of the fonts using the mkvinfo tool (print information about elements in Matroska files):

mkvinfo movie.mkv

or using the GUI version:

mkvinfo -g

Assuming the subtitles are track 3, extract them using the mkvextract tool (extract tracks from Matroska files into other files):

mkvextract tracks movie.mkv 3:movie.***

Optionally extract also the font (by not specifying a file name for the font, the filename of the attached font will be used. This needs to be done for each font that is attached):

mkvextract attachments movie.mkv FontID:

Install the fonts and regenerate the font cache so that the subtitles will be rendered properly:

cp *.ttf ~/.fonts
sudo fc-cache -v ~/.fonts

Make sure that the file is in MSDOS (CR-LF) format by using flip command:

sudo apt-get install flip
flip -m movie.srt

MKV files

In order to extract subtitles from Matroska (MKV) files, you need the free and open source mkvtoolnix packages. They come for Windows and Linux, and on a Mac you can install them through Homebrew with brew install mkvtoolnix.

Then, inspect the file:

mkvmerge -i input.mkv

This will list the tracks, for example like this:

File 'input.mkv': container: Matroska
Track ID 1: video (V_MPEG4/ISO/AVC)
Track ID 2: audio (A_AAC)
Track ID 3: subtitles (S_TEXT/UTF8)

Based on the ID of the track, call the following command, where <trackID> is the one you identified above. <output> is just a dummy name, you can use any you want.

mkvextract tracks input.mkv <trackID>:<output>.srt

So, in our case, that would have been:

mkvextract tracks input.mkv 3:subs.srt

 

 

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *