Tags

, , , ,

Recently I needed to find the width and height of  Flash (.flv) movies. To make matters more fun (troublesome) the files were stored and would be served from a remote server. A stint of Google magic lead me to php-flvinfo which will read the meta data from flv files and allow you to pick through it at your leisure. If your flv files are being read from a local disc or from somewhere that PHP supports the fseek function then you should be good to go with something like this:

include APPPATH.'libraries/flvinfo.php';
$flvinfo = new FLVInfo();
  $info = $flvinfo->getInfo('example.flv',true);
  echo print_r($info);

If you need to read a remote flv file you’ll need to edit flvinfo.php. One option is to read the metadata area of the remote file to an in memory temporary file then use this temporary file instead of the remote file.

In flvinfo.php replace lines starting at 118 and ending at the line //read header with this:

// Open file
 $f = fopen($filename,'rb');
 $f2 = fopen('php://temp', 'w+b');
 while (ftell($f2) < 5000) {
 fwrite($f2, fread($f, 5000));
 }
 fclose($f);
 rewind($f2);
 $f = &$f2;

Even though we’re only reading in 5k of data we use the while loop on remote files in PHP because the data could be split across packets and an fread stops at a new packet. NB. this requires PHP 5.1 at least.

Advertisements