Streaming Flash Video via PHP

You can ‘stream’ FLVs or you can use ‘progressive download’. Not many of us use ‘streaming’ because you need a streaming media server software for this, like Macromedia Flash Communication Server or Flash Media Server, and this has a considerable cost.

You have two obvious advantages with streaming: you can seek to an arbitrary time in the video (still you land on a key frame, I think) and the file is not cached (and eats your bandwidth every time, but I can see how this is considered an advantage).

Now it’s possible to stream a FLV using a simple PHP script and FLVMDI injected data. Flashcomguru has a great post and sample code in his blog titled: ‘Streaming’ flv video via PHP, take two (I borrowed his title:) ).

This does solve the ‘seek’ problem with progressive downloads (which is huge, depending on who you are asking), but the FLV gets cached (or can be easily retrived), and because currently only our free software FLVMDI 2.7 Beta supports adding the required data, this is Windows only for now.

So how does it work? FLVMDI adds key frame times and file positions to the injected metadata. When user seeks a time, you find the nearest key frame and its file position using the injected metadata and pass the file position to the PHP. The PHP script creates a new FLV header, seeks to the file position and starts sending data from there.

Kudos to Stefan Richter, the  Flashcomguru, and everybody else involved.

This entry was posted in Flash.

7 Responses to Streaming Flash Video via PHP

  1. Narration says:

    Neat. Thanks, Burak.

  2. Also see Frédéric v. Bochmann’s post at:
    He actually contributed the PHP code for writing the FLV header.

  3. Sha says:

    Kudos, Burak!
    As I search in google, I can only see this being done in PHP. Would you have any idea of doing it using C modules in the apache server? I seem to be having problems with the player recognizing from the partial .flv file inspite of adding the header: “4c46 0156 0001 0000 0009 0000? in hex followed by the actual data from the flv file starting from the requested offset.
    Would be glad of any pointers and suggestions…

  4. Some news: has commercial components that use PHP streaming.
    PhilFlash has released ‘Vidéo FLV en PHP Streaming et avec le FLVPlayback’ (Video FLV in PHP Streaming and with FLVPlayback) at (French, Google translations available).

  5. james says:

    php streaming seems to fail miserably on Very large FLV filesizes.. ie 260M.. any fixes or things that need to be done to accomodate this size?

  6. Paul Querna has developed an apache module to allow apache to handle the heavy duty work.
    I think it’s a very cool solution, but at this point I’m still trying to get it to work. While I understand the file seeking in php, I’m not fully sure what’s going on in his apache mod_flvx

  7. Suchit says:

    Is is possible to record audio from flash based web app and store it at server end – without using Flash Media Server?