modern_lisp-machine/misc/scripts/shrink_audio.sh

41 lines
1.0 KiB
Bash
Executable File

EXEC_SHELL_PATH=$(command -v bash)
if [ $# -ne 1 ]; then
echo "Usage: $0 <input_folder>"
exit 1
fi
input_folder="$1"
temp_folder="/dev/shm" # Use tmpfs to store files in RAM
# Function to convert and delete a single file
convert_and_delete() {
local input_file="$1"
local output_file="$(dirname "$input_file")/$(basename "${input_file%.*}")_converted.ogg"
# Copy the input file to RAM and stream it to ffmpeg
cat "$input_file" | \
ffmpeg -i pipe: -c:a libopus -b:a 16k -map_metadata 0 -id3v2_version 3 -threads 32 "$output_file"
echo "Conversion complete. Output file: $output_file"
# Delete the original file after conversion
rm "$input_file"
echo "Original file deleted: $input_file"
}
export -f convert_and_delete
# Find all audio files (adjust the file types as needed)
find "$input_folder" -type f \( -iname "*.mp3" -o -iname "*.wav" -o -iname "*.flac" -o -iname "*.ogg" \) -exec bash -c '
convert_and_delete "$0"
' {} \;
echo "All conversions and deletions complete."