views:

114

answers:

2

Specifically, I need to automate the encoding of audio files into mp3 with LAME. You don't need to know LAME to answer this, I could be talking about svn or some other program..

I know how to use LAME on the command line to do this, for one file at a time.

I would like to do this via a php script however, so I can convert a bunch at once (for instance, all the files in a directory)

So what I am confused about, is how I should invoke the program, LAME. I could definitely use shell_exec() http://php.net/manual/en/function.shell-exec.php

But is that a "screwy" way to do it, since I am going through the shell?

Should I be using lame_enc.dll somehow instead, instead of lame.exe?

It seems like I could somehow do it with exec() also http://php.net/manual/en/function.exec.php

But in that case, how would I supply the arguments?

Or is there a better way to do it, maybe a .bat file? I am running windows

Should I be using lame_enc.dll instead of lame.exe somehow?

A: 

It's possible to do it with PHP. Not a typical use case scenario but it can be done. Since you are on Windows, a bat file would be better suited since then you don't need the PHP parser to run the script.

Put the same commands you would run in the console to convert your audio files with LAME in a *.bat. Then run the bat as if it was a regular executable file.

Cesar
Ok. I think I will use .bat file then.According to this:http://windowsitpro.com/article/articleid/13443/how-do-i-pass-parameters-to-a-batch-file.htmlIt looks like I can pass paramaters to a bat file, which is perfect
Jonah
+2  A: 

You can use exec() and specify arguments just like you would on the command line. Other options are outlined on the Program Execution manual page for PHP.

Amber