コマンドのオプションに配列を使用したbashスクリプトを理解するのに行き詰まっています。
mkv ファイルから添付ファイルを抽出するための bash スクリプトを作成し、最後にビデオ/オーディオのエンコード後にその添付ファイルを mkv ファイルに再度マージします。
これは抽出アタッチメント用です
#find the total of attachment
A=$(mkvmerge -i input.mkv | grep -i attachment
| awk '{printf $3 "\n"}'
| sed 's;\:;;'
| awk 'END { print NR }')
#extract it
for (( i=1; i<=$A; i++ ))
do
font[${i}]="$(mkvmerge -i input.mkv | grep -i attachment
| awk '{for (i=11; i <= NF; i++) printf($i"%c" , (i==NF)?ORS:OFS) }'
| sed "s/'//g"
| awk "NR==$i")"
mkvextract attachments input.mkv $i:"${font[${i}]}"
done
そして今、添付ファイルを再度マージします
for (( i=1; i<=$A; i++ ))
do
#seach for space between file name and and '\' before
#the space because some attachment has space in filename
font1[${i}]=$(echo ${font[${i}]} | sed 's/ /\\ /g')
#make option for add attachment
attachment[${i}]=$"--attach-file ${font1[${i}]}"
done
mkvmerge -o output.mkv -d 1 -S test.mp4 sub.ass ${attachment[*]}
問題は、スペースを含むファイル名ではまだ機能しません。をエコーしてみたところ${attachment[*]}
、大丈夫そうです
--attach-file Beach.ttf --attach-file Candara.ttf
--attach-file CASUCM.TTF
--attach-file Complete\ in\ Him.ttf
--attach-file CURLZ_.TTF
--attach-file Frostys\ Winterland.TTF
--attach-file stilltim.ttf
ただし、出力では、最初の単語のみにスペースがあるファイル名が引き続き認識されます。
mkvmerge v3.0.0 ('Hang up your Hang-Ups') built on Dec 6 2010 19:19:04
Automatic MIME type recognition for 'Beach.ttf': application/x-truetype-font
Automatic MIME type recognition for 'Candara.ttf': application/x-truetype-font
Automatic MIME type recognition for 'CASUCM.TTF': application/x-truetype-font
Error: The file 'Complete\' cannot be attached because it does not exist or cannot be read.