0

I have a short bash script that is meant to convert a folder full of .mp3 files to .m4r ringtones. I am having trouble figuring out why it is throwing the following error:

"Error: ExtAudioFileCreateWithURL failed ('fmt?')"

#!/bin/bash

cd "/path/to/directory/containing/mp3s"

for i in *.mp3; do
    baseFilename=$( basename ${i} .mp3 )
    afconvert -f m4af ${i} -o "/path/to/new/location/${baseFilename}.m4r"
done

exit 0
notarobot
  • 23
  • 4
  • If the file names contains spaces and characters that are special to the shell that might throw an error, since your variable is not quoted. Use `"$i"` and not `${i}`, the braces is optional but it is not a replacement for quotes. – Jetchisel Sep 07 '21 at 01:14
  • Run the script through [shellcheck.net](https://www.shellcheck.net) and fix what it points out. If that doesn't solve it, try running the command directly (not via the script), and see if it works that way. If it doesn't, troubleshoot that (I have no idea about `afconvert`, so I can't help there). If it does work when you just run the command directly, put `set -x` at the beginning of the script to get an execution trace, and see what it's doing differently. – Gordon Davisson Sep 07 '21 at 04:29

1 Answers1

1

The issue was that I had not specified the output data format. Found a helpful page that lead me to the answer:

http://support.moonpoint.com/os/os-x/audio/afconvert.php

    #!/bin/bash

cd "/path/to/directory/containing/mp3s"

for i in *.mp3; do
    baseFilename=$( basename "${i}" .mp3 )
    afconvert -f m4af "${i}" -d aac "/path/to/new/location/${baseFilename}.m4r"
done

exit 0
notarobot
  • 23
  • 4