Hi,

I have limited experience of using PHP, but having done some searching around it would seem that it is possible to convert audio files that are uploaded through a web page to mp3 using ffmpeg. The audio files would be uploaded using the Uploadify script to subfolders that are named according to the user's login.

I would need the PHP script to be able to process all audio files that are either not in MP3 format, or are in MP3 format but greater than 192kbps, deleting the original file after the conversion. Am I right in thinking that this could be achieved using PHP, and if so, can anyone get me started with some code, or a link to a webpage with some code?

Also, I am currently using Hostpapa for hosting my website, and I understand that they don't include ffmpeg, and also don't allow ssh. I read on one website that I could still install a compiled version of ffmpeg on a shared server, but I am not sure if this means that it would work on Hostpapa, or whether I would need to change my host to get ffmpeg working.

Any advice on any of this would be welcome!

Thanks,

Nick

    You can do it using PHP and FFMPEG if you know the following items:

    1. You can execute commands in PHP using either the backtick operator or the [man]exec/man command.

    2. You have read/write access to where the files are stored and will be written to.

    3. You have execute permissions to the ffmpeg binary

    4. You know the ffmpeg parameters which will be used to convert/downgrade the original file to the format/quality you want.

    Basically, you would just run the [man]exec/man command via a PHP script which would execute the proper ffmpeg command.

    Utilize the ffmpeg manual entry to construct your command. Test it out on a local linux server on a couple test files to make sure they work. If it doesn't work via CLI, it won't work in the PHP implementation (since it's just a PHP wrapper to the CLI).

      Note that item #1 above could be avoided if you have something like the ffmpeg-php (unmaintained) extension available instead.

        Seeing as it hasn't been updated since 2007, I'd be surprised if it still really supports any recent release of ffmpeg. But it's worth a shot if you can install it (or your host will install it).

          12 days later

          I have never been able to get FFmpeg working with exec() for some reason. If you can't either, then know you can do it using the popen() and pclose() commands.

          I'm using it now to run FFmpeg from PHP and convert video files to .flv. It works perfectly, except for one small issue: if you close the process immediately, your page will load, but you have no way of knowing when the conversion is complete. If you leave the process open, you can read from it and get the current conversion status, but then your page will hang blank until the conversion is finished and the process ends.

          It's a catch-22 that I'm working on getting around, but for small audio files the conversion shouldn't take too long.

          Anyway, the code I'm using:

          pclose(popen('ffmpeg -i ORIGINAL_FILE.MP4 -ar 22050 NEW_FILE.FLV 2>&1', 'r'));

          (I'm actually trying to monitor the status, but like I said, you don't need to do that for audio files that will convert quickly).

          -IMP 😉 🙂

            a year later

            Thanks for these helpful answers. This project has laid dormant for a while, but I have now switched the site to a new host which has ffmpeg and ffmpeg-php preinstalled. So now I need to work out how to write the script to handle the conversions. As stated in my original question, I am using uploadify to handle the uploads, and then I would want the conversion triggered when new files are created in subdirectories. Any help with this would be appreciated.

            Nick

              2 months later

              Thanks for excellent tips. I am very interesting to download flac music. But can you tell me please how can I download it. I have got this website-

              converting flac to mp3

                Write a Reply...