2018-12-15 21:23:44 -08:00
|
|
|
#!/usr/bin/bash
|
2018-09-13 15:46:32 -07:00
|
|
|
# Trim an audio file given a startpoint and an endpoint
|
2018-12-15 21:23:44 -08:00
|
|
|
# Dependencies: ffmpeg
|
2018-09-13 15:46:32 -07:00
|
|
|
|
|
|
|
printHelp() {
|
|
|
|
cat << EOF
|
|
|
|
Usage: audiotrim [input file] [start time] [stop time] [output file]
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-h show this help page
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2018-10-22 10:36:02 -07:00
|
|
|
while true; do
|
|
|
|
case "${1}" in
|
|
|
|
'-h'|'--help')
|
2018-09-13 15:46:32 -07:00
|
|
|
printHelp
|
2018-10-22 10:36:02 -07:00
|
|
|
exit
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
shift
|
2018-10-22 10:48:15 -07:00
|
|
|
break
|
2018-10-22 10:36:02 -07:00
|
|
|
;;
|
2018-12-15 21:23:44 -08:00
|
|
|
-*)
|
|
|
|
printf '%s\n' "Unknown option: ${1}"
|
|
|
|
exit 1
|
|
|
|
;;
|
2018-10-22 10:36:02 -07:00
|
|
|
*)
|
|
|
|
break
|
2018-09-13 15:46:32 -07:00
|
|
|
;;
|
|
|
|
esac
|
2018-10-22 10:36:02 -07:00
|
|
|
done
|
|
|
|
|
2018-12-15 21:23:44 -08:00
|
|
|
if [[ ! -x '/usr/bin/ffmpeg' ]]; then
|
2019-01-06 21:20:35 -08:00
|
|
|
printf '%s\n' 'ffmpeg program is not installed' >&2
|
2018-12-15 21:23:44 -08:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-10-22 10:47:24 -07:00
|
|
|
readonly infile="${1}"
|
|
|
|
readonly starttime="${2}"
|
|
|
|
readonly stoptime="${3}"
|
|
|
|
readonly outfile="${4}"
|
|
|
|
readonly format="${1%.*}"
|
|
|
|
|
2018-10-22 10:48:15 -07:00
|
|
|
[[ -z "${infile}" ]] && printf '%s\n' "No file entered." >&2 exit 2
|
|
|
|
[[ ! -f "${infile}" ]] && printf '%s\n' "Not a file: ${infile}" >&2 exit 3
|
2018-09-13 15:46:32 -07:00
|
|
|
|
2018-10-22 10:47:24 -07:00
|
|
|
ffmpeg -i "${infile}" -ss "${starttime}" -to "${stoptime}" -c copy "${outfile:-"${outfile%.*}-trimmed.${format}"}"
|