<?php
function getVideoInfo($file) {
$cmd = ffprobe.' -show_streams -show_format "'.$file.'" -v quiet -of json';
exec($cmd, $output, $ret);
if ($ret!=0) {
echo " AAAA ";
return null;
}
echo "exe end output:= $output \n";
echo "exe end ret:= $ret \n";
$output = implode("\n", $output);
$info = json_decode($output, true);
$ret = array();
echo "output : $output";
echo "ret : $ret";
$usekey = array('codec_name', 'profile', 'width', 'height', 'pix_fmt',
'level', 'fps'=>'r_frame_rate', 'start_time', 'duration', 'bit_rate',
'sample_fmt', 'sample_rate', 'channels', 'rotate'=>'tags');
foreach($info['streams'] as $obj) {
$out = array();
if ($obj['codec_type']=='video' || $obj['codec_type']=='audio') {
foreach($usekey as $method=>$key) {
if (isset($obj[$key])) {
if ($method === 'fps') {
$tmp = explode('/', $obj[$key]);
$den = intval($tmp[0]);
$num = intval($tmp[1]);
if ($den!=0 && $num!=0) {
$out['fps'] = $den/$num;
}
} else if ($method === 'rotate') {
if (isset($obj['tags']) && isset($obj['tags']['rotate'])) {
$out['rotate'] = intval($obj['tags']['rotate']);
}
} else {
$out[$key] = $obj[$key];
}
}
}
$ret[$obj['codec_type']]=$out;
}
}
if (isset($info['format'])) {
$fmt = $info['format'];
$usekey = array('format_name', 'start_time', 'duration', 'size', 'bit_rate');
foreach($usekey as $key) {
$ret[$key] = $fmt[$key];
}
}
return $ret;
}
$result=getVideoInfo('/video/1080p/1920x1080.mp4');
echo "\nhere end get info, be ana -------------------> \n";
var_dump($result);
$video_duration = isset($result['video']['duration']) ? $result['video']['duration'] : 0;
$video_width = isset($result['video']['width']) ? $result['video']['width'] : 0;
$video_height = isset($result['video']['height']) ? $result['video']['height'] : 0;
echo "video_duration:= $video_duration \n";
echo "video_width:= $video_width \n";
echo "video_height:= $video_height \n";
if($video_height < $video_width){
$video_width = $video_height;
}
echo "video_width:= $video_width \n";
?>
ffmpeg获取视频信息
最新推荐文章于 2024-07-23 18:09:00 发布