Home Backend Development PHP Tutorial 哪位兄弟能帮忙注解一下这段程序?该怎么处理

哪位兄弟能帮忙注解一下这段程序?该怎么处理

Jun 13, 2016 am 10:13 AM
byte data header length

哪位兄弟能帮忙注解一下这段程序?
功能是取得flv视频的时间,是网上找的,但是很多地方不明白。。。

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->function BigEndian2Int($byte_word, $signed = false) {         $int_value = 0;        $byte_wordlen = strlen($byte_word);                for ($i = 0; $i  $flv_header_frame_length) {       fseek($fp, $frame_size_data_length - $flv_header_frame_length, SEEK_CUR);    }    $duration = 0;    while ((ftell($fp) + 1)  $duration) {          $duration = $timestamp;         }          fseek($fp, $next_offset, SEEK_SET);    }     fclose($fp);    return $duration;    }    //转化为0:03:56的时间格式    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;         } $t = getTime("/tmp/907701336.flv");//显示数字时间如236722 echo fn($t);//显示时间格式0:03:56
Copy after login


对 BigEndian2Int这个函数看不懂,以及getTimes里面的一些数字 有什么意思?

------解决方案--------------------
根据 FLV 文件格式的规定
FLV包括文件头(File Header)和文件体(File Body)两部分,其中文件体由一系列的Tag及Tag Size对组成。Tag包括Tag Header和Tag Data两部分。
Tag Header 的 
第5-7字节为UI24类型的值,表示该Tag的时间戳(单位为ms)
第8个字节为时间戳的扩展字节,当24位数值不够时,该字节作为最高位将时间戳扩展为32位值

只要将这一系列的时间戳加起来就得到了整个播放时间

UI24类型 占 3 个字节,高位在前
所以程序中有 
$int_value += ord($byte_word{$i}) * pow(256, ($byte_wordlen - 1 - $i));
这个写法很烂,还用到了 pow
你也可以修改他,基础算式
令传入串 $s,有 ( ord($s{0}) * 256 + ord($s{1}) ) * 256 + ord($s{2})
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What does linux header mean? What does linux header mean? Jul 18, 2023 pm 03:34 PM

The Linux header refers to the beginning of a file or data stream, which is used to contain metadata about the content. By correctly writing and using Header files, developers can better utilize system resources and improve code readability and Maintainability.

How does SpringBoot pass parameters in the Header through Feign calls? How does SpringBoot pass parameters in the Header through Feign calls? May 16, 2023 pm 08:38 PM

[SpringBoot] Passing parameters in the Header through Feign calls How to pass Header parameters through Feign Problem description When we use Feign to request the Api interface of another service in Spring Cloud, there is a need to pass the parameters in the Header. If no special processing is done, it will The parameters in the Header will be lost. Solution 1: Pass it through @RequestHeader(name="headerName"). For example: Feign is defined as follows @FeignClient(name="service-name")pub

Use java's String.length() function to get the length of a string Use java's String.length() function to get the length of a string Jul 25, 2023 am 09:09 AM

Use Java's String.length() function to get the length of a string. In Java programming, string is a very common data type. We often need to get the length of a string, that is, the number of characters in the string. In Java, we can use the length() function of the String class to get the length of a string. Here is a simple example code: publicclassStringLengthExample{publ

What is the difference between html5 tag head and header? What is the difference between html5 tag head and header? Jan 17, 2022 am 11:10 AM

Differences: 1. The head tag is used to define the head of the document, which is a container for all head elements, and the header tag is used to define the header (introduction information) of the document; 2. All browsers support the head tag, and older versions of browsers None of the browsers support the header tag, and browsers such as IE9+ and above are required to support the header tag.

Golang function byte, rune and string type conversion skills Golang function byte, rune and string type conversion skills May 17, 2023 am 08:21 AM

In Golang programming, byte, rune and string types are very basic and common data types. They play an important role in processing data operations such as strings and file streams. When performing these data operations, we usually need to convert them to each other, which requires mastering some conversion skills. This article will introduce the byte, rune and string type conversion techniques of Golang functions, aiming to help readers better understand these data types and be able to apply them skillfully in programming practice.

1byte equals how many bits 1byte equals how many bits Mar 19, 2021 pm 02:52 PM

1byte equals 8bit. Data storage is in "byte" (Byte) as the unit, and data transmission is mostly in "bit" (bit) as the unit. One bit represents a 0 or 1 (that is, binary), and every 8 bits (bit) form a Byte is the smallest unit of information; therefore, "1Byte=8bit".

How to use PHP header() method to adjust web pages How to use PHP header() method to adjust web pages Mar 28, 2023 pm 01:54 PM

PHP is a powerful programming language that can be used to create dynamic websites and web applications. One of the most powerful features is PHP’s header() method. In this article, we will explore how to use PHP’s header() method to adjust web pages.

How to jump in php header How to jump in php header Dec 02, 2022 am 09:14 AM

How to implement jump in php header: 1. Use "Header("Location:$url");" syntax to implement jump; 2. Use if judgment to implement jump, with jump statements such as "if($_COOKIE[" u_type"]){ header('location:register.php'); } else{ setcookie('u_type','1','86400*360');".

See all articles