-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio-reencode.sh
More file actions
executable file
·86 lines (67 loc) · 2.54 KB
/
Copy pathaudio-reencode.sh
File metadata and controls
executable file
·86 lines (67 loc) · 2.54 KB
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
#!/bin/bash
echo -e "--------------\nAUDIO REENCODE\n--------------"
echo "Converts every audio file in the current folder"
echo "(including the files in subfolders) to the selected"
echo "audio format."
echo
if ! which ffmpeg &> /dev/null
then
echo "Install ffmpeg to continue."
exit
fi
# change working dir to current dir
cd -- "$(dirname "$0")"
(
IFS=$'\n' # internal file separator for the for loop below
echo "Choose an audio codec (mp3, ogg, aac, opus):"
select ACODEC in "libmp3lame" "libvorbis" "libfdk_aac" "libopus"; do
break
done
echo "Choose a bitrate:"
select ABITRATE in "8k" "12k" "16k" "24k" "32k" "48k" "64k" "96k" "128k" "192k" "256k" "320k"; do
break
done
echo "Number of audio channels:"
select ACHANNELS in "1" "2" "0"; do
break
done
echo "Number of CPU threads (FIRST OPTION 1): 0=auto ):"
select THREADS in "0" "1" "2" "4" "8" "16"; do
break
done
echo "Do you want to delete original files after conversion?"
select DELETE in "yes" "no"; do
break
done
##########################################
FILES=$(find ./ -not -path '*/.*' \( -name "*.mp3" -o -name "*.MP3" -o -name "*.ogg" -o -name "*.OGG" -o -name "*.m4a" -o -name "*.M4A" -o -name "*.wav" -o -name "*.WAV" -o -name "*.wma" -o -name "*.WMA" -o -name "*.flac" -o -name "*.FLAC" -o -name "*.amr" -o -name "*.AMR" \) | sort -V)
for file in $FILES
do
# skip if already compressed
if echo "$file" | grep -q "\.compressed\."; then
echo "SKIP"
continue
fi
# Check if the file contains an apostrophe, if so then rename
if [[ "$file" == *"'"* ]]; then
new_filename=$(echo "$file" | tr -d "'") # remove apostrophe
mv "$file" "$new_filename"
file=$new_filename
fi
# aac_he_v2: tailored fo low bitrate audio, csak stereo, legkisebb 32kbps
ffmpeg -i input.mp3 -c:a libopus -b:a 16k -ac 1 output.opus
if [ "$ACODEC" = "libmp3lame" ]; then
ffmpeg -i "$file" -c:a "$ACODEC" -b:a "$ABITRATE" -ac "$ACHANNELS" "$file.compressed.mp3" -y;
elif [ "$ACODEC" = "libvorbis" ]; then
ffmpeg -i "$file" -c:a "$ACODEC" -b:a "$ABITRATE" -ac "$ACHANNELS" "$file.compressed.ogg" -y;
elif [ "$ACODEC" = "libfdk_aac" ]; then
ffmpeg -i "$file" -c:a libfdk_aac -profile:a aac_he_v2 -b:a "$ABITRATE" -ac "$ACHANNELS" -vn "$file.compressed.m4a" -y;
elif [ "$ACODEC" = "libopus" ]; then
ffmpeg -i "$file" -c:a "$ACODEC" -b:a "$ABITRATE" -ac "$ACHANNELS" "$file.compressed.ogg" -y;
fi
if [ "$DELETE" = "yes" ]; then
rm "$file"
fi
done
echo "Press ENTER to exit"; read enter
)