转自:https://blog.csdn.net/hechenhongbo/article/details/83347704
1: 安装 ffmpeg
ffmpeg的下载链接 http://ffmpeg.org/download.html
解压安装包
tar -jxvf ffmpeg-x.x.tar.bz2
进入目录
cd ffmpeg-x.x
编译安装
./configure --enable-shared && make && make install
报错:
nasm/yasm not found or too old. Use --disable-x86asm 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 "ffbuild/config.log" produced by configure as this will help
solve the problem.
报这个错说明没有安装yasm,所以要先去安装yasm
http://yasm.tortall.net/Download.html 下载yasm,上传到服务器的local目录中
解压:
tar -zxvf yasm.tar.gz
进入解压目录安装:
cd yasm-1.3.0/
./configure
make
make install
安装成功以后进入FFmpeg目录进行安装,可能需要3,4分钟时间
如果编译报错,请加选项(报错会提示选项内容)./configure --enable-shared --选项 && make && make install
安装完成之后 执行 ffmpeg -version
如果出现ffmpeg: error while loading shared libraries: libavdevice.so.57: cannot open shared object file: No such file or directory
编辑/etc/ld.so.conf文件中的:include ld.so.conf.d/*.conf 这行下面加入如下内容
/usr/local/ffmpeg-4.0.2
保存退出后执行ldconfig命令
检验安装成功与否,输入 ffmpeg检验,出现如下图内容,即安装成功
2.修改php.ini中的禁止函数
因为PHP代码中会用到exec或者system,直接删除,还有shell_exc,proc_open,peoc_get_status
cd /usr/local/php/etc
vi php.ini
修改完成后保存退出重启服务器
service php-fpm restart
看到如下,说明重启成功
Gracefully shutting down php-fpm .. done
Starting php-fpm done
3.PHP代码篇
我用的框架是tp5的框架,代码如下,因为视频和图片一样都是文件,所以接收方式和图片的接收方式一样,上传也是一样,直接调取框架自带的上传类:
$video = request()->file('video');//接收video文件
或者将截取视频第一帧的功能封装一个方法,可以调用