Skip to content

Commit

Permalink
Add count, fix logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kn007 committed Mar 1, 2016
1 parent 45bf985 commit 99b9199
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions converter.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash
# File: converter.sh
# Date: March 1th, 2016
# Time: 23:59:27 +0800
# Date: March 2th, 2016
# Time: 01:33:25 +0800
# Author: kn007 <kn007@126.com>
# Blog: https://kn007.net
# Usage: sh converter.sh silk_v3_file/input_folder output_format/output_folder flag
# Usage: sh converter.sh silk_v3_file/input_folder output_format/output_folder flag(format)
# Flag: not define ---- not define, convert a file
# other value ---- format, convert a folder, batch conversion support
# Requirement: gcc ffmpeg
Expand All @@ -19,33 +19,40 @@ RESET="\e[0m"
# Main
cur_dir=$(cd `dirname $0`; pwd)

if [ ! -r "$cur_dir/silk/decoder" ] ; then
if [ ! -r "$cur_dir/silk/decoder" ]; then
echo -e "${WHITE}[Notice]${RESET} Silk v3 Decoder is not found, compile it."
cd $cur_dir/silk
make && make decoder
[ ! -r "$cur_dir/silk/decoder" ]&&echo -e "${RED}Silk v3 Decoder Compile False, Please Check Your System For GCC."&&exit
echo -e "${WHITE}========= Silk v3 Decoder Compile Finish ========="
[ ! -r "$cur_dir/silk/decoder" ]&&echo -e "${RED}[Error]${RESET} Silk v3 Decoder Compile False, Please Check Your System For GCC."&&exit
echo -e "${WHITE}========= Silk v3 Decoder Compile Finish =========${RESET}"
fi

cd $cur_dir

while [ $3 ]; do
pidof /usr/bin/ffmpeg&&echo -e "${RED}[Error]${RESET} ffmpeg is occupied by another application, please check it."&&exit
[ ! -d "$1" ]&&echo -e "${RED}[Error]${RESET} Input folder not found, please check it."&&exit
TOTAL=$(ls $1|wc -l)
[ ! -d "$2" ]&&mkdir "$2"&&echo -e "${WHITE}[Notice]${RESET} Output folder not found, create it."
ls $1 | while read line; do
$cur_dir/silk/decoder "$1/$line" "$2/$line.pcm" > /dev/null 2>&1
[ ! -f "$2/$line.pcm" ]&&echo -e "${YELLOW}[Warning]${RESET} Convert $line false, maybe not a silk v3 encoded file."&&continue
ffmpeg -y -f s16le -ar 24000 -ac 1 -i "$2/$line.pcm" "$2/$line.$3" > /dev/null 2>&1 &
[ ! -d "$2" ]&&echo -e "${RED}[Error]${RESET} Output folder could not be created, please check it."&&exit
CURRENT=0
echo -e "${WHITE}========= Batch Conversion Start ==========${RESET}"
ls $1 | while read line; do
let CURRENT+=1
$cur_dir/silk/decoder "$1/$line" "$2/$line.pcm" > /dev/null 2>&1
[ ! -f "$2/$line.pcm" ]&&echo -e "[$CURRENT/$TOTAL]${YELLOW}[Warning]${RESET} Convert $line false, maybe not a silk v3 encoded file."&&continue
ffmpeg -y -f s16le -ar 24000 -ac 1 -i "$2/$line.pcm" "$2/${line%.*}.$3" > /dev/null 2>&1 &
while pidof /usr/bin/ffmpeg; do sleep 1; done > /dev/null
rm "$2/$line.pcm"
echo -e "${GREEN}[OK]${RESET} Convert $line To $line.$3 Finish."
done
echo -e "[$CURRENT/$TOTAL]${GREEN}[OK]${RESET} Convert $line To ${line%.*}.$3 Finish."
done
echo -e "${WHITE}========= Batch Conversion Finish =========${RESET}"
exit
done

$cur_dir/silk/decoder "$1" "$1.pcm" > /dev/null 2>&1
[ ! -f "$1.pcm" ]&&echo -e "${YELLOW}[Warning]${RESET} Convert $1 false, maybe not a silk v3 encoded file."&&exit
ffmpeg -y -f s16le -ar 24000 -ac 1 -i "$1.pcm" "$1.$2" > /dev/null 2>&1
ffmpeg -y -f s16le -ar 24000 -ac 1 -i "$1.pcm" "${1%.*}.$2" > /dev/null 2>&1
rm "$1.pcm"
echo -e "${GREEN}[OK]${RESET} Convert $1 To $1.$2 Finish."
echo -e "${GREEN}[OK]${RESET} Convert $1 To ${1%.*}.$2 Finish."
exit

0 comments on commit 99b9199

Please sign in to comment.