Installing ffmpeg for php - 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.

Related

What exactly is HHVM and/or PHP execution engines?

I've been reading about Facebook's Hack which lead me to reading about HipHop Virtual Machine. I wanted a better understanding of this and could not find a clear definition. Wikipedia defines it as: HipHop for PHP (shortened as HipHop) describes a series of PHP execution engines and improvements created by Facebook. I don't understand what PHP engines are...
So I guess then my question is: What exactly are "PHP execution engines?" and how exactly do the benefit PHP applications?
Thanks!
You can run your PHP code with the standard (Zend) engine that you download from php.net, that works great. If you download WAMP, MAMP, or any of the other pre-packaged PHP & MySQL for your Operating system packages, this is what you're getting.
Alternately you can run (most of[1]) your PHP code with HipHop, that works great.
Which one you're using should be effectively invisible to your end users. Your developers, and operations teams will need to know.
You may choose to use HipHop if you're running a site that gets a lot of traffic. HipHop while not supporting all of the features of PHP, does run a bunch faster. It also has some new features not available in the main PHP distribution mostly to do with type hinting. These can provide some pretty attractive tools to read through your code checking for bugs.
Reasons you may want to use HipHop:
Performance is a big deal for you
The static analysis tools available with HipHop have serious worth to your team
The new features in HipHop but not in Zend PHP are attractive to your team.
Reasons you may want to use Zend PHP
You need an extension not available for HipHop (there's lots of extensions out there, think: gd, curl, imagemagik, etc. Many are available for HipHop now, many aren't).
Your code, or framework is making use of unsupported features.
You have a lot of expertise in hosting your current Webserver & PHP stack, and don't want to start from scratch.
This post goes into some HHVM vs HACK differences, and gives a nice run down: http://www.marco.org/2014/03/21/hack
[1] Not all code that you can run with the regular PHP engine currently works on HipHop. They're working on most of the issues, some they've just decided not to fix (I think variable variables may be an example of this e.g. $$var)

OpenOffice in server mode with PHP on Windows

I am working on a project which requires me to generate documents as docx and then convert to doc and pdf.
This project is written in PHP (using Zend Framework) and running on IIS on Windows (client requirements - definitely not my choice!).
Windows Server
IIS 7.5
PHP 5.3
OpenOffice 3.2
I am researching the ways in which I can carry out the document conversion (including the LiveDocx service) and am currently looking into using OpenOffice running as a service to convert the documents.
I have a PHP script which works -- it is similar to the code in this post How do I convert RTF to PDF from my PHP web page using OpenOffice? -- but I wanted to know how well this will scale. the PHP script is basically a PHP version of the PyOD converter using PHP's COM functions. On this page (http://code.google.com/p/jodconverter/wiki/GettingStarted) it specifically says that the PyOD script is not intended for to work with multiple concurrent connections. I would therefor assume that the PHP script will be equally unsuitable.
Having read around, it seems that the OpenOffice process which is running will only support one connection at a time. Is this definitely correct? If so then am I right in thinking that it is simply not a viable solution? I would be expecting high usage for the product so concurrent conversions are a must. Does anyone have any experience with this in a production environment?
In finishing, does anyone have any other recommendations for carrying out the conversions? If not, I will go back to using the LiveDocx service. My only real gripes with it were speed and some inaccuracies with the conversions.
Thank you in advance for your help.
You probably can scale OpenOffice to do what you require. Having done work directly with the OpenOffice UNO api in the past, you might find you have a lot of work to do though. Trying to use a single OpenOffice process in a multithreaded-fashion only lead me to grief. You can however spawn several OpenOffice processes and single-thread each. It depends on what your performance criteria are as to whether this is going to be scalable enough...
JODReports and Docmosis sit over OpenOffice so it might be worth trying one of these systems out to see if you could potentitally scale to what you require before investing any development effort yourself with the particular technologies. You might also look at LibreOffice which has evolved a little further recently than OpenOffice.
Hope that helps.

compiling PHP 5 to EXE?

i have been using the awesome bambalam: http://www.bambalam.se/bamcompile/ compiler to make exe from php source.
But it's getting old, and it doesn't support php5.
Is there another project that will do the trick?
Thanks
ADD1:
i need only for windows
Please note, this was answered before the OP added the vitally important "I need only for windows" addition to the question.
Well the way Facebook handle this is by compiling to an intermediary language, C++, via a piece of software called HipHop for PHP.
There's also PHC, and a few others. Zend Server caches the bytecode which helps a lot.
You can try exe output, get it here, www.exeoutput.com. It has amazing features supports html, flash, javascript, php, etc.
Give a try to one of these tools:
PHPFlexer, if you only have a single php file (like a quick commandline tool)
RapidEXE, if it's several files/folders; here you can even choose a PHP version
PHC-Win, it's the ancestor of PHPFlexer and works pretty well
ExeOutput, a big monster but it gives you a webserver environment and a nice GUI
ZZEE, despite its silly name it's pretty good but features some oldish PHP
The first 3 is command-line, the last 2 are able to develop a window-based application; but they're slow, sometimes a bit tricky to configure and they also make a big fat exe file that loads relatively slow (especially ExeOutput). Command line ones are pretty compact and easy to use, with an output exe around 2MB.

