#!/usr/bin/env bash # 1st argument is video/audio source mkv # 2nd argument is ass source mkv # 3rd argument is output file # 4th argument is timeshift (in milliseconds) # When it's done, check that the number of fonts attached == largest attachment # # Ignore Error: An attachment with the ID x was not found. ffmpeg -i "$2" -vn -an -c:s copy temp-subtitle.ass mkvextract attachments "$2" `seq 1 100` fontsuffixes="ttf ttc otc otf TTF TTC OTF OTC pfa pfb PFA PFB" array_count=0 for font in $fontsuffixes do for f in *.$font do [ -e "$f" ] || continue myarray+=(--attachment-mime-type application/x-truetype-font --attach-file "$f") ((array_count++)) done done echo "Number of fonts attached: $fontcount" mkvmerge -o temp-preshift.mkv "$1" temp-subtitle.ass "${myarray[@]}" fontcount=0 for font in $fontsuffixes do for f in *.$font do [ -e "$f" ] || continue echo "Attached font $f" fontcount=$((fontcount+1)) rm "$f" done done echo "Number of fonts attached: $fontcount" #The shift assumes that the track 2 is the subtitle track. Otherwise, change the value below subtrack=2 mkvmerge -o "$3" -y $subtrack:$4 temp-preshift.mkv rm temp-preshift.mkv rm temp-subtitle.ass