soluble / mediatools
FFMpeg video/audio/subs conversions, thumbnails, audio extraction, query...
Installs: 1 667
Dependents: 1
Suggesters: 0
Security: 0
Stars: 145
Watchers: 9
Forks: 11
Open Issues: 1
Requires
- php: ^7.1 || ^8.0
- ext-json: *
- ext-pcre: *
- psr/container: ^1.0
- psr/log: ^1.0
- psr/simple-cache: ^1.0
- symfony/polyfill-mbstring: ^v1.18.1
- symfony/process: ^3.3 || ^4.0 || ^5.0
Requires (Dev)
- captainhook/captainhook: 5.4.3
- captainhook/plugin-composer: 5.2.2
- consistence/coding-standard: ^3.10.1
- fig/http-message-util: ^1.1.4
- friendsofphp/php-cs-fixer: ^v2.16.7
- infection/infection: ^0.13 || ^0.14 || ^0.15
- jangregor/phpstan-prophecy: ^0.6.2 || ^0.8.1
- laminas/laminas-servicemanager: ^3.4.1
- mikey179/vfsstream: ^v1.6.8
- monolog/monolog: ^1.23 | ^2.0
- phpspec/prophecy: ^1.9.0 || ^1.11.1
- phpstan/phpstan: 0.12.54
- phpstan/phpstan-phpunit: 0.12.16
- phpstan/phpstan-strict-rules: 0.12.5
- phpunit/phpunit: ^7.4 || ^8.0 || ^9.0
- roave/security-advisories: dev-master
- slevomat/coding-standard: ^6.4.1
- squizlabs/php_codesniffer: ^3.4 || ^3.5
- symfony/cache: ^4.3
- vimeo/psalm: 3.18.2
Suggests
- cache/simple-cache-bridge: Useful if you already have a PSR-6 implementation
- monolog/monolog: PSR-3 compatible logger
- symfony/cache: PSR-6/16 compatible cache
- dev-master
- 2.2.0
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.0.1
- 1.0.0
- 0.9.7
- 0.9.6
- 0.9.5
- 0.9.4
- 0.9.3
- 0.9.2
- 0.9.1
- 0.9.0
- 0.8.7
- 0.8.6
- 0.8.5
- 0.8.4
- 0.8.3
- 0.8.2
- 0.8.1
- 0.8.0
- 0.7.7
- 0.7.6
- 0.7.5
- 0.7.4
- 0.7.3
- 0.7.2
- 0.7.1
- 0.7.0
- 0.6.3
- 0.6.2
- 0.6.1
- 0.6.0
- 0.5.0
- 0.4.0
- 0.3.0
- 0.2.0
- 0.1.0
- dev-chore/travis-debug
- dev-chore/phpunit-9
- dev-chore/mkdocs-5.4
- dev-feat/mkdocs-5
- dev-belgattitude-patch-1
This package is auto-updated.
Last update: 2024-12-25 21:11:07 UTC
README
Flexible audio/video conversions and thumbnailing for hiphpies. Wraps around ffmpeg and ffprobe and exposes most of their features, like scaling, clipping, filters, transcoding, audio extraction and much more.
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.
On another side, 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.
Documentation
All is here: https://soluble-io.github.io/soluble-mediatools/
Requirements
- PHP 7.1+
- FFmpeg/FFProbe 3.4+, 4.0+.
Features
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; use Soluble\MediaTools\Video\VideoInfo; $infoReader = new VideoInfoReader(new FFProbeConfig('/path/to/ffprobe')); // Step 1: Read a media file try { $info = $infoReader->getInfo('/path/video.mp4'); } catch (InfoReaderExceptionInterface $e) { // not a valid video (see exception) } $duration = $info->getDuration(); // total duration $format = $info->getFormatName(); // container format: mkv, mp4 // Step 2: Media streams info (video, subtitle, audio, data). // Example with first video stream (streams are iterable) try { $video = $info->getVideoStreams()->getFirst(); } catch (\Soluble\MediaTools\Video\Exception\NoStreamException $e) { // No video stream, } $codec = $video->getCodecName(); // i.e: vp9 $fps = $video->getFps($decimals=0); // i.e: 24 $width = $video->getWidth(); // i.e: 1080 $ratio = $video->getAspectRatio(); // Alternate example if ($info->countStreams(VideoInfo::STREAM_TYPE_SUBTITLE) > 0) { $sub = $info->getSubtitleStreams()->getFirst(); $sub->getCodecName(); // webvtt }
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 );