Copy CodeThe code is as follows:
// +----------------------------------------------------------------------+
// | PHP version 4&5 |
// +----------------------------------------------------------------------+
// | Copyright (c) JackieWangjackieit@hotmail.com |
// +----------------------------------------------------------------------+
// | This source file ' s function was to get the time length of the FLV |
// | Main function getTime param: $name The flv file you want to get |
// +----------------------------------------------------------------------+
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;
}
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;
}
?>
http://www.bkjia.com/PHPjc/320523.html www.bkjia.com true http://www.bkjia.com/PHPjc/320523.html techarticle Copy the code as follows:? PHP//+----------------------------------------------------------------------+//| PHP version 4 $byte _wordlen = strlen ($byte _word); for ($i = 0; $i $ ...