buonaparte / bnp-ffmpeg-module
本模块为 PHP_FFmpeg 库提供了一个简单的封装,将库作为 Zend Framework 服务暴露
dev-master
2014-06-12 12:32 UTC
Requires
- php: >=5.3.3
- php-ffmpeg/php-ffmpeg: 0.4.*@dev
- zendframework/zend-loader: ~2.1
- zendframework/zend-modulemanager: ~2.1
- zendframework/zend-mvc: ~2.1
- zendframework/zend-servicemanager: ~2.1
- zendframework/zend-stdlib: ~2.1
Requires (Dev)
- phpunit/phpunit: >=3.7,<4
- satooshi/php-coveralls: dev-master
- squizlabs/php_codesniffer: 1.4.*
This package is not auto-updated.
Last update: 2024-09-24 01:56:25 UTC
README
本模块为 PHP_FFmpeg 库提供了一个简单的封装,将库作为 ZendFramework 服务暴露。
安装
设置
-
将此项目添加到您的 composer.json 文件中
"require": { "buonaparte/bnp-ffmpeg-module": "dev-master" }
-
现在运行以下命令,让 composer 下载 BnpFFMpegModule
$ php composer.phar update
安装后
在您的 application.config.php
文件中启用它。
<?php return array( 'modules' => array( // ... 'BnpFFMpegModule', ), // ... );
配置
通过复制并调整 config/module.config.php.dist
到您的配置包含路径来配置模块
$ffmpegConfig = array( 'configuration' => array( 'ffmpeg.threads' => 4, 'ffmpeg.timeout' => 300, 'ffmpeg.binaries' => '/opt/local/ffmpeg/bin/ffmpeg', ), /** * Custom logger service, must resolve to a Psr\Logger\LoggerInterface instance pulled from the ServiceManager */ 'logger' => 'ffmpeg_logger', /** * Custom FFProbe service, pulled from the ServiceManager */ 'ffprobe' => 'ffprobe_service' ); return array( /** * Root Module configuration */ 'bnp-ffmpeg-module' => array( /** * For single ffmpeg service instance you can just uncomment the bellow line */ // 'ffmpeg' => $ffmpegConfig, /** * For multiple ffmpeg services with different configuration you will specify them in an array, * from to the service name to service configuration */ // 'ffmpeg' => array( // 'FFMpeg1' => array_merge_recursive($ffmpegConfig, array()), // 'FFMpeg2' => array_merge_recursive($ffmpegConfig, array()), // ), /** * FFProbe configuration */ 'ffprobe' => array( 'configuration' => array( 'ffprobe.timeout' => 30, 'ffprobe.binaries' => '/opt/local/ffmpeg/bin/ffprobe', ), /** * Custom logger service must resolve to a Psr\Logger\LoggerInterface instance pulled from the ServiceManager */ 'logger' => 'ffprobe_logger', /** * Custom cache service must resolve to a Doctrine\Common\Cache\Cache instance pulled from the ServiceManager */ 'cache' => 'ffprobe_cache' ) ), /** * Service Manager config */ 'service_manager' => array( // 'factories' => array( // /** // * FFProbe service factory // */ // 'FFProbe' => 'BnpFFMpegModule\Factory\FFProbeServiceFactory', // /** // * For single ffmpeg service instance you can just register the factory for the service name // */ // 'FFMpeg' => 'BnpFFMpegModule\Factory\FFMpegServiceFactory' // ), // 'abstract_factories' => array( // /** // * For multiple ffmpeg service instances you must register the FFMpeg abstract factory // */ // 'BnpFFMpegModule\Factory\FFMpegAbstractServiceFactory' // ) ) );
使用方法
$ffmpeg = $serviceLocator->get('FFMpeg'); // Open video $video = $ffmpeg->open('/your/source/folder/input.avi'); // Resize to 720x480 $video ->filters() ->resize(new Dimension(720, 480), ResizeFilter::RESIZEMODE_INSET) ->synchronize(); // Start transcoding and save video $video->save(new X264(), '/your/target/folder/video.mp4');