因项目需要截取视频第一帧,百度搜索,说是需要 ffmpeg,捣鼓了一天,勉强算是弄出来了,稀里糊涂的,不知道对错,记录一下,以后好找…当然,肯定在别的地方拿来的东西,复制一下而已~ Linux的,貌似要在 / 进行安装,在 ~ 下,yasm成功,单 ffmpeg 安装失败…小白的我也不晓得这俩位置的区别,哪位路过的好心大佬能给讲解一波呗!
1.安装gcc cc cl
yum -y install gcc cc cl
2.安装yasm
1) 下载
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
2) 解压
tar -xvf yasm-1.3.0.tar.gz
3) 安装
cd yasm-1.3.0/
./configure && make && make install
3.安装FFmpeg
1) 下载
wget http://www.ffmpeg.org/releases/ffmpeg-3.4.tar.gz
2) 解压
tar -xvf ffmpeg-3.4.tar.gz
3) 安装
cd ffmpeg-3.4/
./configure && make && make install
4) 查看安装情况
ffmpeg -version
出现以下情况就是安装成功了,过程很漫长......
ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-36)
configuration:
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
4.使用
//待处理视频路径
$in_file = "xxx/video.mp4";
//缩略图保存路径
$out_file = 'xxx/img.jpg';
//要执行的 cmd 命令
$cmd = "ffmpeg -ss 0.1 -i ".$in_file." -y -f image2 -t 0.01 -s 350x240 ".$out_file;
$cmd = iconv('UTF-8','GB2312',$cmd);
//执行命令
exec($cmd.' 2>&1');
-ss 0.1 :将视频指向 0.1 秒,也就是从 0.1 秒开始
-i /storage/emulated/0/test.mp4 :输入 test.mp4 文件
-y:强制覆盖文件(防止因为重名出错)
-f image2:文件格式
-t 0.01 :持续时间
/storage/emulated/0/0.jpg:输出文件路径
如果顺利的话执行完,就可以看到你亲爱的图片了~
还有一个用jq转换成 base64的方法
https://download.csdn.net/download/qq_40528167/12354283