I have installed ffmpeg using MacPorts and am trying to work out a script that will convert audio files in a specified folder to mp3 files, outputting the converted files as mp3 files in another folder.
So far the script looks like this:
set convertPath to "Macintosh HD:opt:local:bin:ffmpeg"
set convertCommand to quoted form of POSIX path of convertPath & " -i {infile} -f mp3 -ar 44100 -ab 128 -acodec mp3 - "
tell application "Finder"
set inPath to "Macintosh HD:Users:nick:Desktop:new:"
set outPath to "Macintosh HD:Users:nick:Desktop:new2:"
set myFiles to (files of entire contents of inPath whose name ends with ".m4a") as alias list
repeat with i from 1 to count of myFiles
do shell script convertCommand
end repeat
end tell
With this script I am getting the error : “Can’t make every file of «class ects» of “Macintosh HD:Users:nick:Desktop:new:” whose name ends with “.m4a” into type alias list.”
Another issue is that I am not sure how to define the do shell script command so that it outputs an MP3 file in the output directory.
I was using a command line that works in another app, but probably not suited to the script.
I googled convert mp3 with ffmpeg and the following command was listed for converting from aac to mp3 preserving metadata. I actually want to convert from .m4a (Apple Lossless) but I’m sure it can be adapted:
I am not sure how to enter this command in the script. In a previous script I got working to convert images using ImageMagick and ‘do shell script’ the following line worked:
do shell script convertCommand & quoted form of POSIX path of thisImage & space & quoted form of POSIX path of outPath
But I’m not sure how to adapt this/put this all together for the current script