项目作者: sharapov-outsource

项目描述 :
Extensions library for the PHP FFMpeg (https://github.com/PHP-FFMpeg/PHP-FFMpeg)
高级语言: PHP
项目地址: git://github.com/sharapov-outsource/php-ffmpeg-extensions.git
创建时间: 2016-06-25T20:57:56Z
项目社区:https://github.com/sharapov-outsource/php-ffmpeg-extensions

开源协议:GNU General Public License v3.0

下载


php-ffmpeg-extensions

An extensions library for the PHP FFMpeg (https://github.com/PHP-FFMpeg/PHP-FFMpeg)

Installation (via Composer):

For composer installation, add:

  1. "require": {
  2. "sharapov/php-ffmpeg-extensions": "^0.2"
  3. },

to your composer.json file and update your dependencies. Or you can run:

  1. $ composer require sharapov/php-ffmpeg-extensions

Notes:

Tested with ffmpeg 3+, not tested with ffmpeg 4+

Usage:

Now you can autoload or use the class via its namespace. Below are examples of how to use the library.

Draw texts and boxes

  1. // Init FFMpeg library
  2. $ffmpeg = \Sharapov\FFMpegExtensions\FFMpeg::create(array(
  3. 'ffmpeg.binaries' => '/path/to/ffmpeg', // Path to FFMpeg
  4. 'ffprobe.binaries' => '/path/to/ffprobe', // Path to FFProbe
  5. 'timeout' => 3600, // The timeout for the underlying process
  6. 'ffmpeg.threads' => 12, // The number of threads that FFMpeg should use
  7. ));
  8. // Open source video
  9. $video = $ffmpeg->open( new InputFile( 'source/Coast - 1270.mp4' ) );
  10. // Apply filter options to video
  11. $video
  12. ->filters()
  13. ->complex( new OptionsCollection( [
  14. ( ( new FilterComplexOptions\OptionDrawText() )
  15. // Set z-index property. Greater value is always in front
  16. ->setZIndex( 160 )
  17. // You can use fade-in and fade-out effects. Set time in seconds
  18. ->setFadeIn( 1 )
  19. ->setFadeOut( 2 )
  20. // Set font path
  21. ->setFontFile( new InputFile( 'source/arial.ttf' ) )
  22. // Set font color. Accepts transparency value as the second argument. Float value between 0 and 1.
  23. ->setFontColor( '#ffffff' )
  24. // Set font size in pixels
  25. ->setFontSize( 33 )
  26. // Set text string
  27. ->setText( 'php-ffmpeg-extensions library' )
  28. // Coordinates where the text should be rendered. Accepts positive integer or
  29. // constants "(w-tw)/2", "(h-th)/2" to handle auto-horizontal, auto-vertical values
  30. ->setCoordinates( new Coordinate\Point( Coordinate\Point::AUTO_HORIZONTAL, 50 ) )
  31. // Set timings (start, stop) in seconds. Accepts float values as well
  32. ->setTimeLine( new Coordinate\TimeLine( 1, 20 ) ) ),
  33. ( ( new FilterComplexOptions\OptionDrawText() )
  34. ->setZIndex( 160 )
  35. ->setFadeIn( 1 )
  36. ->setFadeOut( 2 )
  37. ->setFontFile( new InputFile( 'source/arial.ttf' ) )
  38. ->setFontColor( '#ffffff' )
  39. ->setFontSize( 28 )
  40. ->setText( 'Sharapov A. (www.sharapov.biz)' )
  41. ->setCoordinates( new Coordinate\Point( 15, 600 ) )
  42. ->setTimeLine( new Coordinate\TimeLine( 2, 20 ) ) ),
  43. ( ( new FilterComplexOptions\OptionDrawBox() )
  44. ->setZIndex( 130 )
  45. ->setColor( '000000', 0.6 )
  46. ->setDimensions( new Coordinate\Dimension( Coordinate\Dimension::WIDTH_MAX, 60 ) )
  47. ->setCoordinates( new Coordinate\Point( 0, 580 ) ) ),
  48. ( ( new FilterComplexOptions\OptionDrawText() )
  49. ->setZIndex( 160 )
  50. ->setFadeIn( 1 )
  51. ->setFadeOut( 2 )
  52. ->setFontFile( new InputFile( 'source/arial.ttf' ) )
  53. ->setFontColor( '#ffffff' )
  54. ->setFontSize( 28 )
  55. ->setText( 'v2.0' )
  56. ->setCoordinates( new Coordinate\Point( 1200, 600 ) )
  57. ->setTimeLine( new Coordinate\TimeLine( 3, 20 ) ) )
  58. ] ) );
  59. // Run render
  60. $format = new \FFMpeg\Format\Video\X264( 'libmp3lame' );
  61. $format->on( 'progress', function ( $video, $format, $percentage ) {
  62. echo "$percentage% transcoded\n";
  63. } );
  64. try {
  65. $video
  66. ->save( $format, 'output/output.mp4' );
  67. print 'Done!';
  68. } catch ( ExecutionFailureException $e ) {
  69. print $e->getMessage();
  70. }

You will find other examples in “/examples” folder.

Changelog

Links

PHP FFMpeg Homepage

Composer

GitHub

Packagist