-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin2flac2.sh
96 lines (84 loc) · 1.72 KB
/
bin2flac2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
# Convert binary file to flac file
## $1 folder name
## $2 sampling rate
## $3 number of channels
### default 16 bit little endian
## -r to delete bin file after conversion
## -q -loglevel quiet
## -y overwrites flac file if already exist
## -f float encoding instead of int16
## -d .dat instead of .bin
if [ $# -eq 0 ]
then
echo 'bin2flac.sh [folder_path] [fs] [number_of_channels] [outfolder(optional)] [options: -r(delete after convert), -q(quiet logs), -y(overwrite flac if exist), -f(float encoding), -d(.dat file)]'
exit 1
fi
folder="$1"
fs=$2
ch=$3
var_4="$4"
# [outfolder(optional)]
if (( $# > 3 )) && [[ ${var_4:0:1} != "-" ]]
then
outfol="$4"
mkdir $outfol
shift 1
else
outfol="$1_flac"
mkdir $outfol
fi
# [metadata config file]
if (( $# > 3 )) && [[ ${var_4:0:1} != "-" ]]
then
outfol="$4"
mkdir $outfol
shift 1
else
outfol="$1_flac"
mkdir $outfol
fi
shift 3
r=""
loglevel=""
y=""
ENCODING=s16le
filetype=bin
while getopts ":rqyfd" opt; do
case $opt in
r)
r="remove"
;;
q)
loglevel="-loglevel quiet"
;;
y)
y="-y"
;;
f)
ENCODING=f32be
;;
d)
filetype=dat
echo "**********************************"
;;
*)
;;
esac
done
if [ "$r" = remove ]; then
for f in `ls "$folder"/*.$filetype`;
do
outfile="$outfol/${f%%.$filetype}.flac"
outfile=${outfile##*/}
ffmpeg -f $ENCODING -ar $fs -ac $ch -i "$f" -c:a flac $outfol/"$outfile" $y $loglevel && rm "$f"
done
else
for f in `ls "$folder"/*.$filetype`;
do
outfile="$outfol/${f%%.$filetype}.flac"
outfile=${outfile##*/}
ffmpeg -f $ENCODING -ar $fs -ac $ch -i "$f" -c:a flac $outfol/"$outfile" $y $loglevel
done
fi
exit 0