Created
August 26, 2017 07:17
-
-
Save mafredri/879719183989c2466154c460b66b5451 to your computer and use it in GitHub Desktop.
Convert mp3 to m4r (Apple Tone), limit to 39 seconds for use as iPhone 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
#!/usr/bin/env zsh | |
if (( ! ${#@} )); then | |
print "Convert mp3 to m4r (Apple Tone)" | |
print "Usage: $0 file1.mp3 file2.mp3" | |
exit 1 | |
fi | |
tmpdir=$(mktemp -d) | |
trap 'exit 1' INT | |
trap 'print Cleaning up...; rm -r $tmpdir' EXIT | |
for i in $@; do | |
print Converting: ${i:r} | |
ffmpeg_out=$(ffmpeg -t 39 -i $i -acodec copy $tmpdir/$i 2>&1) | |
(( ? )) && { | |
print "ffmpeg failed:" | |
print -- $ffmpeg_out | |
exit 1 | |
} | |
af_out=$(afconvert -v -f m4af -q 127 $tmpdir/$i ${i:r}.m4r) | |
(( ? )) && { | |
print "afconvert failed:" | |
print -- $af_out | |
exit 1 | |
} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment