lookingdown / soluble-mediatools

MediaTools for PHP (ffmpeg video conversion, thumbnailing...)

Home Page:https://soluble-io.github.io/soluble-mediatools/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

soluble-mediatools

PHP 7.1+ Build Status Coverage Code Quality Latest Stable Version Total Downloads License

Toolbox for video conversions, transcoding, querying, thumbnailing... wraps around ffmpeg and ffprobe.

It likes PSR (psr-log, psr-container), 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.

Status

Not yet 1.0 but what is documented works pretty well ;) Travis runs unit and integration/functional tests to ensure a smooth experience. But this project is young and would ❤️ to meet new contributors !

Roadmap

It's an attempt to make a swiss-army knife for medias managment in PHP, need to implement more services: image optimization, subtitle conversions... polish the API...

Documentation

All is here: https://soluble-io.github.io/soluble-mediatools/

Requirements

  • PHP 7.1+
  • FFmpeg/FFProbe 3.4+, 4.0+.

A quick taste

Check the doc to get a more detailed overview !!!

Implemented services

VideoConverter

Full doc: here

<?php
use Soluble\MediaTools\Video\Config\FFMpegConfig;
use Soluble\MediaTools\Video\Exception\ConverterExceptionInterface;
use Soluble\MediaTools\Video\{VideoConverter, VideoConvertParams};

$converter = new VideoConverter(new FFMpegConfig('/path/to/ffmpeg'));

$params = (new VideoConvertParams())
    ->withVideoCodec('libx264')    
    ->withStreamable(true)
    ->withCrf(24);                  
    
try {    
    $converter->convert(
        '/path/inputFile.mov', 
        '/path/outputFile.mp4', 
        $params
    );    
} catch(ConverterExceptionInterface $e) {
    // See chapter about exception !!!    
}
       

VideoInfoReader

Full doc: here

<?php
use Soluble\MediaTools\Video\Config\FFProbeConfig;
use Soluble\MediaTools\Video\Exception\InfoReaderExceptionInterface;
use Soluble\MediaTools\Video\VideoInfoReader;

$infoReader = new VideoInfoReader(new FFProbeConfig('/path/to/ffprobe'));

try {
    $videoInfo = $infoReader->getInfo('/path/video.mp4');
} catch (InfoReaderExceptionInterface $e) {
    // see below for exceptions
}

$duration = $videoInfo->getDuration();
$frames   = $videoInfo->getNbFrames();
$width    = $videoInfo->getWidth();
$height   = $videoInfo->getHeight();

// Or alternatively
['width' => $width, 'height' => $height] = $videoInfo->getDimensions();
       

VideoThumbGenerator

Full doc: here

<?php
use Soluble\MediaTools\Video\Config\FFMpegConfig;
use Soluble\MediaTools\Video\Exception\ConverterExceptionInterface;
use Soluble\MediaTools\Video\{VideoThumbGenerator, VideoThumbParams, SeekTime};

$generator = new VideoThumbGenerator(new FFMpegConfig('/path/to/ffmpeg'));

$params = (new VideoThumbParams())
    ->withTime(1.25);
    
try {    
    $generator->makeThumbnail(
        '/path/inputFile.mov', 
        '/path/outputFile.jpg', 
        $params
    );    
} catch(ConverterExceptionInterface $e) {
    // See chapter about exception !!!    
}
       

VideoAnalyzer

Full doc: here

<?php
use Soluble\MediaTools\Video\Config\FFMpegConfig;
use Soluble\MediaTools\Video\Exception\AnalyzerExceptionInterface;
use Soluble\MediaTools\Video\VideoAnalyzer;

$analyzer = new VideoAnalyzer(new FFMpegConfig('/path/to/ffmpeg'));

    
try {    
    $interlaceGuess = $analyzer->detectInterlacement(
        '/path/input.mov',
        // Optional:
        //   $maxFramesToAnalyze, default: 1000
        $maxFramesToAnalyze = 200
    );
    
} catch(AnalyzerExceptionInterface $e) {
    // See chapter about exception !!!    
}

$interlaced = $interlaceGuess->isInterlaced(
    // Optional: 
    //  $threshold, default 0.25 (if >=25% interlaced frames, then true) 
    0.25
);

Coding standards and interop

About

MediaTools for PHP (ffmpeg video conversion, thumbnailing...)

https://soluble-io.github.io/soluble-mediatools/

License:MIT License


Languages

Language:PHP 99.7%Language:Shell 0.3%