php flv视频时间获取函数
时间:2023-09-04 13:41:48
<?php
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;
}
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");//显示数字时间如236722
echo fn(236722); //显示时间格式0:03:56
?>
标签:php,flv,时间获取


猜你喜欢
python2.7 安装pip的方法步骤(管用)
2022-02-11 06:28:43

vue服务器代理proxyTable配置如何解决跨域
2024-04-28 09:22:32

IE6实现min-width
2008-06-12 12:40:00
TensorFlow2.1.0最新版本安装详细教程
2021-11-08 00:14:02

如何使用python-opencv批量生成带噪点噪线的数字验证码
2023-10-14 03:38:54

Pycharm远程连接服务器跑代码的实现
2021-06-19 21:13:54

ASP与Excel结合生成数据表和Chart图的代码
2011-03-08 10:50:00
Python 中如何将十六进制转换为 Base64
2022-09-07 01:20:14
tensorflow 实现打印pb模型的所有节点
2022-09-28 22:37:33
Go语言使用钉钉机器人推送消息的实现示例
2024-05-09 14:57:37

Div即父容器不根据内容自适应高度的解决方法
2010-04-23 18:19:00
python如何往列表头部和尾部添加元素
2021-12-17 07:05:17
利用Python实现好看的水波特效
2023-05-26 22:23:53

go语言开发环境安装及第一个go程序(推荐)
2024-05-05 09:34:22

树莓派(python)与arduino串口通信的详细步骤
2022-05-29 15:31:06

Laravel 微信小程序后端实现用户登录的示例代码
2024-06-05 15:40:52

通过FSO进行页面计数
2008-11-27 16:02:00
使用python实现rsa算法代码
2022-07-12 14:06:10
Python中五种实现字符串反转的方法
2023-11-08 00:22:12

考虑SQL Server安全时所应注意的几个方面
2009-01-04 13:57:00