请注意:这篇文章中会用到passthru,可能部分虚拟主机会将此命令禁用。
代码如下:
PHP
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
<?php
define( 'FFMPEG_PATH' , '/usr/local/ffmpeg2/bin/ffmpeg -i "%s" 2>&1' );
function getVideoInfo( $file ) {
$command = sprintf(FFMPEG_PATH, $file );
ob_start();
passthru ( $command );
$info = ob_get_contents();
ob_end_clean();
$data = array ();
if (preg_match( "/Duration: (.*?), start: (.*?), bitrate: (\\d*) kb\\/s/" , $info , $match )) {
$data [ 'duration' ] = $match [1]; //播放时间
$arr_duration = explode ( ':' , $match [1]);
$data [ 'seconds' ] = $arr_duration [0] * 3600 + $arr_duration [1] * 60 + $arr_duration [2]; //转换播放时间为秒数
$data [ 'start' ] = $match [2]; //开始时间
$data [ 'bitrate' ] = $match [3]; //码率(kb)
}
if (preg_match( "/Video: (.*?), (.*?), (.*?)[,\\s]/" , $info , $match )) {
$data [ 'vcodec' ] = $match [1]; //视频编码格式
$data [ 'vformat' ] = $match [2]; //视频格式
$data [ 'resolution' ] = $match [3]; //视频分辨率
$arr_resolution = explode ( 'x' , $match [3]);
$data [ 'width' ] = $arr_resolution [0];
$data [ 'height' ] = $arr_resolution [1];
}
if (preg_match( "/Audio: (\\w*), (\\d*) Hz/" , $info , $match )) {
$data [ 'acodec' ] = $match [1]; //音频编码
$data [ 'asamplerate' ] = $match [2]; //音频采样频率
}
if (isset( $data [ 'seconds' ]) && isset( $data [ 'start' ])) {
$data [ 'play_time' ] = $data [ 'seconds' ] + $data [ 'start' ]; //实际播放时间
}
$data [ 'size' ] = filesize ( $file ); //文件大小
return $data ;
}
//用法
$video_info = getVideoInfo( 'video.mp4' );
print_r( $video_info );
?>
|
总结
以上就是这篇文章的全部内容,希望对大家学习或使用PHP的时候能有所帮助。如果有疑问大家可以留言交流。
相关文章
猜你喜欢
- ASP.NET本地开发时常见的配置错误及解决方法? 2025-06-10
- ASP.NET自助建站系统的数据库备份与恢复操作指南 2025-06-10
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
ASP.NET MVC使用EPPlus,导出数据到Excel中
2025-05-29 77 -
2025-05-24 88
-
2025-05-29 95
-
2025-05-26 41
-
2025-05-27 40
热门评论