FFMPEG视频处理

2020-07-24  本文已影响0人  花佬爷
    define('FFMPEG_PATH', '/usr/local/ffmpeg/bin/ffmpeg -i "%s" 2>&1');// ffmpeg安装路径
    public function videoTime($file)
    {
        ob_start();
        passthru(sprintf(FFMPEG_PATH, Env::get('root_path').'public/uploads/'.$file));  //passthru()类似exec()
        $info = ob_get_contents();
        ob_end_clean();
        // 通过使用输出缓冲,获取到ffmpeg所有输出的内容。
        $ret = array();
        // Duration: 01:24:12.73, start: 0.000000, bitrate: 456 kb/s
        if (preg_match("/Duration: (.*?), start: (.*?), bitrate: (\d*) kb\/s/", $info, $match)) {
            $ret['duration'] = $match[1]; // 提取出播放时间
            return $ret;
        }
        return '';
    }
上一篇 下一篇

猜你喜欢

热点阅读