PHP implementation to obtain FLV file Time, _ PHP Tutorial

Source: Internet
Author: User
Tags flv file
PHP implementation to obtain the FLV File time ,. How long does PHP obtain the FLV file? How does PHP obtain the FLV file Time? the answer is to view the FLV file is HEX data after the fopen file and convert it to number. Copy the code as follows: phpfunct PHP time for obtaining FLV files,

How does PHP obtain the FLV file Time? the answer is that the FLV file is HEX data after the fopen file is viewed and converted to number.

The code is as follows:


<? Php
FunctionBigEndian2Int ($ 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 (256, ($ 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;
}

FunctiongetTime ($ 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;
}

Functionget_flv_file_time ($ time)
{
$ Time = getTime ($ 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;
}

?>

Use get_flv_file_time ("your FLV. flv") directly.

Finally, how does PHP get the FLV file Time? the answer is that after the fopen file is viewed, the FLV file is HEX data and converted to number. The code is as follows: php funct...

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.