View Single Post
  #1  
Old 10-07-2012, 09:17 PM
n0risc n0risc is offline
Junior Member
 
Join Date: Oct 2012
Posts: 3
n0risc is on a distinguished road
Default

f4f to f4v php code error


I get a Parse Error on Line 9 of this code.

I found this code on stackoverflow.com and would love to be able to take my .f4f generated files from Adobe Media Server 5.0 (interactive) and covert them to .f4v on the server on the fly to redistribute the content for video on demand.

Is the script below able to be run from the command line? Is this why I'm getting these errors?

Thanks in Advance.

Code:
PHP Parse error:  syntax error, unexpected '[' in /home/videos/f4ftof4v.php on line 9
Code:
<?php
  function ReadInt24($str, $pos)
    {
      return intval(bin2hex(substr($str, $pos, 3)), 16);
    }

  function ReadInt32($str, $pos)
    {
      return unpack("N", substr($str, $pos, 4))[1];
    }

  echo "\nKSV Adobe HDS Downloader\n\n";
  $flvHeader        = hex2bin("464c5601050000000900000000");
  $firstVideoPacket = true;
  $prevTagSize      = 4;
  $fragCount        = 0;

  isset($argv[1]) ? $baseFilename = $argv[1] : $baseFilename = "";
  $baseFilename ? $outputFile = "$baseFilename.flv" : $outputFile = "Joined.flv";
  while (true)
    {
      if (file_exists("$baseFilename" . $fragCount + 1 . ".f4f"))
          $fragCount++;
      else
          break;
    }
  echo "Found $fragCount fragments\n";
  $flv = fopen("$outputFile", "wb");
  fwrite($flv, $flvHeader, 13);

  for ($i = 1; $i <= $fragCount; $i++)
    {
      $frag = file_get_contents("$baseFilename$i.f4f");
      preg_match('/(.{4})mdat[\x08\x09\x12]/i', $frag, $mdat, PREG_OFFSET_CAPTURE);
      $fragLen = ReadInt32($mdat[1][0], 0) - 8;
      $frag    = substr($frag, $mdat[1][1] + 8, $fragLen);
      $pos     = 0;
      while ($pos < $fragLen)
        {
          $packetType  = $frag[$pos];
          $packetSize  = ReadInt24($frag, $pos + 1);
          $packetTS    = ReadInt24($frag, $pos + 4);
          $totalTagLen = 11 + $packetSize + $prevTagSize;
          if (($packetType == "\x08" && $packetSize > 4) or ($packetType == "\x09" && $packetSize > 40) or ($packetType == "\x09" && $firstVideoPacket))
            {
              if ($packetType == "\x09" && $firstVideoPacket)
                  $firstVideoPacket = false;
              fwrite($flv, substr($frag, $pos, $totalTagLen), $totalTagLen);
            }
          $pos += $totalTagLen;
        }
    }

  fclose($flv);
  echo "Finished\n";
?>
Reply With Quote