当前位置:Gxlcms > PHP教程 > php获取flv视频时间_PHP教程

php获取flv视频时间_PHP教程

时间:2021-07-01 10:21:17 帮助过:6人阅读

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 << (8 * ($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...

人气教程排行