Finding exact requirements for a php application

I am developing a php application which my customers will download and install on their own servers. I know the base requirements for my application (like min. php version) but is there a way to generate a list of requirements that needed to run my application on windows or unix systems?
Thanks.
You mean, generate a list of requirements based on an analysis of your source code?
While in theory, that might be possible, I don't think such a solution exists. I think there is no way than analyzing your code by hand, with the PHP manual very close by.
Do you use GD? Then you need PHP with the GD module. Do you need to create GIF images with GD? Then you need GD, but not between versions 1.6 and (I think) 1.8. Do you use PDO? Then you need PHP > 5.1.0. And so on and so on.
In short, I'm afraid think this is going to be a manual process. Manual also as in "PHP manual" - the User Contributed Notes to each function and method are a gem, and any common cross-platform problems are usually noted there somewhere.
While you can trust that PHP x.y.z has a defined set of functions and behaviour, be sure to test well before you declare something suitable to run on a different server. IIS's support of PHP is way better now, I'm told, but the last time a ported a big PHP application over to IIS, it took me three days to work around all the mysterious bugs.
Just be aware of what you are using. For example, you should clearly communicate if you need something like .. a special database binding ( other then mysql ), xml libraries etc.., or even better, create an installer that is bundled with your software that checks that kind of stuff.
Other than that, there should be no problems concerning different servers ( apache / iis / fastcgi.. ). So to answer your question: you have to generate that list all by yourself.
As others have said, you'll need to manually keep track of special libraries and functions you're using. If you need PHP4 compatibility then you won't be able to use the built-in XML libraries for example. You can also check the list of functions added to PHP 5.
One thing I would recommend is installing WampServer if you have access to a Windows machine. Aside from being good for local development, you can download modules for most Apache/PHP/MySQL versions and test combinations.

Run Apache / PHP / MySQL (CakePHP) application on a USB stick?

I have an existing CakePHP that runs on a LAMP environment and need to install it on a USB drive for mass public distribution.
There are a few requirements:
Protect the source code
No installation required
Windows support essential
MAC & Linux would be a bonus
Must run offline, without Internet connection
Ability to sync with server for data transfer and updates
I have conducted a large amount of research into the options and am keen to learn what other developers think.
Potential solutions:
- Flash / XML
- Adobe AIR app
- USB webserver (Server2Go, Portable Apps XAMPP)
Has anyone used any of the above, any comments would be greatly appreciated.
Thanks
Similar thread here :
Portable USB Webserver
If you ask me, XAMPP should do, because it offers a "plain unzip" version. There's lots of variety out there - Bitnami also offers a nice bunch of stacks, although they may not be good for this particular task.
To keep the same scripts in both Windows and Linux, you could consider using UnxUtils which is a port of all common Linux commands. This will be very handy if you are good at Linux bash shell scripting but not good at Windows batch files.
Protecting the source code is a bit troublesome. Do you really, really need to do so? Because there's a ton of great open source code out there which already does practically everything in most common business domains - sourceforge.net.
And if someone's taking your code and calling it their own, you can just name them on the internet if you can prove it. That itself will be bad publicity for them. That said, I obviously don't know your specific need. So that is just my opinion.
You will have problems with this, no matter how you go about it. Each step is a little more unusual it seems.
You'll need to use a source code obfuscator to protect your source. I recommend the one by Zend, not from experience, but because Zend makes awesome products. Never used a source protector myself.
You'll need three custom LAMP/MAMP/XAMP installs, one for each target OS. They should point to a directory that is shared on the USB drive. Make sure you configure them to use an unprotected port, otherwise the user will need admin privileges to run the server software. And getting the server stuff up and running will likely result in a few hiccups as well.
I would actually recommend finding something that will allow you to distribute a binary, or something like an AIR app that is intended for this type of distribution. You may have to rewrite lots of code, but it'll be easier to fix than all the niggling little install errors you'll see on the client end. To package scripts into binaries without rewriting stuff, check out http://www.scriptol.com/apollo.php and similar products.
But I'd suggest you make a standalone app in adobe air that will sync with your server (maybe even some google gears integration, to have it function offline). Don't try to force a PHP app into this distribution model, it'll create nightmarish problems.
This is what I used to run a CakePHP app from a DVD. Worked on USB too (while I was still developing it).
http://www.server2go-web.de/
Server2Go is a Webserver that runs out of the box without any installation and on write protected media. This means that web applications based on Server2Go can be used directly from cdrom, a usb stick or from any folder on a hard disk without the hassle of configuring Apache, PHP or MySQL.
Server2Go allows you to create a standalone working web site or PHP application on a CD-ROM.
It's really nice.
You can use MAMP for Mac, you'll just need to edit the config to properly point the sites directory.
however you would have the problem that the mysql db would not necessarily work with windows. if you switched the db to sqlite, you could sync the sqlite db file fairly easily.
XAMPP would work for the windows side
sorry dont know about the linux side.
Out there is a CakePHP InstaWeb Server
http://bakery.cakephp.org/articles/view/the-cakephp-instaweb-webserver
that runs on python and doesn't need an installation. This plus some additional goodies should get you already half the way.

Categories