简体   繁体   中英

Installing ffmpeg for php

I've been searching the internet for over 3 days now and cannot find anything that has a clear explanation of how to install ffmpeg for php. I currently have ffmpeg installed correctly on my Mac command line but as to how to use it in my php scripts is beyond me. How do I install ffmpeg for php? Any help would be great. Thanks.

ffmpeg is a set of executable programs and not an API. There was a project I was aware of in the past that built a php extension, but it was not robust and never really emerged as viable for a number of reasons, not the least of which is that ffmpeg has a lot of different options and builds.

Several years ago I was tasked with building an audio and video encoding system for a social network startup, utilizing PHP as the middleware, so I've been through this exact exercise.

One of the most challenging aspects was coming up with a working compiled version of ffmpeg with all the encoders we wanted to have. In our case our hosted environment was AWS and we were using Amazon linux servers, so there were a few hiccups along the way, and patches I had to chase down. There were packages available that had ffmpeg, but they were hopelessly outdated and missing key features we needed. The only way to get things working was to get the ffmpeg source and compile it, along with the source for the various codecs we were using, primarily to get mpeg4 video and compatible audio. If you aren't comfortable doing this, you will probably not be able to get things working.

In regards to the PHP side of it, I ended up using the PHP-FFMpeg library suggested in the comment above, but I did fork it and made a lot of customizations that worked for us, but were not really contributable back upstream. Subsequently, the maintainer of the library has addressed many of the issues I had and it is a much more robust library now that should save you a lot of problems if you were to try and create your own wrapper.

In summary your server needs:

  • A working compiled version of ffmpeg and its associated helper
    programs which may be of need depending on what you're going to be
    doing with media you are producing. For example, there is a separate media introspection program (ffprobe) that is used to determine the characteristics of media you want to encode.
  • A PSR-0/Composer compatible project. Ours was built on top of Symfony 2.x but that isn't a requirement. I did want to mention it as the project has really pushed the improvement and stability of the symfony component that wraps the php 'exec' function at the heart of any effort to call an external program.

Following the instructions and reading through the API you should be able to get a sample encoding to work with PHP, but keep in mind that ffmpeg works with files, and there are lots of file related issues you have to think through (original files, rendered files and naming, temporary file locations) all of which you'll have to deal with unless you're doing something trivial. In our case these programs were async command line/batch oriented and there was a lot of time and effort that needed to go into figuring out a way to scale and be performant. Needless to say, encoding video can take a lot of time, and is not something you want to do in a monolithic php script where the end user uploads and then waits while you do all the processing in the same script!

I know you are trying to do this on your Mac. Is this really the target environment for your production deployment? This is finicky and platform dependent enough of a process that I don't think it's advisable to try and get a hacky version on your Mac, because the process of getting ffmpeg, and the exact version and components is highly variable and extremely important to your success.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM