We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

fris on 12/27/07


Tagged

php file video media


Versions (?)


Who likes this?

9 people have marked this snippet as a favorite

basicmagic
vali29
kdaviesnz
skywalker
adix
jeff
jayjansheskigmailcom
romanos
Nix


get time length of flash video file


Published in: PHP 


Credit goes to http://www.retoxmedia.com for this

  1. <?
  2. function get_flv_duration($file)
  3. {
  4. if(file_exists($file))
  5. {
  6. $handle = fopen($file, "r");
  7. $contents = fread($handle, filesize($file));
  8. fclose($handle);
  9.  
  10. if(strlen($contents) > 3)
  11. {
  12. if(substr($contents, 0, 3) == "FLV")
  13. {
  14. $taglen = hexdec(bin2hex(substr($contents, strlen($contents) - 3)));
  15. if(strlen($contents) > $taglen)
  16. {
  17. $milliseconds = hexdec(bin2hex(substr($contents, strlen($contents) - $taglen, 3)));
  18. $seconds = $milliseconds / 1000;
  19. $duration = date("i:s", $seconds);
  20. return $duration;
  21. }
  22. }
  23. }
  24. }
  25. return false;
  26. }
  27.  
  28. echo get_flv_duration("video.flv");
  29. ?>

Report this snippet 

You need to login to post a comment.