美文网首页
FFMPEG视频处理

FFMPEG视频处理

作者: 花佬爷 | 来源:发表于2020-07-24 16:15 被阅读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 '';
        }
    
    • php开启passthru函数
    • error while loading shared libraries: libavdevice.so// 出现此错误时,需配置ffmpeg环境变量
      1.vi /etc/ld.so.conf,加入路径/usr/local/ffmpeg/lib
      2.sudo ldconfig,更新环境变量
      3.vi /etc/profile,加入export PATH="/usr/local/ffmpeg/bin:$PATH",然后运行source /etc/profile完成变量配置

    相关文章

      网友评论

          本文标题:FFMPEG视频处理

          本文链接:https://www.haomeiwen.com/subject/hodjlktx.html