Good day. My question is: how to implement "online youtube to mp3 converter" using php?
1 answer
This is usually done like this. On php / python (another favorite language) is written to the shell to download files. After uploading the file to the server, a special program on the server begins its conversion. And when the conversion is complete, the script shows the link to the download.
For conversions, ffmpeg is usually used, which is the repository of almost every distribution. But perhaps for better performance, you will have to assemble it for yourself.
Here is an example of how to extract the soundtrack for the seed:
ffmpeg -i vid.flv -acodec copy output.mp3
Why the script itself is not engaged in the formation? but because the scripts for the web should not work long and hard. And the default Apache limits the script’s runtime to 30 seconds.
The general scheme of the system. The user selected the file and uploaded it to the server. The script copied it to the transformation directory. He also added a record to the database stating that such a file, such a user (you can use sessions or user registration).
Special program will be somewhere like this:
повторять: проверить, есть ли записи в базе если нет, подождать немного и перейти в начало цикла иначе: извлечь очередное задание пометить его как "в прогрессе" запустить ffmpeg на преобразование. если преобразование завершено удачно скопировать результат пометить в базе "все ок" и прописать ссылку на результат иначе: пометить в базе "все плохо" удалить начальный файл перейти в начало цикла
The web part, after adding the file for processing, simply launches the page update at intervals of a few seconds / minutes (you need to pick up here) checks the status in the database and shows the progress.