Need help with applescript to convert audio files using ffmpeg

Hi

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.

Could someone help me get this working?

Thanks

Nick

Hi,

inPath is a literal string, not a folder specifier, add the keyword folder

 set myFiles to (files of entire contents of folder inPath whose name ends with ".m4a") as alias list

thanks Stephan

that got me past the set myFiles error. now on to the next error I predicted. I get the following error for the do shell script command:

Finder got an error: FFmpeg version 0.6, Copyright (c) 2000-2010 the FFmpeg developers
built on Sep 26 2010 15:17:18 with gcc 4.2.1 (Apple Inc. build 5646)
configuration: --prefix=/opt/local --enable-gpl --enable-postproc --enable-swscale --enable-avfilter --enable-avfilter-lavf --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libdirac --enable-libschroedinger --enable-libfaac --enable-libfaad --enable-libxvid --enable-libx264 --enable-libvpx --enable-libspeex --enable-nonfree --mandir=/opt/local/share/man --enable-shared --enable-pthreads --disable-indevs --cc=/usr/bin/gcc-4.2 --arch=x86_64
libavutil 50.15. 1 / 50.15. 1
libavcodec 52.72. 2 / 52.72. 2
libavformat 52.64. 2 / 52.64. 2
libavdevice 52. 2. 0 / 52. 2. 0
libavfilter 1.19. 0 / 1.19. 0
libswscale 1.11. 0 / 1.11. 0
libpostproc 51. 2. 0 / 51. 2. 0
{infile}: No such file or directory

what is infile? infile is not defined

good point.

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:

ffmpeg -i audio1.aac -ar 22050 -ab 32 -map_meta_data audio1.mp3:audio1.aac audio1.mp3

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

Nick