Skip to content

Instantly share code, notes, and snippets.

@theAprel
Last active June 30, 2017 10:09
Show Gist options
  • Select an option

  • Save theAprel/499b2334154d81a8c6fddf9144cdafc6 to your computer and use it in GitHub Desktop.

Select an option

Save theAprel/499b2334154d81a8c6fddf9144cdafc6 to your computer and use it in GitHub Desktop.

Revisions

  1. theAprel revised this gist Jun 30, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion add-and-shift-subtitles.sh
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ for font in $fontsuffixes
    for f in *.$font
    do
    [ -e "$f" ] || continue
    myarray[array_count]="--attachment-mime-type application/x-truetype-font --attach-file $f"
    myarray+=(--attachment-mime-type application/x-truetype-font --attach-file "$f")
    ((array_count++))
    done
    done
  2. theAprel revised this gist Jun 30, 2017. 1 changed file with 12 additions and 1 deletion.
    13 changes: 12 additions & 1 deletion add-and-shift-subtitles.sh
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,18 @@
    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"
    mkvmerge -o temp-preshift.mkv "$1" temp-subtitle.ass `for font in $fontsuffixes; do for f in *.$font; do [ -e "$f" ] || continue; echo -n "--attachment-mime-type application/x-truetype-font --attach-file $f "; done; done`
    array_count=0
    for font in $fontsuffixes
    do
    for f in *.$font
    do
    [ -e "$f" ] || continue
    myarray[array_count]="--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
  3. theAprel created this gist Jun 30, 2017.
    30 changes: 30 additions & 0 deletions add-and-shift-subtitles.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #!/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"
    mkvmerge -o temp-preshift.mkv "$1" temp-subtitle.ass `for font in $fontsuffixes; do for f in *.$font; do [ -e "$f" ] || continue; echo -n "--attachment-mime-type application/x-truetype-font --attach-file $f "; done; done`
    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