Created
June 10, 2022 05:03
-
-
Save youhey/45dc7933f5808659c8b8d2ff55f13e89 to your computer and use it in GitHub Desktop.
wav audio file to ogg format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: | |
# AUDIO_PATH=~/Desktop/working/dir/path sh ./wav2ogg.sh | |
# | |
# @see [FFmpeg](https://ffmpeg.org/) | |
set -Ceuo pipefail | |
cd "$(dirname "$0")" | |
AUDIO_PATH="${AUDIO_PATH:-/tmp/audio}" | |
AUDIO_CHANNELS="2" | |
AUDIO_SAMPLING_FREQUENCY="44100" | |
AUDIO_BITRATE="128k" | |
AUDIO_CODEC="libvorbis" | |
OGG_EXT=".ogg" | |
function confirm() { | |
local message default reply | |
message="${1}" | |
echo "${message}" | |
default="No" | |
read -r reply | |
if [[ -z "${reply}" ]]; then | |
reply="${default}" | |
fi | |
case "${reply}" in | |
Y*|y*) return 0 ;; | |
N*|n*) return 1 ;; | |
*) return 2 ;; | |
esac | |
} | |
function bye() { | |
echo "Bye." | |
return 1 | |
} | |
function raise() { | |
local error | |
error="${1}" | |
echo "${error}" 1>&2 | |
return 1 | |
} | |
if [ ! -e "${AUDIO_PATH}" ] || [ ! -d "${AUDIO_PATH}" ]; then | |
raise 'The path to audio location does not exist.' | |
fi | |
echo "Audio files location: ${AUDIO_PATH}" | |
confirm "Is it OK to convert? [y/N]" || bye | |
ffmpeg -version >/dev/null 2>&1 || raise 'FFmpeg is not installed' | |
for file in $(ls "${AUDIO_PATH}" | grep ".*\.wav$"); do | |
ffmpeg -y -stats \ | |
-i "${AUDIO_PATH}/${file}" \ | |
-vn \ | |
-ac "${AUDIO_CHANNELS}" \ | |
-ar "${AUDIO_SAMPLING_FREQUENCY}" \ | |
-b:a "${AUDIO_BITRATE}" \ | |
-codec:a ${AUDIO_CODEC} \ | |
-f ogg "${AUDIO_PATH}/${file%.wav}${OGG_EXT}" | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment