Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jms2k

macrumors newbie
Original poster
Apr 7, 2012
9
0
I'm very new to using Automator (and ffmpeg), but I will try to explain what I'm trying to do.

I need to concatenate 3 .mp3 files (Intro, File, Outro). I want to create an automated process that will allow me to drop any file into the directory and automator will automatically execute the ffmpeg process.

Here is what I have tried (but not working):
*edit* this is using Applescript */edit*
Code:
on run {input, parameters}
	tell application "Terminal"
		do script "cd /Users/xxxxxxx/Documents/itunesu/automator/step2/"
		do script "for f in *.mp3
			do
			cat ../files/intro.mp3 \"$f\" ../files/outro.mp3 > ../step3/\"$f\"
			done" in window 1
	end tell
end run
I've placed the intro/outro.mp3 in a separate directory and am wanting to call them into the concatenate process. Ideally, it would concatenate intro.mp3, $f, outro.mp3 and store it in the next directory (step3), with the same file name that it started with.

*edit 2* I'd also like to remove the .mp3 in directory "step2" once the process is done

Can anyone give me a hand, or point me in a better direction? Please don't flame me too hard! Thanks!!!
 
Last edited:
I just tried this line in Terminal and it seemed to work:

Code:
for f in *.mp3; do cat ../files/intro.mp3 $f ../files/outro.mp3 > ../step3/$f; done

And then I needed to clean the headers, so I ran this in terminal as well:

Code:
for f in *.mp3; do ffmpeg -i $f ../step4/$f; done

This seemed to work, but I can't get Automator to successfully run it. It seems to rush into the next command too quickly, or something?
 
Sorry, I'm kind of talking to myself here, but it's helping me figure things out. I directly copied what I used in Terminal into my Applescript, and it seems to have worked... so far. I don't need quotes around the variable, for starters. Also, putting everything in one line and using the semi-colons must prevent it from skipping ahead or something.
 
Ok, stuck again. I decided to consolidate my first step (that was working) with the rest of my workflow. I came up with this:

Code:
on run {input, parameters}
	tell application "Terminal"
		do script "cd /Users/xxxxxx/Documents/itunesu/auto/step1/"
		do script "for f in *.m4a; do ffmpeg -i \"$f\" -acodec libmp3lame -ab 128k \"../step2/${f%.m4a}.mp3\"; rm $f; done" in window 1
		do script "cd /Users/xxxxxx/Documents/itunesu/auto/step2/" in window 1
		do script "for f in *.mp3; do cat ../files/intro.mp3 $f ../files/outro.mp3 > ../step3/$f; rm $f; done" in window 1
		do script "cd /Users/xxxxxx/Documents/itunesu/auto/step3/" in window 1
		do script "for f in *.mp3; do ffmpeg -i $f ../step4/$f; rm $f; done" in window 1
	end tell
end run

The first step (converting m4a files to mp3) works fine, but then it completely stops after that.
 
Turns out, I don't need all those "do scripts"

Code:
on run {input, parameters}
	tell application "Terminal"
		do script "cd /Users/xxxxxx/Documents/itunesu/auto/step1/; for f in *.m4a; do ffmpeg -i \"$f\" -acodec libmp3lame -ab 128k \"../step2/${f%.m4a}.mp3\"; rm $f; done; cd ../step2/; for f in *.mp3; do cat ../files/intro.mp3 $f ../files/outro.mp3 > ../step3/$f; rm $f; done; cd ../step3/; for f in *.mp3; do ffmpeg -i $f ../step4/$f; rm $f; done"
	end tell
end run

Appears to have worked. If anyone has a better way, Please let me know. It would be nice if I could work within one directory, but I couldn't figure out a good way to do that yet.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.