Subtitles Cheatsheet

Extraction

Mkv files often come with subtitles "buried" within them which are not "hard subbed" (built into the image). These can be extracted with:

mkvextract tracks [input file] [track number]:[output file]  

This will not remove the subtitles from the mkv file.

The easiest way to list the subtitle tracks is by running:

mkvmerge -i [mkv file]  

This may extract an ass or srt file

Conversion

You can convert from ass to srt with this tool. However, I found that it would insert ? characters wherever it found characters it didn't understand. For example there is a special character for three dots ... which is really common.

Synchronization

VLC media player can use g and h to adjust times to see how much of a delay you need

You can shift srt subtitles (even by fractions of a second) with this script:

#!/bin/bash

set -o errexit -o noclobber -o nounset -o pipefail

date_offset="$1"

shift_date() {
    date --date="$1 $date_offset" +%T,%N | cut -c 1-12
}

while read -r line
do
    if [[ $line =~ ^[0-9][0-9]:[0-9][0-9]:[0-9][0-9],[0-9][0-9][0-9]\ --\>\ [0-9][0-9]:[0-9][0-9]:[0-9][0-9],[0-9][0-9][0-9]$ ]]
    then
        read -r start_date separator end_date <<<"$line"
        new_start_date="$(shift_date "$start_date")"
        new_end_date="$(shift_date "$end_date")"
        printf "%s %s %s\n" "$new_start_date" "$separator" "$new_end_date"
        echo "New date"
    else
        printf "%s\n" "$line"
    fi
done

Example usage:

./shifter.sh "+3.5 seconds" < input.srt

References

Author

Programster

Stuart is a software developer with a passion for Linux and open source projects.

comments powered by Disqus