哈哈,下次才修改註釋,這是我自己的一個實習寫的SHELL腳本,現在還在加工測試。
[root@localhost source]# cat /tmp/translation.sh
#!/bin/bash
#writed by mojigan
#2012-4-23
#GO=$(ps aux | grep "translation.sh" | grep -v "grep" &> /dev/null| wc -l)
#[ "$GO" -gt 1 ] && exit
#if [ "$GO" -gt 1 ];then
# exit 1
#fi
input_dir=/tmp/aa
trans_dir=/tmp/bb
output_dir=/tmp/cc
fail_dir=/tmp/fail
fail_tran_log=/tmp/fail_tran_log
success_log=/tmp/success_log
other_log=/tmp/other_log
[ ! -d $input_dir ] && mkdir $input_dir
[ ! -d $trans_dir ] && mkdir $trans_dir
[ ! -d $output_dir ] && mkdir $output_dir
[ ! -d $fail_dir ] && mkdir $fail_dir
translation() {
mv $input_dir/$1 $trans_dir
for format in 640x320 320x240 176x144
do
[ "$format" = "640x320" ] && size=bi
[ "$format" = "320x240" ] && size=mi
[ "$format" = "176x144" ] && size=sm
ffmpeg -threads 4 -y -i $trans_dir/$1 -r 12 -vcodec libx264 -bf 0 -s $format -flags +loop -cmp +chroma -deblockalpha 0 -deblockbeta 0 -b 250k -bt 250k -refs 3 -coder 0 -me_method hex -me_range 32 -subq 8 -nr 500 -partitions +parti4x4+parti8x8+partp8x8 -g 60 -keyint_min 6 -level 12 -qmin 10 -qmax 51 -qcomp 0 -acodec libfaac -ab 16000 -ar 22050 -ac 1 $trans_dir/$2_$size.3gp &> /dev/null
if [ $? -eq 0 ];then
[ ! -d "$output_dir/$2" ] && mkdir $output_dir/$2 &>/dev/null
[ ${size} = "sm" ] && rm $trans_dir/$1
mv $trans_dir/$2_$size.3gp $output_dir/$2
echo "$input_dir/$1 is successfully translation." >> $success_log
else
echo "the file of $input_dir/$1 translations fail." >> $fail_tran_log
mv $trans_dir/$1 $fail_dir
fi
done
}
for filename in $(ls $input_dir | awk -F"." 'NF==2{print}')
do
while true
do
temp=$(ps aux | grep ffmpeg | grep -v grep | wc -l)
if [ "$temp" -gt 3 ];then
exit
else
break
fi
done
part1=$(echo $filename | awk -F"." '{print $1}')
part2=$(echo $filename | awk -F"." '{print $2}')
case "$part2" in
"rwvb")
translation $filename $part1
;;
"mp4")
translation $filename $part1
;;
"avi")
translation $filename $part1
;;
"mkv")
translation $filename $part1
;;
"flv")
translation $filename $part1
;;
"mp3")
translation $filename $part1
;;
*)
echo "it don't knowk the type about the $input_dir/$filename ." >>$other_log
mv $input_dir/$filename $fail_dir
;;
esac
done