linux部署支持psd等文件预览,视频缩略图/视频转码

环境要求

  • 操作系统: CentOS 7+、Ubtntu 14+、Debian 8+、RedHat 7+;推荐CentOS 7.4
  • 建议服务器内存4G以上;
  • 删除php禁用函数:exec,shell_exec,proc_open,proc_close

一、安装转换工具软件

1. Linux下,安装ImageMagick 及FFmpeg等依赖组件

# CentOS下安装
yum install ImageMagick dcraw ghostscript ffmpeg libjpeg libjpeg-devel libpng libpng-devel libtiff libtiff-devel libungif libungif-devel freetype zlib
# 安装ffmpeg(视频缩略图,视频转码)
curl http://doc.kodcloud.com/tools/psd/install.sh | sh

#其他Redhat安装
apt-get install ImageMagick dcraw ghostscript ffmpeg libjpeg libjpeg-devel libpng libpng-devel libtiff libtiff-devel libungif libungif-devel freetype zlib

#debian和ubuntu安装
apt install -y imagemagick

apt install -y dcraw

apt install -y ghostscript

apt install -y ffmpeg

apt install -y libjpeg-dev

apt install -y libpng-dev

apt install -y libtiff-dev

apt install -y libfreetype6 libfreetype6-dev

apt install -y zlib1g zlib1g-dev

# 安装完成后测试(没有报错说明安装成功)
convert && dcraw && ffmpeg

1.1 CentOS8下安装

# 1.安装ImageMagick
sudo dnf install epel-release
sudo dnf config-manager --set-enabled PowerTools 
(Powertools 在 RL9 下被称为 crb。centos9使用  dnf config-manager --set-enabled crb  命令 不执行此命令安装ffmpeg可能报错)
sudo dnf update
sudo dnf install ImageMagick ImageMagick-devel
sudo dnf groupinstall "Development Tools"
sudo dnf install git

# 如果有包含ffmpeg的源,可以直接安装ffmpeg; 如果缺少依赖报错可以编译安装;
yum install ffmpeg

# 2.编译安装ffmpeg依赖的转码库libx264
git clone https://code.videolan.org/videolan/x264.git
cd x264 && ./configure --disable-asm --enable-shared --enable-static
make && make install
mkdir /usr/share/x264 && cp ./x264.pc /usr/share/x264/
export PKG_CONFIG_PATH=/usr/share/x264
ldconfig

# 3.编译安装ffmpeg
cd ../
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpeg
./configure --disable-x86asm  --enable-pthreads --enable-libx264 --enable-gpl --enable-pic --enable-shared
make && make install

echo "/usr/local/lib/" >> /etc/ld.so.conf
ldconfig

# 4.安装dcraw
dnf install dcraw

2. Mac下安装

#通过brew,未安装brew则先安装
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

# 安装ImageMagick
brew install ImageMagick dcraw ghostscript ffmpeg libjpeg libjpeg-devel libpng libpng-devel libtiff libtiff-devel libungif libungif-devel freetype zlib

# 安装完成后测试(没有报错说明安装成功)
convert && dcraw && ffmpeg

二、修改php.ini 超时时间及内存限制

由于超过20M的psd,ai等文件,转换时可能会比较耗时间,所以建议php的超时时间及内存限制给大点(也可以不做调整)

max_execution_time = 1200
max_input_time = 1200
memory_limit = 512M

修改保存后,需要重启web服务器才能生效.
ffmpeg 视频转码是否正常,可以手动尝试转换一个文件,试试看有无报错(依赖库及解码器是否正常), eg: ffmpeg -i input.avi output.mp4

CentOS 7安装 FFmpeg

我们将使用 yum 从 RPM Fusion 存储库安装:
1.RPM Fusion 存储库依赖于EPEL 软件存储库,如果您的系统上未启用 EPEL,请使用以下命令:

sudo yum install epel-release

2.接下来,通过安装 rpm 包启用 RPM Fusion 存储库 :

sudo yum localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm

3.启用存储库后,安装 FFmpeg:

sudo yum install ffmpeg ffmpeg-devel

4.通过检查其版本来验证 FFmpeg 安装:

ffmpeg -version

一切顺利,FFmpeg 已经安装在你的CentOS 7上。

CentOS 7安装 FFmpeg-另外一个版本方法

1安装epel-release因为安装需要使用其他的repo源所以需要epel支持

yum install -y epel-release rpm

2安装Nux-Dextop源

①rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro

②rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm

③ yum repolist

3环境都搭建好之后就可以正式安装ffmpeg了

yum install -y ffmpeg

这样ffmpeg就正常安装完成了。

添加其他存储库安装;centos8+ ,如果是centos9就把命令里面的8改为9

dnf install -y epel-release rpm
dnf localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf install -y https://download1.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm
dnf install -y https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-8.noarch.rpm

添加其他存储库安装;centos7+

yum install -y epel-release rpm

rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
yum repolist

yum localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm
sanradar
sanradar
文章: 97

一条评论

  1. Very informative article! I appreciate the depth of analysis. If you want to delve deeper, here’s a helpful resource: EXPLORE FURTHER. Eager to hear everyone’s thoughts!

留下评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注