Skip to content

Instantly share code, notes, and snippets.

@mafredri mafredri/itone.zsh
Created Aug 26, 2017

What would you like to do?
Convert mp3 to m4r (Apple Tone), limit to 39 seconds for use as iPhone ringtone
#!/usr/bin/env zsh
if (( ! ${#@} )); then
print "Convert mp3 to m4r (Apple Tone)"
print "Usage: $0 file1.mp3 file2.mp3"
exit 1
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.