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

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

程序员文章站 2022-05-30 09:38:08
...
澶嶅埗浠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...