ffmpeg获取视频信息

<?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";


?>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值