您现在的位置是:首页 > 技术杂谈 > php php
php要实现这个功能需要用到ffmpeg视频扩展
1、下载地址:ffmpeg下载地址
2、将下载文件解压放到项目中
3、方法:
<?php
$file = "视频路径";
$video_info = getVideoInfo($file);
//获取的视频时长单位一般要转化为秒
$duration = date('H:i:s',strtotime($video_info['duration']));
//获取视频相关信息
//$file 视频路径
function getVideoInfo($file) {
//__PUBLIC__.'/admin-layout/plugins/ffmpeg/bin/ffmpeg
//ffmpeg文件的绝对路径
$command = sprintf(__PUBLIC__.'/admin-layout/plugins/ffmpeg/bin/ffmpeg -i "%s" 2>&1', $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]; //播放时间
}
return $data;
}
//获取第一帧生成图片
//$file 视频路径
//$time 获取第几秒的帧
//$name 生成的图片绝对路径(包括图片名称)
function getVideoCover($file,$time,$name) {
if(empty($time))$time = '1';//默认截取第一秒第一帧
$execStr = __PUBLIC__."/admin-layout/plugins/ffmpeg/bin/ffmpeg -i ".$file." 2>&1 -y -f image2 -ss 1 -vframes 1 -s 640x360 ".$name;
exec($execStr,$arr,$status);
}
下一篇:公众号基本配置
文章评论

评论列表