Skip to content

Home

PHP Version Build Status codecov Scrutinizer Code Quality Latest Stable Version License

Flexible audio/video conversions and thumbnailing for hi*php*ies. Wraps around ffmpeg and ffprobe and exposes most of their features, like scaling, clipping, filters, transcoding, audio extraction and much more.

Logo

To prevent limitations, the API rather focus on providing developer fine-tuned parameters than giving ready-made recipes. Transcoding and conversions generally requires specific processing, judge by yourself. To help starting, the documentation includes a lot of examples and snippets you can easily try and tune later. Check also alternatives wrappers for ffmpeg, they are good and sometimes offer more magic if you're looking for it.

It likes PSR (psr-log, psr-container, psr-simplecache), tastes php 7.1 in strict mode, tries to fail as early as possible with clear exception messages and ensure that substitution is possible when you need to customize (SOLID friendly).

Under the hood, it relies on the battle-tested symfony/process, its only dependency.

Requirements

A PHP version >= 7.1 and depending on required services: ffmpeg and/or ffprobe.

Features at a glance

Video services

  • VideoConverter (doc here)

    • Conversions: transcode, compress, transmux...
    • Clipping (start-time/send-time)
    • Filters: scale, deinterlace, denoise... and others.
      <?php // A quick taste            
      $converter = new VideoConverter(new FFMpegConfig('/path/to/ffmpeg'));
      
      $params = (new VideoConvertParams())
          ->withVideoCodec('libx264')    
          ->withStreamable(true)
          ->withVideoFilter(
              new ScaleFilter(720, 576)
          )
          ->withCrf(24);                  
      
      $converter->convert(
          '/path/inputFile.mov', 
          '/path/outputFile.mp4', 
          $params
      );           
      
  • VideoInfoReader (doc here)

    • Duration, dimensions, number of frames
      <?php // a quick taste    
      $infoReader = new VideoInfoReader(new FFProbeConfig('/path/to/ffprobe'));
      
      try {
          $videoInfo = $infoReader->getInfo('/path/video.mp4');
      } catch (InfoReaderExceptionInterface $e) {
          // Break here
      }
      
      // Total duration
      $duration = $videoInfo->getDuration();        
      // ffprobe format: i.e 'mov,mp4,m4a,3gp,3g2,mj2'
      $format   = $videoInfo->getFormatName();
      
      // Iterable video streams
      $videoStreams = $videoInfo->getVideoStreams();
      
      echo $videoStreams->getFirst()->getCodecName();
      
      $audioStreams = $videoInfo->getAudioStreams();
      
      // ...
      
  • VideoThumbGenerator (doc here)

    • Thumbnail at specific time or frame.
    • Filters: scale, deinterlace, denoise... and others.
      <?php // a quick taste        
      $generator = new VideoThumbGenerator(new FFMpegConfig('/path/to/ffmpeg'));
      
      $params = (new VideoThumbParams())
          ->withVideoFilter(
              new ScaleFilter(720, 576)
          )        
          ->withTime(1.25);
      
      $generator->makeThumbnail(
          '/path/inputFile.mov', 
          '/path/outputFile.jpg', 
          $params
      );    
      
  • VideoAnalyzer (doc here)

    • Interlacing detection
      <?php // a quick taste        
      $analyzer = new VideoAnalyzer(new FFMpegConfig('/path/to/ffmpeg'));
      
      $interlaceGuess = $analyzer->detectInterlacement();
      
      $interlaced = $interlaceGuess->isInterlaced();
      

Alternatives