php flv瑙嗛鏃堕棿鑾峰彇鍑芥暟_PHP鏁欑▼ | 甯涔嬪

WBOY
发布: 2016-07-21 15:36:28
原创
1145 人浏览过

澶嶅埗浠g爜 浠g爜濡備笅:

銆€銆€function BigEndian2Int($byte_word, $signed = false) {
銆€銆€$int_value = 0;
銆€銆€$byte_wordlen = strlen($byte_word);
銆€銆€for ($i = 0; $i 銆€銆€{
銆€銆€$int_value += ord($byte_word{$i}) * pow(256, ($byte_wordlen - 1 - $i));
銆€銆€}
銆€銆€if ($signed)
銆€銆€{
銆€銆€$sign_mask_bit = 0x80 銆€銆€if ($int_value & $sign_mask_bit)
銆€銆€{
銆€銆€$int_value = 0 - ($int_value & ($sign_mask_bit - 1));
銆€銆€}
銆€銆€}
銆€銆€return $int_value;
銆€銆€}
銆€銆€function getTime($name){
銆€銆€if(!file_exists($name)){
銆€銆€return;
銆€銆€}
銆€銆€$flv_data_length=filesize($name);
銆€銆€$fp = @fopen($name, 'rb');
銆€銆€$flv_header = fread($fp, 5);
銆€銆€fseek($fp, 5, SEEK_SET);
銆€銆€$frame_size_data_length =BigEndian2Int(fread($fp, 4));
銆€銆€$flv_header_frame_length = 9;
銆€銆€if ($frame_size_data_length > $flv_header_frame_length) {
銆€銆€fseek($fp, $frame_size_data_length - $flv_header_frame_length, SEEK_CUR);
銆€銆€}
銆€銆€$duration = 0;
銆€銆€while ((ftell($fp) + 1) 銆€銆€$this_tag_header = fread($fp, 16);
銆€銆€$data_length = BigEndian2Int(substr($this_tag_header, 5, 3));
銆€銆€$timestamp = BigEndian2Int(substr($this_tag_header, 8, 3));
銆€銆€$next_offset = ftell($fp) - 1 + $data_length;
銆€銆€if ($timestamp > $duration) {
銆€銆€$duration = $timestamp;
銆€銆€}
銆€銆€fseek($fp, $next_offset, SEEK_SET);
銆€銆€}
銆€銆€fclose($fp);
銆€銆€return $duration;
銆€銆€}
銆€銆€function fn($time){
銆€銆€$num = $time;
銆€銆€$sec = intval($num / 1000);
銆€銆€$h = intval($sec / 3600);
銆€銆€$m = intval(($sec % 3600) / 60);
銆€銆€$s = intval(($sec % 60 ));
銆€銆€$tm = $h . ':' . $m . ':' . $s ;
銆€銆€return $tm;
銆€銆€}
銆€銆€echo getTime("27729.flv");//鏄剧ず鏁板瓧鏃堕棿濡?36722
銆€銆€echo fn(236722); //鏄剧ず鏃堕棿鏍煎紡0:03:56
銆€銆€?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/322136.htmlTechArticle澶嶅埗浠g爜 浠g爜濡備笅: ?php function BigEndian2Int($byte_word, $signed = false) { $int_value = 0; $byte_wordlen = strlen($byte_word); for ($i = 0; $i $byte_wordlen; $i++) { $in...
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!