当前位置: 首页 > 图文教程 > 网络编程 > PHP > 用PHP读取flv文件的播放时间长度

PHP
PHP 七大优势分析
PHP n个不重复的随机数生成代码
php addslashes 函数详细分析说明
PHP 文件上传功能实现代码
PHP 超链接 抓取实现代码
PHP 网页过期时间的控制代码
PHP HTML代码串 截取实现代码
php 过滤危险html代码
PHP 彩色文字实现代码
通过PHP CLI实现简单的数据库实时监控调度
php mysql Errcode: 28 终极解决方法
连接到txt文本的超链接,不直接打开而是点击后下载的处理方法
phpmyadmin MySQL 加密配置方法
PHP 上传文件大小限制
php 多个submit提交表单 处理方法
PHP 页面跳转到另一个页面的三种方法方法总结
php 执行系统命令的方法
程序员编程十条戒律
php 论坛采集程序 模拟登陆,抓取页面 实现代码
PHP 程序授权验证开发思路

用PHP读取flv文件的播放时间长度


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 70 ::
收藏到网摘: n/a

用PHP读取flv文件的播放时间长度的代码,需要用的朋友可以参考下。
复制代码 代码如下:

<?php
// +----------------------------------------------------------------------+
// | PHP version 4&5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2007 [email protected] |
// +----------------------------------------------------------------------+
// | This source file'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, '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;
}
?>