欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php获取flv视频时间_PHP教程

程序员文章站 2022-05-31 20:17:42
...
php获取flv时间!有源码!拿来就可以使用!超级简单。
  1.   function BigEndian2Int($byte_word, $signed = false) {
  2.   $int_value = 0;
  3.   $byte_wordlen = strlen($byte_word);
  4.   for ($i = 0; $i $byte_wordlen; $i++)
  5.   {
  6.   $int_value += ord($byte_word{$i}) * pow(256, ($byte_wordlen - 1 - $i));
  7.   }
  8.   if ($signed)
  9.   {
  10.   $sign_mask_bit = 0x80 $byte_wordlen - 1));
  11.   if ($int_value & $sign_mask_bit)
  12.   {
  13.   $int_value = 0 - ($int_value & ($sign_mask_bit - 1));
  14.   }
  15.   }
  16.   return $int_value;
  17.   }
  18.   function getTime($name){
  19.   if(!file_exists($name)){
  20.   return;
  21.   }
  22.   $flv_data_length=filesize($name);
  23.   $fp = @fopen($name, rb);
  24.   $flv_header = fread($fp, 5);
  25.   fseek($fp, 5, SEEK_SET);
  26.   $frame_size_data_length =BigEndian2Int(fread($fp, 4));
  27.   $flv_header_frame_length = 9;
  28.   if ($frame_size_data_length > $flv_header_frame_length) {
  29.   fseek($fp, $frame_size_data_length - $flv_header_frame_length, SEEK_CUR);
  30.   }
  31.   $duration = 0;
  32.   while ((ftell($fp) + 1) $flv_data_length) {
  33.   $this_tag_header = fread($fp, 16);
  34.   $data_length = BigEndian2Int(substr($this_tag_header, 5, 3));
  35.   $timestamp = BigEndian2Int(substr($this_tag_header, 8, 3));
  36.   $next_offset = ftell($fp) - 1 + $data_length;
  37.   if ($timestamp > $duration) {
  38.   $duration = $timestamp;
  39.   }
  40.   fseek($fp, $next_offset, SEEK_SET);

    www.bkjia.comtruehttp://www.bkjia.com/PHPjc/486304.htmlTechArticlephp获取flv时间!有源码!拿来就可以使用!超级简单。 ?php function BigEndian2Int( $byte_word , $signed =false){ $int_value =0; $byte_wordlen = strlen ( $byte_word...