soluble / mediatools
FFMpeg 视频音频字幕转换,缩略图,音频提取,查询...
2.2.0
2020-11-14 09:06 UTC
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-08-25 20:31:41 UTC
README
为 hiphpies 提供灵活的音频/视频转换和缩略图功能。它围绕 ffmpeg 和 ffprobe 包装,并暴露了它们的大部分功能,如缩放、剪辑、滤镜、转码、音频提取等等。
为了避免限制,API 更注重提供开发者细调的参数,而不是提供现成的方案。转码和转换通常需要特定的处理,请自行判断。为了帮助入门,文档中包含了很多可以轻松尝试和调整的示例和片段。还可以查看 ffmpeg 的替代包装器,它们很好,有时还能提供更多魔法,如果你在寻找它的话。
另一方面,它喜欢 PSR (psr-log, psr-container, psr-simplecache),口味是 php 7.1 在严格模式下,尽量早地失败并给出清晰的异常信息,确保当需要自定义时可以替换 (SOLID 友好)。
底层,它依赖于经过实战考验的 symfony/process,它的唯一依赖。
文档
所有内容都在这里:https://soluble-io.github.io/soluble-mediatools/
要求
- PHP 7.1+
- FFmpeg/FFProbe 3.4+, 4.0+。
功能
请查看 文档 以获得更详细的概述!
实现的服务
VideoConverter
完整文档: 这里
<?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
完整文档: 这里
<?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
完整文档: 这里
<?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
完整文档: 这里
<?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 );