JoZ3: un poco de GNU/Linux, desarrollo web, fotografía, videojuegos, música y ...

Extraer subtítulos de un contenedor Matroska

Hace unas semanas descargue una versión HD de la excelente película de terror tailandés Shutter, la versión que descargue fue Shutter 2004 (1080p Bluray x265 HEVC 10bit AAC 5.1 Thai Tigole) pero no encontré subtítulos en español sincronizados para esa versión. La película estaba en un contenedor Matroska que incluía los subtítulos en ingles y alemán, la única opción que tenía era la de extraer los subtítulos en ingles, usar los subtítulos en español de otras versiones y sincronizar los tiempos de los subtítulos en ingles.

El contenedor Matroska

La definición del contenedor Matroska, segun la wikipedía es el siguiente:

Matroska es un formato contenedorabierto, un archivo informático que puede contener una cantidad ilimitada de vídeo, audio, imagen o pistas de subtítulos dentro de un solo archivo. Su finalidad es la de servir como formato universal para el almacenamiento de contenidos audiovisuales y multimedia, como películas o programas de televisión, videojuegos, imágenes y textos. No es un codec de video como H.264/MPEG-4 AVC o vorbis, sino que es un contenedor que envuelve audio, video y subtítulos dentro de un mismo paquete, y que permite reproducir el archivo tanto en ordenadores como en otros dispositivos con la suficiente potencia de procesamiento.

Matroska - Wikipedia, la enciclopedia libre

Luego de conocer un poco sobre este contenedor sigue la explicación sobre esta tarea, les recuerdo que mi SO es GNU/Linux distribución Manjaro x64, aunque las instrucciones sirven para cualquier distribución de GNU/Linux incluso para usuarios de ms windows, a excepción de la forma de instalar la herramienta usada.

MKVToolNix la navaja suiza para el contenedor Matroska

La herramienta principal y básica es MKVToolNix, un poderoso set de herramientas para manipular archivos Matroska; este programa lo pueden descargar desde su su sitio web y esta disponible tanto para diferentes distribuciones de GNU/Linux como ms windows. Para instalarla en Manjaro es tan fácil como escribir desde la terminal esto:

sudo pacman -S mkvtoolnix-cli

También pueden instalarlo desde el gesto de paquetes de Manjaro o el Octopi.

Luego de instalar el MKVToolNix, abrimos la terminal, desde GNU/Linux o ms windows, y nos ubicamos donde esta localizado el archivo el archivo del contenedor Matroska del que vamos a extraer los subtítulos, en mi caso el nombre del archivo es Shutter.2004.mkv; lo primero es ubicar la “pista” (track) donde se encuentra los subtítulos que necesitamos, esto lo hacemos con el comando mkvinfo:

