Skip to content

Instantly share code, notes, and snippets.

@landgenoot
Created February 22, 2024 11:55
Show Gist options
  • Save landgenoot/c472d283ae46ce8f7e104b077a5e3af0 to your computer and use it in GitHub Desktop.
Save landgenoot/c472d283ae46ce8f7e104b077a5e3af0 to your computer and use it in GitHub Desktop.
Convert vobsub to srt subtitles inside mkv
tracks=$(mkvinfo "$1" | gawk '
match($0, /mkvextract: ([0-9]+)/, m) {TN=m[1]} \
match($0, /Language: ([a-z]+)/, m) {CI=m[1]} \
/Track type: subtitles/ {SUB=1} \
/^\| \+ Track$/ {if(SUB) print TN, CI, "\n"; SUB=0;} \
END {if(SUB) print TN, CI; SUB=0}')
IFS=$'\n'
mergecommand=\"$1\"
for track in $tracks
do
IFS=" " read -ra my_array <<< "$track"
echo "Item: ${my_array[0]}"
mkvextract tracks "$1" "${my_array[0]}:${my_array[0]}"
vobsubocr -l ${my_array[1]} -o ${my_array[0]}.srt ${my_array[0]}.idx
rm ${my_array[0]}.idx
rm ${my_array[0]}.sub
mergecommand="${mergecommand} --language 0:${my_array[1]} --track-name 0:${my_array[1]}.srt ${my_array[0]}.srt"
sed -i 's/|/I/g' ${my_array[0]}.srt
done
echo "-o output.mkv -S ${mergecommand}" | xargs mkvmerge
for track in $tracks
do
IFS=" " read -ra my_array <<< "$track"
rm ${my_array[0]}.srt
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment