linux 安装ffmpeg 并用php获取视频封面

安装MP3编码库
  tar -zxvpf lame-3.99.tar.gz
  cd lame-3.99
  ./configure && make && make install
安装X264视频编码库
  tar -zxvpf nasm-2.14.02.tar.gz
  cd nasm-2.14.02
  ./configure && make && make install
  cd ..
  tar -jxvpf x264-master.tar.bz2
  cd x264-master
  ./configure --enable-shared  && make && make install
SDL显示安装
  tar -zxvpf SDL2-2.0.12.tar.gz
  cd SDL2-2.0.12
  ./configure && make && make install
安装ffmpeg
     http://ffmpeg.org/download.html下载包
     tar -jxvf ffmpeg-x.x.tar.bz2
     cd ffmpeg-x.x
     ./configure --enable-shared --enable-libfreetype --enable-libmp3lame --enable-libx264 --enable-gpl && make && make install
    (如果编译报错,请加选项(报错会提示选项内容)./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命令
报错nasm/yasm not found or too old则先安装yasm
     tar -zxvf yasm.tar.gz
     cd yasm-1.3.0/
     ./configure
     make && make install
 

生成文字水印

ffmpeg  -i  a.mp4  -vf  drawtext=fontfile=/usr/share/fonts/dejavu/DejaVuSans.ttf:text=welcome:x=10:y=10:fontsize=48:fontcolor=red@0.5:shadowy=2 b.mp4

生成右下角图片水印

ffmpeg -i video.mp4 -i logo.png -filter_complex 'overlay=main_w-overlay_w-10:main_h-overlay_h-10' output.mp4 -y

php操作
引入类库
composer require php-ffmpeg/php-ffmpeg
php代码
$configuration = array(
'ffmpeg.binaries' => '/usr/local/bin/ffmpeg',
'ffprobe.binaries' => '/usr/local/bin/ffprobe', //这里是电脑或服务器上所安装的位置
// 'timeout' => 3600, // The timeout for the underlying process
// 'ffmpeg.threads' => 12, // The number of threads that FFMpeg should use
);
$ffmpeg = FFMpeg::create($configuration);
$video = $ffmpeg->open('文件的绝对路径');
$video->filters()->resize(new Dimension(320,240))->synchronize();
$video->frame(TimeCode::fromSeconds(1))->save('生成文件的绝对路径');

  

原文地址:https://www.cnblogs.com/godehi/p/13087167.html