mkvinfo Shutter.2004.mkv
La salida es la siguiente:
+ EBML head
|+ EBML version: 1
|+ EBML read version: 1
|+ EBML maximum ID length: 4
|+ EBML maximum size length: 8
|+ Doc type: matroska
|+ Doc type version: 4
|+ Doc type read version: 2
+ Segment, size 2048528838
|+ Seek head (subentries will be skipped)
|+ EbmlVoid (size: 4012)
|+ Segment information
| + Timecode scale: 1000000
| + Multiplexing application: libebml v1.3.4 + libmatroska v1.4.5
| + Writing application: mkvmerge v9.4.0 ('Knurl') 64bit
| + Duration: 5804.222s (01:36:44.222)
| + Date: Tue Sep 06 06:57:54 2016 UTC
| + Segment UID: 0xa1 0xc1 0xec 0x85 0xd8 0x36 0x5b 0x84 0x85 0x9b 0xdf 0x6d 0xca 0x60 0x48 0x23
|+ Segment tracks
| + A track
|  + Track number: 1 (track ID for mkvmerge & mkvextract: 0)
|  + Track UID: 10832681874364858
|  + Track type: video
|  + Lacing flag: 0
|  + MinCache: 1
|  + Codec ID: V_MPEGH/ISO/HEVC
|  + CodecPrivate, length 1131 (HEVC profile: Main 10 @L4.0)
|  + Default duration: 41.667ms (24.000 frames/fields per second for a video track)
|  + Language: und
|  + Video track
|   + Pixel width: 1920
|   + Pixel height: 1080
|   + Display width: 1920
|   + Display height: 1080
| + A track
|  + Track number: 2 (track ID for mkvmerge & mkvextract: 1)
|  + Track UID: 16111199640271706300
|  + Track type: audio
|  + Codec ID: A_AAC
|  + CodecPrivate, length 2
|  + Default duration: 21.333ms (46.875 frames/fields per second for a video track)
|  + Language: tha
|  + Audio track
|   + Sampling frequency: 48000
|   + Channels: 6
| + A track
|  + Track number: 3 (track ID for mkvmerge & mkvextract: 2)
|  + Track UID: 4506191980823210926
|  + Track type: subtitles
|  + Lacing flag: 0
|  + Codec ID: S_TEXT/UTF8
| + A track
|  + Track number: 4 (track ID for mkvmerge & mkvextract: 3)
|  + Track UID: 5025865172156633481
|  + Track type: subtitles
|  + Default flag: 0
|  + Lacing flag: 0
|  + Codec ID: S_VOBSUB
|  + CodecPrivate, length 348
|  + Language: ger
|  + Content encodings
|   + Content encoding
|    + Content compression
|+ EbmlVoid (size: 1181)
|+ Chapters
| + EditionEntry
|  + EditionFlagHidden: 0
|  + EditionFlagDefault: 1
|  + EditionUID: 3152495284696511680
|  + ChapterAtom
|   + ChapterUID: 15056966616418343257
|   + ChapterTimeStart: 00:00:00.000000000
|   + ChapterFlagHidden: 0
|   + ChapterFlagEnabled: 1
|   + ChapterTimeEnd: 00:07:57.250000000
|   + ChapterDisplay
|    + ChapterString: Chapter 01
|    + ChapterLanguage: eng
|  + ChapterAtom
|   + ChapterUID: 15253337529613683601
|   + ChapterTimeStart: 00:07:57.250000000
|   + ChapterFlagHidden: 0
|   + ChapterFlagEnabled: 1
|   + ChapterTimeEnd: 00:15:43.000000000
|   + ChapterDisplay
|    + ChapterString: Chapter 02
|    + ChapterLanguage: eng
|  + ChapterAtom
|   + ChapterUID: 1994698034217092959
|   + ChapterTimeStart: 00:15:43.000000000
|   + ChapterFlagHidden: 0
|   + ChapterFlagEnabled: 1
|   + ChapterTimeEnd: 00:23:48.208333333
|   + ChapterDisplay
|    + ChapterString: Chapter 03
|    + ChapterLanguage: eng
|  + ChapterAtom
|   + ChapterUID: 258434961097259531
|   + ChapterTimeStart: 00:23:48.208333333
|   + ChapterFlagHidden: 0
|   + ChapterFlagEnabled: 1
|   + ChapterTimeEnd: 00:31:47.083333333
|   + ChapterDisplay
|    + ChapterString: Chapter 04
|    + ChapterLanguage: eng
|  + ChapterAtom
|   + ChapterUID: 18288776774064417453
|   + ChapterTimeStart: 00:31:47.083333333
|   + ChapterFlagHidden: 0
|   + ChapterFlagEnabled: 1
|   + ChapterTimeEnd: 00:39:34.666666666
|   + ChapterDisplay
|    + ChapterString: Chapter 05
|    + ChapterLanguage: eng
|  + ChapterAtom
|   + ChapterUID: 1173979347969436520
|   + ChapterTimeStart: 00:39:34.666666666
|   + ChapterFlagHidden: 0
|   + ChapterFlagEnabled: 1
|   + ChapterTimeEnd: 00:47:19.208333333
|   + ChapterDisplay
|    + ChapterString: Chapter 06
|    + ChapterLanguage: eng
|  + ChapterAtom
|   + ChapterUID: 11281031232039191669
|   + ChapterTimeStart: 00:47:19.208333333
|   + ChapterFlagHidden: 0
|   + ChapterFlagEnabled: 1
|   + ChapterTimeEnd: 00:56:15.375000000
|   + ChapterDisplay
|    + ChapterString: Chapter 07
|    + ChapterLanguage: eng
|  + ChapterAtom
|   + ChapterUID: 10815360979304430871
|   + ChapterTimeStart: 00:56:15.375000000
|   + ChapterFlagHidden: 0
|   + ChapterFlagEnabled: 1
|   + ChapterTimeEnd: 01:02:14.208333333
|   + ChapterDisplay
|    + ChapterString: Chapter 08
|    + ChapterLanguage: eng
|  + ChapterAtom
|   + ChapterUID: 16809010294411897098
|   + ChapterTimeStart: 01:02:14.208333333
|   + ChapterFlagHidden: 0
|   + ChapterFlagEnabled: 1
|   + ChapterTimeEnd: 01:12:48.291666666
|   + ChapterDisplay
|    + ChapterString: Chapter 09
|    + ChapterLanguage: eng
|  + ChapterAtom
|   + ChapterUID: 8150110444134871576
|   + ChapterTimeStart: 01:12:48.291666666
|   + ChapterFlagHidden: 0
|   + ChapterFlagEnabled: 1
|   + ChapterTimeEnd: 01:18:00.958333333
|   + ChapterDisplay
|    + ChapterString: Chapter 10
|    + ChapterLanguage: eng
|  + ChapterAtom
|   + ChapterUID: 18439445082546892497
|   + ChapterTimeStart: 01:18:00.958333333
|   + ChapterFlagHidden: 0
|   + ChapterFlagEnabled: 1
|   + ChapterTimeEnd: 01:27:29.416666666
|   + ChapterDisplay
|    + ChapterString: Chapter 11
|    + ChapterLanguage: eng
|  + ChapterAtom
|   + ChapterUID: 18327904455893100144
|   + ChapterTimeStart: 01:27:29.416666666
|   + ChapterFlagHidden: 0
|   + ChapterFlagEnabled: 1
|   + ChapterTimeEnd: 01:36:44.208333333
|   + ChapterDisplay
|    + ChapterString: Chapter 12
|    + ChapterLanguage: eng
|+ EbmlVoid (size: 101)
|+ Cluster

