Batch converting song files from mp4 to wav.

I just had some very successful assistance from one of the members which saved me hours and hours of headache. Thanks to this great forum (I left a donation…hope it helps…!). Now, to another little challenge…I have 90 gigs of mostly mp4 (apple lossless) files. I want to keep them on my computer for the higher quality for streaming to my airport express/stereo. However, they don’t fit on my 60 gig iPod…plus there’s a home-grown radio station here in the bush in Australia that runs thier music off of wav files on a PC to the few hundred locals…so here’s what I was thinking: It would be great if someone could create a script that took the mp4 files (and a few odd wav, mp3, (AAC??) etc. out of my main drive’s iTunes music library and batch converted them to the smaller wav files in another folder on another drive. That way I could probably fit everything on my iPod and share that drive with the locals…whadya think? Jeffe:/

Model: Powerbook G4 running iTunes 5.01 (4)
Browser: Safari 312.3.1
Operating System: Mac OS X (10.3.9)

I think you’d use qt pro to convert m4a to wav. If you don’t have it already, I think it’s a few bucks from the apple store.

You can use a recent ffmpeg binary to convert out of Apple lossless to wav:

ffmpeg -i ~/Desktop/lossless.m4a ~/Desktop/out.wav

You can either compile ffmpeg from cvs from source yourself (I don’t think you can use fink or darwinports as their versions are too old to have apple lossless (alac) support), or use a pre-built binary in programs like ffmpegx. Further, you can use that same ffmpeg binary to convert out of aac, mp3, ogg, wma(1,2,3) to wav just as easily.

Thanks guys…but I’m new to Apple and scripting. Anyone out there able to/interested in using this info and creating a script for me?

Hi Jeff,

You don’t give specifics, but you can look at this:

tell application “iTunes”
set conv_pl to first playlist whose name is “Converted to Wave”
set conv_files to location of every track of conv_pl
end tell
tell application “Finder”
set conv_folder to (make new folder at desktop with properties ¬
{name:“Wave Files”}) as string
end tell
tell application “QuickTime Player”
launch
activate
end tell
repeat with this_file in conv_files
set {name:file_name, name extension:file_ext} to (info for this_file)
set strip_ext to (“.” & file_ext)
set def_tid to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to strip_ext
set stripped_name to (text items of file_name)
set AppleScript’s text item delimiters to def_tid
set new_name to ((stripped_name as string) & “.wav”)
set file_spec to (conv_folder & new_name) as file specification
tell application “QuickTime Player”
open this_file
tell front movie
stop
rewind
export to file_spec as wave
close
end tell
end tell
end repeat
tell application “QuickTime Player” to quit

converts an iTunes track to wav

The wav file is not necessarilly smaller than the iTunes file.

gl,

specifics would be: converting mp4, WAV, AAC or other music files in iTunes library on hard drive “big guy” to smaller (I checked and you’re right, WAV would be the same size…so, which size would be best to knock off a third of the total size?.. AAC? AAC with some bitrate or other tweaking, or?) format of music files and moving them to iTunes music library on hard drive “USB”. iTunes has a convert all songs option (option button plus convert to …), but they all get placed back in the same library…I’d like that one feature, but where the compressed copies go right into a second folder. That way, the few files that are already in that format won’t get copied over and be lost from the original folder…

Hi Jeffe,

I think AAC would be best because of the small size and higher quality.

Here’s an example using iTunes to convert to AAC and the Finder to duplicate the files from iTunes music folder. First you choose a folder destination for the converted or duplicated files. The script currently uses the selected items from the Library for testing purposes. I lost all my other songs such as purchased songs, so I couldn’t test with other types other than AAC and some tracks that I converted to mp3, but I think it works. When you want to do the whole library, use the commented section instead of the line after.

set conv_folder to choose folder
tell application “iTunes”
activate
– save current encoder
set user_encoder to current encoder
– change encoder to AAC
set current encoder to encoder “AAC Encoder”
(* uncomment this to do the whole library
set lib_pl to first library playlist
set track_list to every track of lib_pl
*)
set track_list to selection – for testing
repeat with this_track in track_list
set file_loc to location of this_track
set did_conv to false
if kind of this_track is not “AAC audio file” then
with timeout of days seconds
set conv_tracks to (convert this_track)
end timeout
set did_conv to true
– converted tracks have a copy index
– so get name of non-AAC track and add extension
set track_name to name of this_track
set file_name to (track_name & “.m4a”)
– get location in Finder
set conv_track to item 1 of conv_tracks
set file_loc to location of conv_track
end if
tell application “Finder” to set dup_file to (duplicate file_loc to conv_folder)
– clean up
if did_conv then
delete conv_track
tell application “Finder” to set name of dup_file to file_name
end if
end repeat
– reset to previous encoder
set current encoder to user_encoder
end tell

Hope it works for you. I rushed on it, so do testing first. You might want to check if any of your tracks have same names or you might get errors when duplicating.

gl,