php擷取flv視頻時間_PHP教程

來源:互聯網
上載者:User
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); <

    http://www.bkjia.com/PHPjc/486304.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/486304.htmlTechArticlephp擷取flv時間!有源碼!拿來就可以使用!超級簡單。 ?php function BigEndian2Int( $byte_word , $signed =false){ $int_value =0; $byte_wordlen = strlen ( $byte_word...

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.