Search code examples
phpdatabaseffmpegffmpeg-php

How to incoporate ffmpeg in my audio input upload form


this is not really a question but a request to point me to any starting direction. i have a simple audio upload form which stores the audio to a database or just any folder. I want to start by implementing ffmpeg so before this audio is stored in the folder, it goes through ffmpeg(converted to mp3 for example) and stores the converted version to the folder. Can someone please point me to any tutorial or links where i can start more research. I already installed ffmpeg.exe in xampp much appreciated in advance


Solution

  • Option 1: call ffmpeg.exe

    If you are using PHP, you can call ffmpeg from your script like this:

    $answer = shell_exec("ffmpeg.exe -i input.wav -codec:a libmp3lame -qscale:a 2 output.mp3");
    echo $answer."</br>"; 
    

    In this case, ffmpeg.exe and your input file (input.wav in my case) must be in the same folder as your php script, or you set the directory relative to it.

    input.wav can be any other file, ffmpeg doesn't really care about it, as long as it is a usual audio file.

    Documentation about shell_exec: http://php.net/manual/de/function.shell-exec.php

    Information about mp3 encoding can be found here: https://trac.ffmpeg.org/wiki/Encode/MP3

    Option 2: use PHP library

    There are several php librarys for ffmpeg. But most of them are no longer maintened.

    You could try this one: https://github.com/PHP-FFMpeg/PHP-FFMpeg

    There is a good documentation, but I don't have any experiences with it.