Se puede identificar cuatro pistas (track), ubicamos la pista que nos interesa que es la numero tres:

| + A track
|  + Track number: 3 (track ID for mkvmerge & mkvextract: 2)
|  + Track UID: 4506191980823210926
|  + Track type: subtitles
|  + Lacing flag: 0
|  + Codec ID: S_TEXT/UTF8

¿Pero cómo sabemos que es la que buscamos?, por el tipo de pista (track type) el cual indica que es un subtitulo aunque también lo es la pista numero cuatro:

| + A track
|  + Track number: 4 (track ID for mkvmerge & mkvextract: 3)
|  + Track UID: 5025865172156633481
|  + Track type: subtitles
|  + Default flag: 0
|  + Lacing flag: 0
|  + Codec ID: S_VOBSUB
|  + CodecPrivate, length 348
|  + Language: ger
|  + Content encodings
|   + Content encoding
|    + Content compression

Pero esta pista contiene los subtítulos en alemán:

|  + Language: ger

Cuando el lenguaje no esta indicado dentro de la información de la pista quiere decir que se encuentra en ingles. Volvemos a la pista numero tres que es la que interesa y nos enfocamos en la línea donde se encuentra el numero de la pista:

|  + Track number: 3 (track ID for mkvmerge & mkvextract: 2)

En esta se ve el numero dos como identificador de pista (track ID) el cual es util para usarlo con herramientas como el mkvmerge y mkvextract, esta última es la que se utiliza para extraer el contenido de una pista, ya teniendo la información necesario se pude extraer los subtítulos de interés por medio de mkvextract:

mkvextract tracks Shutter.2004.mkv 2:Shutter.2004.srt

Donde tracks indica que lo que se va a extraer es una pista, seguido del nombre del archivo del contenedor Matroska, en este caso Shutter.2004.mkv, luego el identificador de pista (track ID) que es el dos y seguido, por medio de dos puntos, el archivo de salida de los subtítulos Shutter.2004.srt, el nombre de salida pude ser cualquiera, importante decir que si el codec ID de los subtítulos es S_TEXT/UTF8 el archivo de salida es SubRip (.srt). Al ejecutar la herramienta sale el siguiente mensaje:

Extracting track 2 with the CodecID 'S_TEXT/UTF8' to the file 'Shutter.2004.srt'. Container format: SRT text subtitles
Progress: 100%

Donde nos informa todo el proceso que se esta realizando y su respectivo indicador de progreso (progress), al finalizar se obtiene el archivo de subtítulos en ingles que era el objetivo, quedan listo para la sincronización de los subtítulos en español con estos.

Mi objetivo principal de obtener el archivo de subtítulos en ingles era para sincronizar con los subtítulos en español. Los subtítulos en español usados fueron los que se encuentra en Asia-Team y hechos por MalTrain para la versión Shutter (2004) [Promise - pITo], El programa que use para este fin fue el Gnome Subtitules. Para esto no tarde mas de 10 minutos y el resultado lo pueden encontrar acá, sirven muy bien para la versión Shutter 2004 (1080p Bluray x265 HEVC 10bit AAC 5.1 Thai Tigole).
comments powered by Disqus
This website is using cookies to provide a good browsing experience

These include essential cookies that are necessary for the operation of the site, as well as others that are used only for anonymous statistical purposes, for comfort settings or to display personalized content. You can decide for yourself which categories you want to allow. Please note that based on your settings, not all functions of the website may be available.

This website is using cookies to provide a good browsing experience

These include essential cookies that are necessary for the operation of the site, as well as others that are used only for anonymous statistical purposes, for comfort settings or to display personalized content. You can decide for yourself which categories you want to allow. Please note that based on your settings, not all functions of the website may be available.

Your cookie preferences have been saved.