This article mainly introduces how to obtain the FLV file in PHP. This article provides the implementation code and how to use the file. For more information, see how to obtain the FLV file Time in PHP, 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.