

wget https://ffmpeg.org/releases/ffmpeg-5.1.2.tar.gztar -zxvf ffmpeg-5.1.2.tar.gz
/usr/local/ffmpeg
cd ffmpeg-5.1.2./configure --prefix=/usr/local/ffmpegmake && make install
vim /etc/profile在文件内容最下面添加环境变量:(a是切入输入模式)export PATH=$PATH:/usr/local/ffmpeg/bin保存退出(ESC切换模式输入 :wq)使修改内容立即生效执行命令source /etc/profile查看所有环境变量命令:export
ffmpeg -version
yasm/nasm not found or too old. Use –disable-yasm for a crippled build. If you think configure made a mistake, make sure you are using the latest version from Git. If the latest version fails, report the problem to the ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net. Include the log file “config.log” produced by configure as this will help solve the problem.
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gztar -zxvf yasm-1.3.0.tar.gzcd yasm-1.3.0./configuremake && make install
1.在项目根目录新建一个composer.json文件,文件里写一个空对象(就是一个空的大括号)2.初始化,执行命令:composer install3.安装命令:composer require php-ffmpeg/php-ffmpeg
添加公共函数方法:
//FFMpeg获取视频第一帧为图片,使用composer下载插件。处理自动加载冲突function autoloadAdjust($video_src,$ico_src){// 取原有的加载方法$oldFunctions = spl_autoload_functions();// 逐个卸载if ($oldFunctions){foreach ($oldFunctions as $f) {spl_autoload_unregister($f);}}// 注册本框架的自动载入require $_SERVER['DOCUMENT_ROOT'] .'/vendor/autoload.php';$ffmpeg = FFMpeg\FFMpeg::create(['ffmpeg.binaries'=>'/usr/local/ffmpeg/bin/ffmpeg','ffprobe.binaries'=>'/usr/local/ffmpeg/bin/ffprobe']);$video_src = $_SERVER['DOCUMENT_ROOT'] . $video_src;$uqid = uniqid();//获取无序字符串$ico_img = $ico_src .'/'. $uqid . '.png'; //获取符合缩略图格式路径$ico_src_new = $_SERVER['DOCUMENT_ROOT'] . $ico_src;//获取绝对路径目录//没有文件夹,就创建if(!is_dir($ico_src_new)){mkdir($ico_src_new,0777,true);}$ico_src_new = $ico_src_new .'/'. $uqid . '.png';$video = $ffmpeg->open($video_src);//打开一个本地的视频文件$frame = $video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(1));//截取视频中第几秒的截图$frame->save($ico_src_new);//保存截图// 如果引用本框架的其它框架已经定义了__autoload,要保持其使用if (function_exists('__autoload')) {spl_autoload_register('__autoload');}// 再将原来的自动加载函数放回去if ($oldFunctions){foreach ($oldFunctions as $f) {spl_autoload_register($f);}}return $ico_img;}
我找到的真实错误是:file_exists(): open_basedir restriction in effect. File.pbootcms只报Unable to load FFProbe错误。解决方法:在宝塔中的网络目录,将防跨站攻击关闭

错误原因是禁用了 proc_open 函数,找到相应版本的php.ini文件,查找 disable_functionsdisable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,proc_open删除 proc_open 重启php即可。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号