我被我的 bash 脚本与命令选项的数组卡住了。
我制作了 bash 脚本以从 mkv 文件中提取附件,最后在视频/音频编码后再次将附件合并到 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[*]}
问题,仍然无法用于带有空格的文件名。当我尝试 echo the${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.