Sample code of time for PHP to get FLV files

Source: Internet
Author: User
Tags fread flv file
FLV is the short name of Flash video, FLV streaming media format is a new video format, all called Flash video. Because it forms a very small file, loading speed is very fast, so that the network to watch video files become possible, it has effectively solved the video file import Flash, so that the export SWF file size, can not be good use of the network and other shortcomings

FLV is the introduction of Flash MX with the development of video format, is currently used by many new generation of video sharing sites, is currently the fastest growing, the most extensive video transmission format. was developed on the basis of the Sorenson Company's compression algorithm. The FLV format is not only easy to import into Flash, extremely fast, and can play a role in protecting copyright, and can not be played through the local Microsoft or Real Player video.
FLV is a new streaming video format that leverages the widely used flash Player platform on a Web page to integrate video into Flash animations. That is, visitors to the site as long as the Flash animation can be seen, nature can also see the FLV format video, without additional installation of other video plugins, the use of FLV video has brought great convenience to video transmission.

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:

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

Use Get_flv_file_time directly ("Your flv.flv").

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.