1

I made a code in php that extracts mp3 audio track from a video file using the exec function to execute ffmpeg.

All works fine on a local server using WAMP on windows. But when deploying the script to the server, I can not run ffmpeg anymore because the server does not have the software.

Is there a class in pure PHP, or an API that is capable of the same or at least the basic ffmpeg functionality?

Vasfed
  • 18,013
  • 10
  • 47
  • 53
Matheus Prado
  • 85
  • 1
  • 7

4 Answers4

2

But when deploying the script to the server, I can not run ffmpeg anymore because the server does not have the software.

It's easy to get ffmpeg on your server:

  1. Download a static build of ffmpeg for Linux, Windows, or OS X.
  2. Point your script to it.
  3. Encode.

See FFmpeg Wiki: PHP.

llogan
  • 121,796
  • 28
  • 232
  • 243
1

EDITED:

As any conversion is very CPU intensive, there is no pure PHP solution and in near future never will be.

mvorisek
  • 3,290
  • 2
  • 18
  • 53
  • If this post answered your question, please mark it as as answer. – mvorisek Feb 16 '16 at 18:18
  • The question already said that ffmpeg isn't installed on the server! –  Feb 16 '16 at 18:48
  • As I have written, any encoding/decoding of video is CPU intensive and external compiled binary is required. So you have to install it. – mvorisek Feb 16 '16 at 18:49
  • So then why are you mentioning the library? If the answer is "no", just say that; don't send the OP down a blind alley trying to install a library that won't work. –  Feb 16 '16 at 19:00
  • @duskwuff ok, I tried to provide best possible answer. The answer is you still need the binary, there is an extentions for PHP and also some wrapper for it. I also edited the answer. – mvorisek Feb 16 '16 at 19:08
1

For conversion you can use https://cloudconvert.com/ that provides rest api and asyncronous conversions.

Dimitrios Desyllas
  • 9,082
  • 15
  • 74
  • 164
0

First your question title mentions "videos", but the question body asks about MP3s, could you please clarify?

Second, just because the server does not have ffmpeg this does not mean you cannot install it. This probably should be the option to pursue - and if the host is that strict, it is unlikely you'd be able to install any other solution anyway.

PHP as a language does not have MP3 decoders, and while it is possible to write one, or even to find one already written, I would avoid it. Parsing multimedia formats is tricky, as recent Stagefright bug in Android proved, so you'd be better using a well-tested and supported frameworks such as GStreamer or FFMpeg.

Also if you need to convert only certain formats such as MP3, you can look at MP3 decoders such as lame.

George Y.
  • 11,307
  • 3
  • 24
  • 25