Detailed explanation of using php to read the playback time length of flv files

怪我咯
Release: 2023-03-13 17:22:01
Original
1583 people have browsed it

FLV is the abbreviation of FLASH VIDEO. The FLV streaming media format is a new video format, the full name is Flash Video. Because the files it forms are extremely small and the loading speed is extremely fast, it makes it possible to watch video files on the Internet. Its appearance effectively solves the problem that after the video files are imported into Flash, the exported SWF file is bulky and cannot be used well on the Internet. and other shortcomings.
FLV is a video format developed with the launch of Flash MX. It is currently used by many new generation video sharing websites and is currently the fastest growing and most widespread video transmission format. It was developed based on the compression algorithm of Sorenson Company. The FLV format can not only be easily imported into Flash, it is extremely fast, it can also protect copyright, and the video can be played without using the local Microsoft or REAL player.
FLV is a new streaming video format that utilizes the Flash Player platform widely used on web pages to integrate video into Flash animation. In other words, as long as website visitors can watch Flash animations, they can also watch FLV format videos without having to install other video plug-ins. The use of FLV videos brings great convenience to video dissemination. .

This article mainly introduces the code for reading the playback time length of flv files using PHP. Friends who need it can refer to it.

The code is as follows:

<?php 
// +----------------------------------------------------------------------+ 
// | PHP version 4&5 | 
// +----------------------------------------------------------------------+ 
// | Copyright (c) 2007 JackieWangjackieit@hotmail.com | 
// +----------------------------------------------------------------------+ 
// | This source file&#39;s function is to get the time length of 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(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; 
} 
function getTime($name){ 
if(!file_exists($name)){ 
return; 
} 
$flv_data_length=filesize($name); 
$fp = @fopen($name, &#39;rb&#39;); 
$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; 
} 
?>
Copy after login


The above is the detailed content of Detailed explanation of using php to read the playback time length of flv files. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!