php 使用ffmpeg处理视频

作者: JONE 分类: PHPer 发布时间: 2020-08-13 17:24

原链接:https://www.jianshu.com/p/a3e2206ff7b1

安装插件

composer require php-ffmpeg/php-ffmpeg
 使用
  function handle(){
    ffmpeg = \FFMpeg\FFMpeg::create(array(
                'ffmpeg.binaries'  =>"ffmpeg 可执行文件地址"
                'ffprobe.binaries' => "ffprobe 可执行文件地址"
     ));

    $video = $ffmpeg->open($path);
            $video->filters()
                ->resize(new FFMpeg\Coordinate\Dimension(320, 240))
                ->synchronize();
  //获取文件格式
   $codec_name = $video->getStreams()->videos()->first()->get("codec_name");
  //m3u8转mp4
    $path = "xxxx.mp4";
    $video->save(new FFMpeg\Format\Video\X264(), $path);
  //截取视频第一针作为封面图片
   $video->frame(\FFMpeg\Coordinate\TimeCode::fromSeconds(1))->save($poster);
  //宽
  $width = $video->getStreams()->videos()->first()->get("width");
  //高
  $height = $video->getStreams()->videos()->first()->get("height");
  //视频时长
  $duration =$video->getStreams()->videos()->first()->get("duration");
  }