Which brother can help to annotate this procedure? What to do with it

Source: Internet
Author: User
Tags fread flv file
Which brother can help to annotate this procedure?
The function is to obtain the FLV video time, is the online search, but many places do not understand ...
PHP Code
  function Bigendian2int ($byte _word, $signed = False) {$int _value = 0;                $byte _wordlen = strlen ($byte _word); for ($i = 0; $i < $byte _wordlen; $i + +) {$int _value + = Ord ($byte _word{$i}) * POW ($byte _wordlen-1-$        i));            if ($signed) {$sign _mask_bit = 0x80 << (8 * ($byte _wordlen-1));            if ($int _value & $sign _mask_bit) {$int _value = 0-($int _value & ($sign _mask_bit-1)); }} return $int _value;}    Gets the video's digital time 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) < $flv _data_length) {$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;        }//Convert to 0:03:56 time Format 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");//display digital time such as 236722 echo fn ($t);//Display time format 0:03:56


What do you mean by the Bigendian2int function and the numbers in Gettimes?

------Solution--------------------
According to the FLV file format rules
FLV consists of a file header and a file body, where the file body consists of a series of tag and tag size pairs. Tag includes the tag header and the tag data two parts.
Tag Header's
第5-7 byte is a value of type UI24 that represents the timestamp of the tag (in MS)
The 8th byte is the extended byte of the timestamp, which expands the timestamp to a 32-bit value as the highest bit when the 24-bit value is not sufficient

Just add up this series of timestamps and get the whole play time.

UI24 Type 3 bytes, high in front
So the program has
$int _value + = Ord ($byte _word{$i}) * POW ($byte _wordlen-1-$i));
It's a bad one, and it's got a POW.
You can also modify him, the basic formula
Make incoming string $s with (ord ($s {0}) * + ord ($s {1})) * + ord ($s {2})
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.