[dundee] ffmpeg and PHP FTP functions

James Le Cuirot chewi at aura-online.co.uk
Fri Jun 8 10:53:56 BST 2007


On Fri, 8 Jun 2007 01:51:30 +0000
"chris wyllie" <cgwyllie at googlemail.com> wrote:
>
> It's kinda like a youtube clone in that I need to upload large videos,
> create previews of them by converting, watermark them to keep
> copyright and create a thumbnail.
> 
> ffmpeg was suggested and evidently it's a widely used option for this
> kind of task. The problem is that the hosting plan which has been
> bought already(out of my control) have pulled the plug on ffmpeg
> support as it's a shared environment and was causing resource issues.

A standalone ffmpeg will do the job. You can either bundle it into one
big static binary (about 7MB depending on what you include) or you can
keep some of it in shared libraries, allowing you to link other things
like PHP plugins against it. I can show you how to do that.

But whatever you use will consume a lot of juice and it's extremely
likely that your host will notice and will take action against it. It's
easy enough to execute ffmpeg remotely through SSH in a batch fashion
but is that really what you want to do? The input file would need to be
sent to that other server. The output file would be created on that
other server. You might as well just send the whole request to the
other server in the first place. What you do with the output file then
is up to you. Maybe you could host it from the other server or you could
have it sent to the main server afterwards.

One of the other problems is what you send back to the browser during
the request. If you just let the encoding run first, the browser will
probably time out by the time it's finished. You need to send back a
response first and close the connection before you start the encoding.
Alternatively, you can try and set up some kind of daemon process to
handle the encoding separately. That's what we're doing on our
Rails-based project.

I needed to get some information from the input file before starting
the encoding so I wrote a Ruby extension called FFruby. It gives you
easy access to some of a file's properties through FFrubyFile,
FFrubyAudioStream and FFrubyVideoStream objects. It works through
ffmpeg's libraries, libavformat and libavcodec, so it could potentially
handle encoding as well but that would require quite a bit more work.
If you're interested... http://rubyforge.org/projects/ffruby

James



More information about the dundee mailing list