Audio/video stream recording forums

Attention Visitor:
You may have to register or log in before you can post:
  • Click the register link to sign up.
  • Registered members please fill in the form below and click the "Log in" button.
To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Audio/video stream recording forums > Media file management > Converting audio/video files
Register FAQ Members List Calendar Mark Forums Read

Reply Post New Thread
 
Thread Tools Display Modes
  #1  
Old 10-07-2012, 10: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
  #2  
Old 10-08-2012, 06:39 AM
KSV KSV is offline
Senior Member
 
Join Date: Apr 2011
Posts: 853
KSV is on a distinguished road
Cool

Re: f4f to f4v php code error


where did you find this ancient gem . it was the very first script i wrote for f4f fragment processing. it's for processing the client side fragments sent by server not server side .f4f files. simply renaming those f4f files to f4v or mp4 should work.
Reply With Quote
  #3  
Old 10-08-2012, 12:23 PM
n0risc n0risc is offline
Junior Member
 
Join Date: Oct 2012
Posts: 3
n0risc is on a distinguished road
Default

Re: f4f to f4v php code error


@KSV

So AdobeHDS.php that you've elegantly constructed will not flatten server side .f4f's to a single .f4v?

The reason why I ask is the included tool with Adobe "f4vpp" Post Processing Tool will only output files to 2 gig.

Simply renaming the .f4f to .f4v or .mp4 seems not to work with all the time certain players and especially iOS for HLS streaming.

What could be changed or implemented into the AdobeHDS.php for it to recognize server side f4f's? Is it possible? And if it were, could it parse very large .f4f's?

Thanks for your quick reply.
Reply With Quote
  #4  
Old 10-09-2012, 05:21 PM
n0risc n0risc is offline
Junior Member
 
Join Date: Oct 2012
Posts: 3
n0risc is on a distinguished road
Default

Re: f4f to f4v php code error


@KSV

Would it be worth your while to accept a donation to make AdobeHDS.php script work for serve side .f4f's and flatten them into .flv?

Please let me know.
Reply With Quote
  #5  
Old 10-10-2012, 08:18 AM
KSV KSV is offline
Senior Member
 
Join Date: Apr 2011
Posts: 853
KSV is on a distinguished road
Cool

Re: f4f to f4v php code error


client side f4f fragment files can only contain four types of boxes (abst, asrt, afrt, mdat). i have never looked at server side f4f files so i can't be sure how hard or easy it will be to demux them. probably you can upload some small sample somewhere. there was some talk on ffmpeg irc channel few days ago about implementing servers side f4f processing. you can give it a shot at their irc channel. also you are using the paid professional product of adobe. why don't you kick the balls of their support team for having ridiculous limits of 2gb on video data.
Reply With Quote
Reply Post New Thread
Tags: , , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -6. The time now is 02:55 PM.


Powered by All-streaming-media.com; 2006-2011
vB forum hacked with Zoints add-ons