51 lines
1.2 KiB
Plaintext
51 lines
1.2 KiB
Plaintext
|
#!/usr/bin/env bash
|
||
|
|
||
|
if which tput >/dev/null 2>&1; then
|
||
|
ncolors=$(tput colors)
|
||
|
fi
|
||
|
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
|
||
|
RED="$(tput setaf 1)"
|
||
|
GREEN="$(tput setaf 2)"
|
||
|
YELLOW="$(tput setaf 3)"
|
||
|
BLUE="$(tput setaf 4)"
|
||
|
MAGENTA="$(tput setaf 5)"
|
||
|
CYAN="$(tput setaf 6)"
|
||
|
BOLD="$(tput bold)"
|
||
|
NORMAL="$(tput sgr0)"
|
||
|
else
|
||
|
RED=""
|
||
|
GREEN=""
|
||
|
YELLOW=""
|
||
|
BLUE=""
|
||
|
MAGENTA=""
|
||
|
CYAN=""
|
||
|
BOLD=""
|
||
|
NORMAL=""
|
||
|
fi
|
||
|
|
||
|
input="$1"
|
||
|
output_name="$2"
|
||
|
|
||
|
if [[ $input == "" || $output_name == "" ]]; then
|
||
|
printf "${BOLD}${RED}Usage: $0 <input video> <wav output name>${NORMAL}\n"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
if [[ ! -f "$input" ]]; then
|
||
|
printf "${RED}${BOLD}Error: failed to extract audio. Video file \"$input\" doesn't exist.\n${NORMAL}"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# Add extension if not provided.
|
||
|
output_basename=$(basename -- "$output_name")
|
||
|
output_extension="${output_basename##*.}"
|
||
|
if [[ $output_extension != "wav" ]]; then
|
||
|
output_name="${output_name}.wav"
|
||
|
fi
|
||
|
|
||
|
printf "\n${YELLOW}${BOLD}Extracting 16-bit WAV from $input | output: $output_name${NORMAL}\n"
|
||
|
|
||
|
ffmpeg -i "$input" -ar 16000 -ac 1 -c:a pcm_s16le "$output_name"
|
||
|
|
||
|
printf "${GREEN}${BOLD}Done extracting 16-bit WAV from $input | output: $output_name${NORMAL}\n"
|