extract subtitles from mkv using mkvtoolnix

Download Extract subtitles from mkv using mkvtoolnix

If you can't read please download the document

Upload: saimonk

Post on 28-Oct-2015

155 views

Category:

Documents


2 download

DESCRIPTION

Tutorial for Matroska video subtitles

TRANSCRIPT

Extract subtitles from .mkv usingmkvtoolnixBy benkkei IntroductionSometimes you have to extract subtitles (or any other track) from a matroska file, the tool mkvtoolnix can do the job very well. But in case of you have several files on wich to perform this operation or if you do this often, youd probably want to automatize this task. So I writed a little script who do the job for me.MkvtoolnixFirst of all you have to install the packages:# apt-get install mkvtoolnixWell use two commands from this packages: mkvmerge and mkvextract. While the first one will be use to get information about the files and the tracks, the second will extract the track.MkvmergeLets assume youve made a Matroska file with one video track, two audio tracks and two subtitle tracks, and you need the second audio track and the first subtitle track. So first fire up mkvmerge with the identify option:$ mkvmerge -i movie.mkvFile movie.mkv: container: MatroskaTrack ID 1: video (V_MS/VFW/FOURCC, DIV3)Track ID 2: audio (A_MPEG/L3)Track ID 3: audio (A_VORBIS)Track ID 4: subtitles (S_TEXT/UTF8)Track ID 5: subtitles (S_TEXT/UTF8)MkvextractNow you can use mkvextract like this:$ mkvextract tracks movie.mkv 3:audio.ogg 4:subtitles.srtHere is the script#!/bin/bash

# does the directory ~/matroska exist?if [ -e ~/matroska ] then echo "==== ~/matroska directory is already existing ====" else echo "==== Creating ~/matroska ====" mkdir ~/matroskafi

# move the .mkv in ~/Tlchargements to ~/matroskaecho "==== Moving files .mkv ===="mv -v ~/Tlchargements/*.mkv ~/matroskaif [ $? -eq 0 ] then echo "==== Files succesfully moved to ~/matroska ====" else echo "==== ERROR... No files moved... aborting ====" kill -SIGINT $$fi

# extract subtittles from .mkv filesecho "==== Extracting subtitles ===="list=$(ls ~/matroska/ | grep .mkv)for file in $list do subid=$(mkvmerge -i ~/matroska/$file | grep subtitles | awk -F" " '{print $3}') mkvextract tracks ~/matroska/$file $subid$HOME/matroska/$(echo $file | awk -F".mkv" '{print $1}').srt done