PHP implementation time to get FLV files _php Tutorial

Source: Internet
Author: User
Tags fread flv file

PHP implementation time to get FLV files


This article mainly introduces the PHP implementation to get the FLV file time, this article directly give implementation code and use method, the need for friends can refer to the following

How PHP Gets the flv file time, the answer is fopen file after viewing the FLV file is hex data and converted to number.

The code is as follows:


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

?>

Just use Get_flv_file_time ("Your flv.flv").

http://www.bkjia.com/PHPjc/955835.html www.bkjia.com true http://www.bkjia.com/PHPjc/955835.html techarticle PHP implementation time to get FLV files This article mainly introduces the PHP implementation of the time to get the FLV file, this article directly give the implementation code and use method, the need for friends can refer to the next PHP how to obtain ...

  • Related Article

    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.