FLV Video Editor PHP flv video Time acquisition function

Source: Internet
Author: User
Tags fread
Copy CodeThe code is as follows:


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;
}
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;
}
Echo getTime ("27729.flv");//display digital time like 236722
ECHO fn (236722); Show time Format 0:03:56
?>

The above describes the FLV Video editor PHP flv video time acquisition function, including the content of the FLV video Editor, I hope to be interested in PHP tutorial friends helpful.

  • 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.