views:

54

answers:

2

Hi, I want to convert and show video that user uploaded. I have dedicated server and i use php for programming. Where should i start ? Thank You

+4  A: 

Hi,

This is probably the way I would do it :

  • have a PHP webpage that adds a record in database to indicate "this file has to be processed" -- this page is the one that receives the uploaded file
    • and displays a message to the user ; something like "your file will be processed soon"
  • In CLI (as you have a dedicated server, you can use command line, install programs, ...), have a batch that processes the new inserted files
    • first, mark a record as "processing"
    • do the conversion things ; ffmpeg would probably be the right tool for that -- I've seen quite a few posts on SO about it, so you might find some informations about that part :-)
    • mark the file as "processed"
  • And, on some (other ?) webpage, you can show to the user in which state his file is :
    • if it has not been processed yet
    • if it's being processed
    • or if it's been processed -- you can then give him the link to the new video file -- or do whatever you want/need with it.


Here's a couple of other notes :

  • The day your application becomes bigger, you can have :
    • one "web server"
    • many "processing servers" ; in your application, it's the ffmpeg thing that will require lots of CPU, not serving web pages ; so, being able to scale that part is nice (that's another reason to "lock" files, indicating them as "processing" in DB : that way, you will not have several processing servers trying to process the same file)
  • You only use PHP from the web server to generate web pages, which is je job of a web server
    • Heavy / long processing is not the job of a web server !
    • The day you'll want to switch to something else than PHP for the "processing" part, it'll be easier.

Your "processing script" would have to be launch every couple of minutes ; you can use cron for that, if you are on a Linux-like machine.


Of course, you could also call ffmpeg directly from the PHP page to which the file is uploaded to... But, considering this might require quite some CPU time, it might not always be a suitable solution...

... Even if a bit easier, and will allows users to get their converted video quickier (they won't have to wait until the cron job has been executed)


(disclaimer : this answer is adapted from another one I made there)

Pascal MARTIN
Well conceived and put together. +1
kersny
Nice answer, very informative - I'm bookmarking it.
Arms
+3  A: 

It's pretty easy. Once uploaded, you'd want to use exec() to call a video converter - ffmpeg is a popular, free, open-source choice.

In its simplest form:

exec('ffmpeg -i /path/to/video.avi /path/to/flash/video.flv');

ceejayoz
Yea, this is what most ppl do with converting media files (video, photos, etc.) +1
bLee