FFMPEG视频处理

  • 获取视频时长
    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完成变量配置
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容