Created
September 19, 2016 05:43
-
-
Save gkeramidas/bcd3c735e0e5480208604ae5f04fc579 to your computer and use it in GitHub Desktop.
Convert a clip of an MP3 file to an AAC encoded ringtone
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/sh | |
progname=`basename $0` | |
err() | |
{ | |
code="$1" | |
if test -z "$code" ; then | |
code=1 | |
fi | |
msg="$*" | |
if test -z "$msg" ; then | |
msg="something funny is going on" | |
fi | |
echo >&2 "${progname}: error: ${msg}" | |
exit $code | |
} | |
usage() | |
{ | |
echo >&2 "usage: $progname HH:MM HH:MM INFILE.mp3 OFILE.m4r" | |
exit 64 | |
} | |
start="$1" | |
stop="$2" | |
input="$3" | |
output="$4" | |
test -z "$start" && echo >&2 'start time not specified' && usage | |
test -z "$stop" && echo >&2 'stop time not specified' && usage | |
test -z "$input" && echo >&2 'input file not specified' && usage | |
test -z "$output" && echo >&2 'output file not specified' && usage | |
if test "$input" = "$output" ; then | |
err 1 "input and output cannot be the same file" | |
fi | |
case $output in | |
*.[mM]4[rR]) | |
audio=`echo "$output" | sed -e 's/\.[mM]4[rR]$/.m4a/'` | |
;; | |
*) | |
echo >&2 "output file MUST have an .m4r extension" | |
usage | |
;; | |
esac | |
ffmpeg -ss "$start" -t "$stop" -i "$input" -vn -c:a aac -vbr 4 "$audio" | |
if test $? -ne 0 ; then | |
rm -f "$audio" | |
fi | |
mv "$audio" "$output" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment