-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.sh
executable file
·150 lines (140 loc) · 4.27 KB
/
convert.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
typeoffirstparameter() { # Is the input parameter lossless or lossy
if [ "$input" == "flac" ] || [ "$input" == "wav" ] || [ "$input" == "alac" ];
then
inputfiletype="lossless"
elif [ "$input" == "mp3" ] || [ "$input" == "libvorbis" ] || [ "$input" == "aac" ];
then
inputfiletype="lossy"
fi
}
typeofsecondparameter() { # Is the output parameter lossless or lossy
if [ "$output" == "flac" ] || [ "$output" == "wav" ] || [ "$output" == "alac" ];
then
outputfiletype="lossless"
elif [ "$output" == "mp3" ] || [ "$output" == "libvorbis" ] || [ "$output" == "aac" ];
then
outputfiletype="lossy"
fi
}
outputogg() { # Change the file extension of the output to ogg instead of libvorbis
if [ "$output" == "libvorbis" ];
then
extension="ogg"
else
extension="$output"
fi
}
inputogg() { # Change the file extension of the output to ogg instead of libvorbis
if [ "$input" == "libvorbis" ];
then
extension="ogg"
else
extension="$input"
fi
}
options() { # List available options
echo "-i {input file type}"
echo "-o {output file type}"
echo "-q {output file bitrate}"
echo "help Print the help dialogue"
}
smallhelp() { # Small help if no parameter is given
echo "No Parameter given"
options
echo "use ./convert.sh help for full documentation"
}
printhelp() { # Full help dialogue
echo "FCF (FfmpegConvertFolder), the bash-script to convert an entire folder with ffmpeg"
echo ""
options
supportedformats
}
supportedformats() { # echo supported formats
echo "Currently supported codecs:"
supportedaudioformats
supportedvideoformats
echo "If some codec you want is missing, please write an issiue at: https://github.com/Nikurasukun/ffmpegconvertfolder/issues"
}
supportedaudioformats() { # echos supported audio formats
echo "audio:"
echo "Lossless: flac, alac, wav"
echo "Lossy: mp3, libvorbis, aac"
}
supportedvideoformats() { # echos supported video formats
echo "video:"
echo "Lossless: None"
echo "Lossy: None"
}
if [ "$1" == "help" ]; # catch the input of help
then
printhelp
else
while getopts i:o:q: flag # get the options
do
case "${flag}" in
i) input=${OPTARG};;
o) output=${OPTARG};;
q) quality=${OPTARG};;
esac
done
typeoffirstparameter
typeofsecondparameter
if [ "$input" == "" ] && [ "$output" == "" ] && [ "$quality" == "" ]; # if no parameter is given
then
smallhelp
elif [ "$inputfiletype" == "lossless" ] && [ "$outputfiletype" == "lossy" ]; # Lossless to Lossy
then
outputogg
mkdir "$output"
for i in *."$input";
do
outputfilename=$(basename "$i" "$input")$extension # get the outputfilename
echo "$outputfilename"
echo "Element: $i"
if [ "$output" == "libvorbis" ]
then
if [ ! -z "$quality" ];
then
ffmpeg -i "$i" -vsync 2 -acodec "$output" -b:a "$quality" "$outputfilename";
else
ffmpeg -i "$i" -vsync 2 -acodec "$output" "$outputfilename";
fi
else
if [ ! -z "$quality" ];
then
ffmpeg -i "$i" -vcodec copy -acodec "$output" -b:a "$quality" "$outputfilename";
else
ffmpeg -i "$i" -vcodec copy -acodec "$output" "$outputfilename";
fi
fi
mv "$outputfilename" ./"$output";
done
elif [ "$inputfiletype" == "lossy" ] && [ "$outputfiletype" == "lossless" ];
then
echo "You are about to convert a lossy file in a lossless format! Do you really want to do this? (y/N)" # abort because of converting lossy to lossless
read shure
if [ "$shure" == "Y" ] || [ "$shure" == "y" ] || [ "$shure" == "yes" ] || [ "$shure" == "Yes" ];
then
inputogg
mkdir "$output"
for i in *."$extension";
do
outputfilename=$(basename "$i" "$extension")$output # get the outputfilename
echo "$outputfilename"
echo "Element: $i"
if [ ! -z "$quality" ];
then
ffmpeg -i "$i" -vcodec copy -acodec "$output" -b:a "$quality" "$outputfilename";
else
ffmpeg -i "$i" -vcodec copy -acodec "$output" "$outputfilename";
fi
mv "$outputfilename" ./"$output";
done
else
echo "Cancel"
fi
else
echo "You entered not supported formats" # if something other is inputed
supportedformats
fi
fi