Created
February 22, 2024 11:55
-
-
Save landgenoot/c472d283ae46ce8f7e104b077a5e3af0 to your computer and use it in GitHub Desktop.
Convert vobsub to srt subtitles inside mkv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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