-
Notifications
You must be signed in to change notification settings - Fork 7
/
convert.sh
executable file
·55 lines (44 loc) · 1.15 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
#!/bin/sh
#
# Convert files to some preferred open formats.
# eg. video files to webm
#
# by Fernando Carmona Varo
#
help() {
echo "usage: ${0##*/} <file(s)>";
}
[ "$1" ] || { help; exit 0;}
#bitrate="-b:a 128k -b:v 512k"
bitrate="-b:a 64k "
while [ "$1" ]; do
fname="$1"
shift
[ -f "$fname" ] || { echo "file doesn't exist: $fname"; exit 1;}
# get file extension in lowercase
fext=$( echo ${fname##*.} | tr '[A-Z]' '[a-z]' )
echo "converting $fname"
case $fext in
avi|mp4|wmv|mkv)
dest="${fname%.*}.webm"
[ -e dest ] && { echo "destination file already exists: $dest"; exit 1;}
ffmpeg -i "$fname" $bitrate "$dest"
;;
png|jpg)
dest="${fname%.*}.webp"
[ -e dest ] && { echo "destination file already exists: $dest"; exit 1;}
cwebp -quiet -m 6 "$fname" -o "$dest"
;;
ogg)
;;
*)
echo "no conversion available for format \"${fext}\": $fname"
esac || {
errors="$errors ${fname}\n"
}
done
if [ "$errors" ]
then
echo "Errors were found in the following files and they were not converted:"
printf "$errors"
fi