Last active
June 30, 2017 10:09
-
-
Save theAprel/499b2334154d81a8c6fddf9144cdafc6 to your computer and use it in GitHub Desktop.
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
| #!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment