![]() |
|
This thread is locked; no one can reply to it.
![]() ![]() |
1
2
|
Convert WAV to MP3 through a PHP interface? |
Mark Oates
Member #1,146
March 2001
![]() |
Hey Guys, <background> I want to convert a WAV file to a MP3 file through a php interface. Assuming the file has already been uploaded, I'm guessing I'll need to run some kind of Linux application on the server using exec(). Since I'm not a Linux user, my question is how do I get a program that I need (will I need to compile something?) onto the server so that it works? Or is there a better way? I don't anticipate any restrictions on running an executable. I ran the script: <?php // outputs the username that owns the running php/httpd process // (on a system with the "whoami" executable in the path) echo exec('whoami'); ?> and it output the correct information, so I'll assume the executable functionality is working on my host. -- |
kazzmir
Member #1,786
December 2001
![]() |
Use the lame mp3 encoder. $ lame foo.wav bar.mp3
|
Mark Oates
Member #1,146
March 2001
![]() |
Is a linux executable also a .exe file? -- |
kazzmir
Member #1,786
December 2001
![]() |
No, .exe is for windows. There is a project that can run windows executables on linux, called wine, but you probably don't want that. Do you know what sort of linux server you have, as in what distrobution its running? If you can install stuff on the server then you can try one of these commands Red hat $ sudo yum install lame Debian/ubuntu $ sudo apt-get install lame Gentoo (unlikely) $ sudo emerge lame Otherwise you can download the lame sources and build it locally. Probably something like $ tar -xf lame.tar.gz $ cd lame lame $ ./configure --prefix=~/local && make && make install
|
Mark Oates
Member #1,146
March 2001
![]() |
kazzmir said: Do you know what sort of linux server you have, as in what distrobution its running? I have no idea. I'm using 1and1.com hosting and I just see "Linux Hosting". Everything is remote so I have no interface other than exec() -- |
kazzmir
Member #1,786
December 2001
![]() |
Get an ssh client like putty, http://putty.very.rulez.org/, and try to connect to your host using the same username/password that you use for ftp (presumably you use ftp to transfer new html/php files to the host). If that works then you can run those commands. <edit> Look through this page for more info: http://faq.1and1.com/scripting_languages_supported/ssh_secure_shell/index.html |
Arthur Kalliokoski
Second in Command
February 2005
![]() |
I've used sox and ffmpeg to convert files to/from different audio formats. Try a "whereis sox" and "whereis ffmpeg" to see if they're installed. They all watch too much MSNBC... they get ideas. |
Mark Oates
Member #1,146
March 2001
![]() |
ok, sox and ffmpeg are not installed. I've downloaded and unzipped lame via get and tar and am now trying to install it but got an error "-bash: lame: command not found". lame.bat is in that directory. {"name":"601330","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/2\/1223a6720681af5fcbd98d73bb77f276.png","w":694,"h":124,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/2\/1223a6720681af5fcbd98d73bb77f276"} -- |
Matthew Leverton
Supreme Loser
January 1999
![]() |
Just do ./configure --prefix=~/local && make && make install |
Arthur Kalliokoski
Second in Command
February 2005
![]() |
A file named "lame.bat" sounds like a Windows thing. Use "ls -l" to see which files are executable (the -rwxr-xr-x stuff, the 'x's mean it's executable). They all watch too much MSNBC... they get ideas. |
Mark Oates
Member #1,146
March 2001
![]() |
now I get "configure: error: expected an absolute directory name for --prefix: ~/local" {"name":"601331","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/a\/bae2283dbf42f7061dcdb9208e69c814.png","w":694,"h":124,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/a\/bae2283dbf42f7061dcdb9208e69c814"} -- |
Matthew Leverton
Supreme Loser
January 1999
![]() |
Then replace ~ with your absolute path to your home directory. Highlighting text in putty automatically copies it... |
Mark Oates
Member #1,146
March 2001
![]() |
Matthew Leverton said: Highlighting text in putty automatically copies it... nifty. Ok, I found my abs path with <?php echo realpath(''); ?>, ran the command, a bunch of stuff flew by, and it looked like it compiled. It took about 40 seconds. I'm assuming it installed correctly as I didn't see any error messages, but I'm not able to use lame as a command. (uiserver):u49203781:~/lame-3.98.4 > % lame source_file.wav output_file.mp3 -bash: fg: %: no such job I tried "whereis lame" and it returned "lame:", and made sure source_file.wav is in the lame-3.98.4 directory, but no change. -- |
Arthur Kalliokoski
Second in Command
February 2005
![]() |
Try a "locate lame | grep bin" and see if that's in the stuff that "set | grep PATH" shows. You might have to open ~/.bashrc (or create it) and insert the line [EDIT] Doing it this way would enable you to just type "lame <options>" wherever you were in the directory tree. They all watch too much MSNBC... they get ideas. |
Matthew Leverton
Supreme Loser
January 1999
![]() |
If in same directory: Else: Or wherever you put it. |
kazzmir
Member #1,786
December 2001
![]() |
Sorry, I should have been more explicit. When I wrote $ lame foo.wav bar.mp3 The first '$' just signifies that you are at a shell, you don't actually type it. Furthermore, anything that comes before the $ is just extra information, like your current directory. So putting 'lame' before the $ means you are in the 'lame' directory. lame $ ./configure ...
Some shells use a different character than $. In your case you have a >, so mentally replace $ with > whenever necessary. |
Mark Oates
Member #1,146
March 2001
![]() |
Alrightie, I have successfully converted a wav to mp3! the command I used was: just for the record, these were some key points I learned:
and now... Thanks a lot, everybody. Also, I can now delete the lame.tar.gz and all the stuff in the lame-3.98.4, right? So it's just like I downloaded an installer, like I would on Windows, and now that it's installed I can erase it, right? I'm a newb, in this territory, btw. -- |
Arthur Kalliokoski
Second in Command
February 2005
![]() |
Mark Oates said: ~ is the root (not the absolute path root, however) You should refer to that as your "home" directory. They all watch too much MSNBC... they get ideas. |
Matthew Leverton
Supreme Loser
January 1999
![]() |
Quote: <?php exec("~/local/bin/lame ./source_file.wav ./destination_file.mp3"); ?> Arguments are understood to be relative to the current directory, so the ./ is extraneous on them. The point worth noting is that the local directory is not in the search path for executables unless you explicitly add it. (And few people rarely do that.) Mark Oates said: So it's just like I downloaded an installer, like I would on Windows, and now that it's installed I can erase it, right?
It's just like you downloaded the source, compiled it, and moved the executable to another directory on Windows. If you had root privileges, you wouldn't have had to set the prefix to a local directory, and it would have been installed in /usr/local/bin which would have been part of the search path. |
OICW
Member #4,069
November 2003
![]() |
Quite late I presume, but you could also have a look on php5-ffmpeg module, which allows you to manipulate audio/video within the php code. I would expect that you could convert .wav to .mp3 with that as well. But it depends on two things - one if you are able to install new php modules on your server, two if the module does have that functionality. That would be my 0.02$, I remembered that I've seen this module in repository few days ago when reinstalling ffmpeg. I don't have any experience with it, but could be helpful. [My website][CppReference][Pixelate][Allegators worldwide][Who's online] |
Matthew Leverton
Supreme Loser
January 1999
![]() |
I think that extension is only useful for querying media information. |
Mark Oates
Member #1,146
March 2001
![]() |
Matthew Leverton said: It's just like you downloaded the source, compiled it, and moved the executable to another directory on Windows. That was kind of fun. Any other useful command-line Linux apps out there I should know about? Quote: If you had root privileges, you wouldn't have had to set the prefix to a local directory, and it would have been installed in /usr/local/bin which would have been part of the search path. Ok, that makes sense. Thanks again. [edit] A little foot note, I set it up to run as a background process (via this tutorial) -- |
LennyLen
Member #5,313
December 2004
![]() |
Mark Oates said: Any other useful command-line Linux apps out there I should know about? xeyes
|
BAF
Member #2,981
December 2002
![]() |
xeyes isn't a command-line app, it's an X app. |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Mark Oates said: Any other useful command-line Linux apps out there I should know about? Um, it really depends on what you want to do. Most of them have specific purposes. BAF said: xeyes isn't a command-line app, it's an X app. Over ssh, hopefully X forwarding is on, and it'd work just fine -- |
|
1
2
|