Jump to content


Submitter

SUPPORT TOPIC File Information

  • Submitted: Nov 20 2007 06:44 PM
  • Last Updated: Dec 13 2007 07:34 PM
  • File Size: 417bytes
  • Views: 14631
  • Downloads: 1,011

Previous Versions

  • 20 Nov 2007 Download FLV Player v2 (Embedded Media Player)
  • 20 Nov 2007 Download FLV Player v2 (Embedded Media Player)

Download FLV Player v2 (Embedded Media Player)

- - - - -



This is version 2 of the FLV Player inspired by code that Hurby originally made for etomite. I have minimized the amount of code needed to get flv (flash) videos embedded in your website. I also developed a simple php-http streaming script that works in conjunction with the flv player to provide pseudo-streaming (although I think it works better than the real thing!).

The snippet:
I assume you will have your flvplayer.swf stored in the "moviez" directory located on the site root (at the same level as index.php). The $output line contains all the magic with the embed call. I have left my flashvars in the code if you want to copy my setup. Notice that I force type "flv" since some of my files are not named flv. For a detailed list of flashvars, please visit:
http://www.jeroenwij...ras/readme.html

To download the JW FLV Player go here:
http://www.jeroenwij...m=JW_FLV_Player

[[flvplayer]]
//$height = '300';	   //default 
//$width = '400';		//default 
//$flv = 'video.flv';	  //default

$swf = 'moviez/flvplayer.swf'; //this is the flv player

// Get variables
$height = (isset($h))? $h : $height;
$width = (isset($w))? $w : $width;
$flv = (isset($vid))? $vid : $flv; 

$output = "<embed src='$swf' width='$width' height='$height' type=\"application/x-shockwave-flash\" allowfullscreen='true' flashvars='file=$flv&usefullscreen=true&type=flv&displayheight=$height&backcolor=0x000000&frontcolor=0xFFFFF0&bufferlength=1&largecontrols=true'>";
 
return $output;

The snippet call looks like this:

[[flvplayer?vid=/moviez/austin_powers.flv&h=368&w=704]]

vid = the location of the video file with respect to the site root.
h = height
w = width

Simple eh?

The above is all you need for progressive downloading.

If you would like php-streaming, the add the following flashvar: "&streamscript=stream.php" i.e. &largecontrols=true&streamscript=stream.php

If you want php-streaming for your flv files, then you first have to encode them with "keyframe" metadata. Use this tool:
http://www.buraks.com/flvmdi/
I'd recommend downloading the GUI and cli. Make sure to check the XML output to see if the metadata was properly inserted (it isn't always with large files).

Now, create a "stream.php" in your "moviez" folder. The flvplayer.swf reads the stream.php located within its own directory.
stream.php
<?php

$file = $_SERVER["DOCUMENT_ROOT"]."/".$_GET["file"];
$pos = (isset($_GET["pos"])) ? intval($_GET["pos"]): 0;

header("Content-Type: video/x-flv");
header('Content-Length: ' . filesize($file));

if($pos > 0) {
print("FLV");
print(pack('C',1));
print(pack('C',1));
print(pack('N',9));
print(pack('N',9));
}

$fh = fopen($file,"r");
fseek($fh, $pos);

fpassthru($fh);

fclose($fh);

exit;

?>

I used fpassthru in the above example because it is the fastest on my server (Dreamhost). Another widely used method is replacing fpassthru with:
while (!feof($fh))
{ echo fread($fh, 8192); @ob_flush(); @flush(); }

It reads the file in chunks of 8192 bytes (the maximum for fread in php v5). But fread actually only serves exactly the right amount of data from the file to fill a network packet. You can also enable bandwidth limiting by lowering the byte rate and/or adding a sleep() statement in the while loop.

That should be it for php-streaming. If it works right then even a large flv file streams almost instantly to any point on the file.

Note: mod_gzip on some server configurations prevents the stream.php from flushing out the data until the entire function is done (which means buffering the entire file!) as an optimization technique. Dreamhost does that, and I had to wait for the Dreamhost servers to process my entire 800MB flv files before they got sent to the browser and flvpalyer. I had them turn off mod_gzip and now the streams are instant and the server isn't buffering my data. (my website is faster too despite losing gzip compression).

Examples:
http://ordorica.org/video

Only the Global Warming Swindle and LC2E have metadata, thus they are the only ones that can stream. The other files just act like progressive downloads. Pretty nice for a 1Mbit stream? :D




Other files you may be interested in ..





  • 248 Total Files
  • 19 Total Categories
  • 50 Total Authors
  • 131,652 Total Downloads
  • TripTracker Gallery Latest File
  • Dean Latest Submitter