-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflac_24bit_48k.sh
25 lines (23 loc) · 1.26 KB
/
flac_24bit_48k.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
#!/bin/bash
convert_to_24bit_48khz() {
find "$1" -type f -iname "*.flac" -print0 | xargs -0 -I {} bash -c '
file="${1}" # Assign the current file path to the variable "file"
# Check if the file is already 24-bit and 48kHz
bit_depth=$(ffmpeg -i "$file" 2>&1 | grep -oP "Stream.*Audio:.*?(\d+) Hz, \d+ channels, s(\d+)")
sample_rate=$(ffmpeg -i "$file" 2>&1 | grep -oP "Stream.*Audio:.*?(\d+) Hz, \d+ channels, s\d+" | grep -oP "(\d+) Hz")
if [[ $bit_depth =~ s24 && $sample_rate -eq 48000 ]]; then
echo "*************************Skipping \"$file\" (already 24-bit, 48kHz)*************************"
else
# Convert to 24-bit, 48kHz with maximum quality resampling and dithering
echo "---Converting \"$file\" to 24-bit, 48kHz"
if ffmpeg -y -i "$file" -c:a flac -sample_fmt s32 -ar 48000 -af "aresample=resampler=soxr:precision=28:dither_method=triangular" "${file%.flac}_24bit_48khz.flac"; then
mv -v "${file%.flac}_24bit_48khz.flac" "$file"
else
echo "FFMpeg failure, A B O R T i n g"; exit 1
fi
fi
' _ {}
}
# Starting point: current directory or specified directory
start_dir="${1:-.}"
convert_to_24bit_48khz "$start_dir"