diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..ef7b4f8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,25 @@ +| Q | A +| -------------- | --- +| Bug? | no +| New Feature? | no +| Version Used | Specific tag or commit sha +| FFmpeg Version | FFmpeg or AVConv and version +| OS | Your OS and version + +#### Actual Behavior + +How does PHP-FFMpeg behave at the moment? + +#### Expected Behavior + +What is the behavior you expect? + +#### Steps to Reproduce + +What are the steps to reproduce this bug? Please add code examples, +screenshots or links to GitHub repositories that reproduce the problem. + +#### Possible Solutions + +If you have already ideas how to solve the issue, add them here. +Otherwise remove this section. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..49205d2 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,36 @@ +| Q | A +| ------------------ | --- +| Bug fix? | no +| New feature? | no +| BC breaks? | no +| Deprecations? | no +| Fixed tickets | fixes #issuenum +| Related issues/PRs | #issuenum +| License | MIT + +#### What's in this PR? + +Explain the contents of the PR. + +#### Why? + +Which problem does the PR fix? + +#### Example Usage + +```php +$foo = new Foo(); + +// Now we can do +$foo->doSomething(); + +// Remove this section if not needed +~~~ + +#### BC Breaks/Deprecations + +Describe BC breaks/deprecations here (Remove this section if not needed). + +#### To Do + +- [ ] Create tests diff --git a/.gitignore b/.gitignore index f474a5d..4f3f707 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ -/nbproject/ +#/nbproject/ /vendor/ /docs/build composer.phar +composer.lock phpunit.xml - +sami.phar +.idea/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index e4bc51a..e9d7b51 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,39 @@ language: php -before_script: - - sudo apt-get update - - sudo apt-get install -y ffmpeg libavcodec-extra-53 - - composer self-update - - composer install --no-interaction --prefer-source --dev +dist: trusty + +branches: + only: + - master + - v1.x + +cache: + directories: + - $HOME/.composer/cache + - $HOME/.cache php: - - 5.3.3 - - 5.3 - 5.4 - 5.5 - 5.6 + - 7.0 + - 7.1 + - 7.2 + +matrix: + include: + - php: 5.4 + env: COMPOSER_FLAGS="--prefer-lowest" + +before_install: + - sudo add-apt-repository ppa:mc3man/trusty-media -y + - sudo apt-get update -q + - composer self-update + - if [ "$COMPOSER_FLAGS" == "--prefer-lowest" ]; then composer require "roave/security-advisories" dev-master --no-update; fi; + +install: + - sudo apt-get install -y ffmpeg + - composer update --prefer-dist $COMPOSER_FLAGS script: - vendor/bin/phpunit --verbose - - vendor/bin/phpunit --verbose -c phpunit-functional.xml.dist diff --git a/CHANGELOG.md b/CHANGELOG.md index c2f6830..78aeb46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,101 +1,173 @@ CHANGELOG ---------- +========= -* 0.6.0 (xx-xx-2015) +All notable changes to this project will be documented in this file. +This project adheres to [Semantic Versioning](http://semver.org/). - * AbstractData::get no longer throws exceptions (@sujayjaju). - * Add crop filter (@cangelis). - * Fix watermark (@sujayjaju). +[Unreleased] +------------ -* 0.5.1 (08-26-2014) +### Added - * Fix video aspect ratio calculation (@nlegoff). +- Add pull request and issue templates. +- Usage of new codec "aac" of ffmpeg 3 -* 0.5.0 (08-12-2014) +### Changed - * Add support for Wav and AAC audio formats (@MrHash). - * Add watermark filter (@sylvainv). - * Add configuration for audio channels (@SimonSimCity). +- Updated changelog to follow [keepachangelog.com](http://keepachangelog.com/) + style you see now here. -* 0.4.4 (12-17-2013) +[0.7.0] - 2016-12-15 +-------------------- - * Fix width / height dimensions extraction. +- Add support for FFMpeg 3 aac codec (@Nek-) +- Add a waveform filter to extract audio waveform images (@Romain) -* 0.4.3 (12-02-2013) +[0.6.1] - 2016-03-08 +-------------------- - * Fix using rotate and resize filters at the same time (#78) +- Support PHP 7 and test against +- Unused code cleanup (@haphan) +- Composer and tests cleanup (PSR-4 autoloading) +- Allow usage of evenement v2.0 -* 0.4.2 (11-29-2013) +[0.6.0] - 2016-01-30 +-------------------- - * Add Rotate filter. - * Remove time_start metadata when using synchronize filter - * Remove restriction on filesystem resources. +- AbstractData::get no longer throws exceptions (@sujayjaju). +- Add crop filter (@cangelis). +- Fix watermark (@sujayjaju). -* 0.4.1 (11-26-2013) +[0.5.1] - 2016-08-26 +-------------------- - * Add Clip filter (@guimeira) +- Fix video aspect ratio calculation (@nlegoff). -* 0.4.0 (10-21-2013) +[0.5.0] - 2014-08-12 +-------------------- - * Add support for video to audio transcoding - * BC Break : Add FormatInterface::getPasses and FormatInterface::getExtraParams +- Add support for Wav and AAC audio formats (@MrHash). +- Add watermark filter (@sylvainv). +- Add configuration for audio channels (@SimonSimCity). -* 0.3.5 (10-21-2013) +[0.4.4] - 2016-12-17 +-------------------- - * Add vorbis audio format (@jacobbudin). - * Fix #66 : Allow single pass encodings. +- Fix width / height dimensions extraction. -* 0.3.4 (09-05-2013) +[0.4.3] - 2013-02-12 +-------------------- - * Fix Invalid ratio computing. +- Fix using rotate and resize filters at the same time (#78) -* 0.3.3 (09-05-2013) +[0.4.2] - 2013-11-29 +-------------------- - * Add convenient Stream::getDimensions method to extract video dimension. - * Add DisplayRatioFixer Frame filter. +- Add Rotate filter. +- Remove time_start metadata when using synchronize filter +- Remove restriction on filesystem resources. -* 0.3.2 (08-08-2013) +[0.4.1] - 2013-11-26 +-------------------- - * Fix A/V synchronization over flash and HTML5 players. +- Add Clip filter (@guimeira) -* 0.3.1 (08-06-2013) +[0.4.0] - 2013-10-21 +-------------------- - * Allow use of FFProbe on remote URIs. - * Fix #47 : MediaTypeInterface::save adds filters depending on the codec. - * Save frame to target file without prompt. +- Add support for video to audio transcoding +- BC Break : Add FormatInterface::getPasses and FormatInterface::getExtraParams -* 0.3.0 (07-04-2013) +[0.3.5] - 2013-10-21 +-------------------- - * Complete rewrite of the library, lots of BC breaks, check the doc. +- Add vorbis audio format (@jacobbudin). +- Fix #66 : Allow single pass encodings. -* 0.2.4 (05-10-2013) +[0.3.4] - 2013-09-05 +-------------------- - * Add Video\ResizableInterface::getModulus method for better output scaling (@retrojunk) - * Fix timeout setting on audio/video encoding (@xammep-ua) +- Fix Invalid ratio computing. -* 0.2.3 (04-21-2013) +[0.3.3] - 2013-09-05 +-------------------- - * Add timeout getter and setter on FFMpeg and FFProbe - * Add timeout setting via second argument on FFMpeg::load and FFProbe::load +- Add convenient Stream::getDimensions method to extract video dimension. +- Add DisplayRatioFixer Frame filter. -* 0.2.2 (02-11-2013) +[0.3.2] - 2013-08-08 +-------------------- - * Add compatibility with FFMpeg 1.1 - * Upgrade deprecated options (`-ab`, `-qscale` and `-b`) - * Use of a custom stat file for each multi-pass encoding (fix #20) - * Use larger version range for dependencies +- Fix A/V synchronization over flash and HTML5 players. -* 0.2.1 (02-04-2013) +[0.3.1] - 2013-08-06 +-------------------- - * Parse the output of FFProbe using correct EOL sequences (@ak76) - * Add process timeout customization (@pulse00) - * Fix `accurate` option (`FFMpeg::extractImage`) +- Allow use of FFProbe on remote URIs. +- Fix #47 : MediaTypeInterface::save adds filters depending on the codec. +- Save frame to target file without prompt. -* 0.2.0 (12-13-2012) +[0.3.0] - 2013-07-04 +-------------------- - * Add HelperInterface and support for realtime progress ( @pulse00 ). - * Add `accurate` option to `FFMpeg::extractImage` method. +- Complete rewrite of the library, lots of BC breaks, check the doc. -* 0.1.0 (10-30-2012) +[0.2.4] - 2013-05-10 +-------------------- - * First stable version. +- Add Video\ResizableInterface::getModulus method for better output scaling (@retrojunk) +- Fix timeout setting on audio/video encoding (@xammep-ua) + +[0.2.3] - 2013-04-21 +-------------------- + +- Add timeout getter and setter on FFMpeg and FFProbe +- Add timeout setting via second argument on FFMpeg::load and FFProbe::load + +[0.2.2] - 2013-02-11 +-------------------- + +- Add compatibility with FFMpeg 1.1 +- Upgrade deprecated options (`-ab`, `-qscale` and `-b`) +- Use of a custom stat file for each multi-pass encoding (fix #20) +- Use larger version range for dependencies + +[0.2.1] - 2013-02-04 +-------------------- + +- Parse the output of FFProbe using correct EOL sequences (@ak76) +- Add process timeout customization (@pulse00) +- Fix `accurate` option (`FFMpeg::extractImage`) + +[0.2.0] - 2012-12-13 +-------------------- + +- Add HelperInterface and support for realtime progress ( @pulse00 ). +- Add `accurate` option to `FFMpeg::extractImage` method. + +0.1.0 - 2012-10-30 +-------------------- + +- First stable version. + +[Unreleased]: https://github.com/PHP-FFMpeg/PHP-FFMpeg/compare/0.6.1...HEAD +[0.6.1]: https://github.com/PHP-FFMpeg/PHP-FFMpeg/compare/0.6.0...0.6.1 +[0.6.0]: https://github.com/PHP-FFMpeg/PHP-FFMpeg/compare/0.5.1...0.6.0 +[0.5.1]: https://github.com/PHP-FFMpeg/PHP-FFMpeg/compare/0.5.0...0.5.1 +[0.5.0]: https://github.com/PHP-FFMpeg/PHP-FFMpeg/compare/0.4.4...0.5.0 +[0.4.4]: https://github.com/PHP-FFMpeg/PHP-FFMpeg/compare/0.4.3...0.4.4 +[0.4.3]: https://github.com/PHP-FFMpeg/PHP-FFMpeg/compare/0.4.2...0.4.3 +[0.4.2]: https://github.com/PHP-FFMpeg/PHP-FFMpeg/compare/0.4.1...0.4.2 +[0.4.1]: https://github.com/PHP-FFMpeg/PHP-FFMpeg/compare/0.4.0...0.4.1 +[0.4.0]: https://github.com/PHP-FFMpeg/PHP-FFMpeg/compare/0.3.5...0.4.0 +[0.3.5]: https://github.com/PHP-FFMpeg/PHP-FFMpeg/compare/0.3.4...0.3.5 +[0.3.4]: https://github.com/PHP-FFMpeg/PHP-FFMpeg/compare/0.3.3...0.3.4 +[0.3.3]: https://github.com/PHP-FFMpeg/PHP-FFMpeg/compare/0.3.2...0.3.3 +[0.3.2]: https://github.com/PHP-FFMpeg/PHP-FFMpeg/compare/0.3.1...0.3.2 +[0.3.1]: https://github.com/PHP-FFMpeg/PHP-FFMpeg/compare/0.3.0...0.3.1 +[0.3.0]: https://github.com/PHP-FFMpeg/PHP-FFMpeg/compare/0.2.4...0.3.0 +[0.2.4]: https://github.com/PHP-FFMpeg/PHP-FFMpeg/compare/0.2.3...0.2.4 +[0.2.3]: https://github.com/PHP-FFMpeg/PHP-FFMpeg/compare/0.2.2...0.2.3 +[0.2.2]: https://github.com/PHP-FFMpeg/PHP-FFMpeg/compare/0.2.1...0.2.2 +[0.2.1]: https://github.com/PHP-FFMpeg/PHP-FFMpeg/compare/0.2.0...0.2.1 +[0.2.0]: https://github.com/PHP-FFMpeg/PHP-FFMpeg/compare/0.1.0...0.2.0 diff --git a/README.md b/README.md index 967ee3a..edbee3f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -#PHP FFmpeg +# PHP FFmpeg [![Build Status](https://secure.travis-ci.org/PHP-FFMpeg/PHP-FFMpeg.png?branch=master)](http://travis-ci.org/PHP-FFMpeg/PHP-FFMpeg) @@ -6,39 +6,38 @@ An Object Oriented library to convert video/audio files with FFmpeg / AVConv. -Check another amazing repo : [PHP FFMpeg extras](https://github.com/alchemy-fr/PHP-FFMpeg-Extras), you will find lots of Audio/Video formats there. +Check another amazing repo: [PHP FFMpeg extras](https://github.com/alchemy-fr/PHP-FFMpeg-Extras), you will find lots of Audio/Video formats there. ## Your attention please -### How this library works : +### How this library works: This library requires a working FFMpeg install. You will need both FFMpeg and FFProbe binaries to use it. Be sure that these binaries can be located with system PATH to get the benefit of the binary detection, -otherwise you should have to explicitely give the binaries path on load. +otherwise you should have to explicitly give the binaries path on load. For Windows users : Please find the binaries at http://ffmpeg.zeranoe.com/builds/. -### Known issues : +### Known issues: -- Using rotate and resize will produce a corrupted output when using -[libav](http://libav.org/) 0.8. The bug is fixed in version 9. This bug does not +- Using rotate and resize will produce a corrupted output when using +[libav](http://libav.org/) 0.8. The bug is fixed in version 9. This bug does not appear in latest ffmpeg version. ## Installation The recommended way to install PHP-FFMpeg is through [Composer](https://getcomposer.org). -```json -{ - "require": { - "php-ffmpeg/php-ffmpeg": "~0.5" - } -} +```bash +$ composer require php-ffmpeg/php-ffmpeg ``` ## Basic Usage ```php + +require 'vendor/autoload.php'; + $ffmpeg = FFMpeg\FFMpeg::create(); $video = $ffmpeg->open('video.mpg'); $video @@ -62,14 +61,14 @@ to browse the source code as it is self-documented. ### FFMpeg `FFMpeg\FFMpeg` is the main object to use to manipulate medias. To build it, -use the static `FFMpeg\FFMpeg::create` : +use the static `FFMpeg\FFMpeg::create`: ```php $ffmpeg = FFMpeg\FFMpeg::create(); ``` FFMpeg will autodetect ffmpeg and ffprobe binaries. If you want to give binary -paths explicitely, you can pass an array as configuration. A `Psr\Logger\LoggerInterface` +paths explicitly, you can pass an array as configuration. A `Psr\Logger\LoggerInterface` can also be passed to log binary executions. ```php @@ -86,8 +85,8 @@ $ffmpeg = FFMpeg\FFMpeg::create(array( `FFMpeg\FFMpeg` creates media based on URIs. URIs could be either a pointer to a local filesystem resource, an HTTP resource or any resource supported by FFmpeg. -**Note** : To list all supported resource type of your FFmpeg build, use the -`-protocols` command : +**Note**: To list all supported resource type of your FFmpeg build, use the +`-protocols` command: ``` ffmpeg -protocols @@ -99,12 +98,12 @@ To open a resource, use the `FFMpeg\FFMpeg::open` method. $ffmpeg->open('video.mpeg'); ``` -Two types of media can be resolved : `FFMpeg\Media\Audio` and `FFMpeg\Media\Video`. +Two types of media can be resolved: `FFMpeg\Media\Audio` and `FFMpeg\Media\Video`. A third type, `FFMpeg\Media\Frame`, is available through videos. -#### Video +### Video -`FFMpeg\Media\Video` can be transcoded, ie : change codec, isolate audio or +`FFMpeg\Media\Video` can be transcoded, ie: change codec, isolate audio or video. Frames can be extracted. ##### Transcoding @@ -115,15 +114,15 @@ pass a `FFMpeg\Format\FormatInterface` for that. Please note that audio and video bitrate are set on the format. ```php -$format = new Format\Video\X264(); +$format = new FFMpeg\Format\Video\X264(); $format->on('progress', function ($video, $format, $percentage) { echo "$percentage % transcoded"; }); $format - -> setKiloBitrate(1000) - -> setAudioChannels(2) - -> setAudioKiloBitrate(256); + ->setKiloBitrate(1000) + ->setAudioChannels(2) + ->setAudioKiloBitrate(256); $video->save($format, 'video.avi'); ``` @@ -136,7 +135,7 @@ below for more informations. You can extract a frame at any timecode using the `FFMpeg\Media\Video::frame` method. -This code return a `FFMpeg\Media\Frame` instance corresponding to the second 42. +This code returns a `FFMpeg\Media\Frame` instance corresponding to the second 42. You can pass any `FFMpeg\Coordinate\TimeCode` as argument, see dedicated documentation below for more information. @@ -145,6 +144,54 @@ $frame = $video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(42)); $frame->save('image.jpg'); ``` +If you want to extract multiple images from your video, you can use the following filter: + +```php +$video + ->filters() + ->extractMultipleFrames(FFMpeg\Filters\Video\ExtractMultipleFramesFilter::FRAMERATE_EVERY_10SEC, '/path/to/destination/folder/') + ->synchronize(); + +$video + ->save(new FFMpeg\Format\Video\X264(), '/path/to/new/file'); +``` + +##### Generate a waveform + +You can generate a waveform of an audio file using the `FFMpeg\Media\Audio::waveform` +method. + +This code returns a `FFMpeg\Media\Waveform` instance. +You can optionally pass dimensions as the first two arguments and an array of hex string colors for ffmpeg to use for the waveform, see dedicated +documentation below for more information. + +The ouput file MUST use the PNG extension. + +```php +$waveform = $audio->waveform(640, 120, array('#00FF00')); +$waveform->save('waveform.png'); +``` + +If you want to get a waveform from a video, convert it in an audio file first. + +```php +// Open your video file +$video = $ffmpeg->open( 'video.mp4' ); + +// Set an audio format +$audio_format = new FFMpeg\Format\Audio\Mp3(); + +// Extract the audio into a new file as mp3 +$video->save($audio_format, 'audio.mp3'); + +// Set the audio file +$audio = $ffmpeg->open( 'audio.mp3' ); + +// Create the waveform +$waveform = $audio->waveform(); +$waveform->save( 'waveform.png' ); +``` + ##### Filters You can apply filters on `FFMpeg\Media\Video` with the `FFMpeg\Media\Video::addFilter` @@ -173,9 +220,9 @@ $video->filters()->rotate($angle); The `$angle` parameter must be one of the following constants : -- `FFMpeg\Filters\Video\RotateFilter::ROTATE_90` : 90° clockwise -- `FFMpeg\Filters\Video\RotateFilter::ROTATE_180` : 180° -- `FFMpeg\Filters\Video\RotateFilter::ROTATE_270` : 90° counterclockwise +- `FFMpeg\Filters\Video\RotateFilter::ROTATE_90`: 90° clockwise +- `FFMpeg\Filters\Video\RotateFilter::ROTATE_180`: 180° +- `FFMpeg\Filters\Video\RotateFilter::ROTATE_270`: 90° counterclockwise ###### Resize @@ -185,12 +232,57 @@ Resizes a video to a given size. $video->filters()->resize($dimension, $mode, $useStandards); ``` -The resize filter takes three parameters : +The resize filter takes three parameters: - `$dimension`, an instance of `FFMpeg\Coordinate\Dimension` - `$mode`, one of the constants `FFMpeg\Filters\Video\ResizeFilter::RESIZEMODE_*` constants - `$useStandards`, a boolean to force the use of the nearest aspect ratio standard. +If you want a video in a non-standard ratio, you can use the padding filter to resize your video in the desired size, and wrap it into black bars. + +```php +$video->filters()->pad($dimension); +``` + +The pad filter takes one parameter: + +- `$dimension`, an instance of `FFMpeg\Coordinate\Dimension` + +Don't forget to save it afterwards. + +```php +$video->save(new FFMpeg\Format\Video\X264(), $new_file); +``` + +###### Watermark + +Watermark a video with a given image. + +```php +$video + ->filters() + ->watermark($watermarkPath, array( + 'position' => 'relative', + 'bottom' => 50, + 'right' => 50, + )); +``` + +The watermark filter takes two parameters: + +`$watermarkPath`, the path to your watermark file. +`$coordinates`, an array defining how you want your watermark positioned. You can use relative positioning as demonstrated above or absolute as such: + +```php +$video + ->filters() + ->watermark($watermarkPath, array( + 'position' => 'absolute', + 'x' => 1180, + 'y' => 620, + )); +``` + ###### Framerate Changes the frame rate of the video. @@ -199,7 +291,7 @@ Changes the frame rate of the video. $video->filters()->framerate($framerate, $gop); ``` -The framerate filter takes two parameters : +The framerate filter takes two parameters: - `$framerate`, an instance of `FFMpeg\Coordinate\Framerate` - `$gop`, a [GOP](https://wikipedia.org/wiki/Group_of_pictures) value (integer) @@ -228,9 +320,21 @@ The clip filter takes two parameters: - `$start`, an instance of `FFMpeg\Coordinate\TimeCode`, specifies the start point of the clip - `$duration`, optional, an instance of `FFMpeg\Coordinate\TimeCode`, specifies the duration of the clip -#### Audio +###### Crop -`FFMpeg\Media\Audio` can be transcoded, ie : change codec, isolate audio or +Crops the video based on a width and height(a `Point`) + +```php +$video->filters()->crop(new FFMpeg\Coordinate\Point("t*100", 0, true), new FFMpeg\Coordinate\Dimension(200, 600)); +``` + +It takes two parameters: +- `$point`, an instance of `FFMpeg\Coordinate\Point`, specifies the point to crop +- `$dimension`, an instance of `FFMpeg\Coordinate\Dimension`, specifies the dimension of the output video + +### Audio + +`FFMpeg\Media\Audio` can be transcoded too, ie: change codec, isolate audio or video. Frames can be extracted. ##### Transcoding @@ -250,8 +354,8 @@ $format->on('progress', function ($audio, $format, $percentage) { }); $format - -> setAudioChannels(2) - -> setAudioKiloBitrate(256); + ->setAudioChannels(2) + ->setAudioKiloBitrate(256); $audio->save($format, 'track.flac'); ``` @@ -267,6 +371,35 @@ method. It only accepts audio filters. You can build your own filters and some are bundled in PHP-FFMpeg - they are accessible through the `FFMpeg\Media\Audio::filters` method. +##### Clipping +Cuts the audio at a desired point. + +```php +$audio->filters()->clip(FFMpeg\Coordinate\TimeCode::fromSeconds(30), FFMpeg\Coordinate\TimeCode::fromSeconds(15)); +``` + + +###### Metadata + +Add metadata to audio files. Just pass an array of key=value pairs of all +metadata you would like to add. If no arguments are passed into the filter +all metadata will be removed from input file. Currently supported data is +title, artist, album, artist, composer, track, year, description, artwork + +```php +$audio->filters()->addMetadata(["title" => "Some Title", "track" => 1]); + +//remove all metadata and video streams from audio file +$audio->filters()->addMetadata(); +``` + +Add artwork to the audio file +```php +$audio->filters()->addMetadata(["artwork" => "/path/to/image/file.jpg"]); +``` +NOTE: at present ffmpeg (version 3.2.2) only supports artwork output for .mp3 +files + ###### Resample Resamples an audio file. @@ -293,6 +426,68 @@ $frame->save('target.jpg'); This method has a second optional boolean parameter. Set it to true to get accurate images ; it takes more time to execute. +#### Gif + +A gif is an animated image extracted from a sequence of the video. + +You can save gif files using the `FFMpeg\Media\Gif::save` method. + +```php +$video = $ffmpeg->open( '/path/to/video' ); +$video + ->gif(FFMpeg\Coordinate\TimeCode::fromSeconds(2), new FFMpeg\Coordinate\Dimension(640, 480), 3) + ->save($new_file); +``` + +This method has a third optional boolean parameter, which is the duration of the animation. +If you don't set it, you will get a fixed gif image. + +#### Concatenation + +This feature allows you to generate one audio or video file, based on multiple sources. + +There are two ways to concatenate videos, depending on the codecs of the sources. +If your sources have all been encoded with the same codec, you will want to use the `FFMpeg\Media\Concatenate::saveFromSameCodecs` which has way better performances. +If your sources have been encoded with different codecs, you will want to use the `FFMpeg\Media\Concatenate::saveFromDifferentCodecs`. + +The first function will use the initial codec as the one for the generated file. +With the second function, you will be able to choose which codec you want for the generated file. + +You also need to pay attention to the fact that, when using the saveFromDifferentCodecs method, +your files MUST have video and audio streams. + +In both cases, you will have to provide an array of files. + +To concatenate videos encoded with the same codec, do as follow: + +```php +// In order to instantiate the video object, you HAVE TO pass a path to a valid video file. +// We recommand that you put there the path of any of the video you want to use in this concatenation. +$video = $ffmpeg->open( '/path/to/video' ); +$video + ->concat(array('/path/to/video1', '/path/to/video2')) + ->saveFromSameCodecs('/path/to/new_file', TRUE); +``` + +The boolean parameter of the save function allows you to use the copy parameter which accelerates drastically the generation of the encoded file. + +To concatenate videos encoded with the same codec, do as follow: + +```php +// In order to instantiate the video object, you HAVE TO pass a path to a valid video file. +// We recommand that you put there the path of any of the video you want to use in this concatenation. +$video = $ffmpeg->open( '/path/to/video' ); + +$format = new FFMpeg\Format\Video\X264(); +$format->setAudioCodec("libmp3lame"); + +$video + ->concat(array('/path/to/video1', '/path/to/video2')) + ->saveFromDifferentCodecs($format, '/path/to/new_file'); +``` + +More details about concatenation in FFMPEG can be found [here](https://trac.ffmpeg.org/wiki/Concatenate), [here](https://ffmpeg.org/ffmpeg-formats.html#concat-1) and [here](https://ffmpeg.org/ffmpeg.html#Stream-copy). + #### Formats A format implements `FFMpeg\Format\FormatInterface`. To save to a video file, @@ -305,7 +500,7 @@ informations about the transcoding. Predefined formats already provide progress informations as events. ```php -$format = new Format\Video\X264(); +$format = new FFMpeg\Format\Video\X264(); $format->on('progress', function ($video, $format, $percentage) { echo "$percentage % transcoded"; }); @@ -315,6 +510,18 @@ $video->save($format, 'video.avi'); The callback provided for the event can be any callable. +##### Add additional parameters + +You can add additional parameters to your encoding requests based on your video format. + +The argument of the setAdditionalParameters method is an array. + +```php +$format = new FFMpeg\Format\Video\X264(); +$format->setAdditionalParameters(array('foo', 'bar')); +$video->save($format, 'video.avi'); +``` + ##### Create your own format The easiest way to create a format is to extend the abstract @@ -355,7 +562,7 @@ FFMpeg use many units for time and space coordinates. - `FFMpeg\Coordinate\AspectRatio` represents an aspect ratio. - `FFMpeg\Coordinate\Dimension` represent a dimension. - `FFMpeg\Coordinate\FrameRate` represent a framerate. -- `FFMpeg\Coordinate\Point` represent a point. +- `FFMpeg\Coordinate\Point` represent a point. (Supports dynamic points since v0.10.0) - `FFMpeg\Coordinate\TimeCode` represent a timecode. ### FFProbe @@ -379,9 +586,19 @@ $ffprobe ->get('duration'); // returns the duration property ``` -##Using with Silex Microframework +### Validating media files -Service provider is easy to set up : +(since 0.10.0) +You can validate media files using PHP-FFMpeg's FFProbe wrapper. + +```php +$ffprobe = FFMpeg\FFProbe::create(); +$ffprobe->isValid('/path/to/file/to/check'); // returns bool +``` + +## Using with Silex Microframework + +Service provider is easy to set up: ```php $app = new Silex\Application(); @@ -390,7 +607,7 @@ $app->register(new FFMpeg\FFMpegServiceProvider()); $video = $app['ffmpeg']->open('video.mpeg'); ``` -Available options are as follow : +Available options are as follow: ```php $app->register(new FFMpeg\FFMpegServiceProvider(), array( @@ -405,14 +622,6 @@ $app->register(new FFMpeg\FFMpegServiceProvider(), array( )); ``` -## API Browser - -Browse the [API](http://readthedocs.org/docs/ffmpeg-php/en/latest/_static/API/) - ## License This project is licensed under the [MIT license](http://opensource.org/licenses/MIT). - - - - diff --git a/composer.json b/composer.json index 8686027..302d2b5 100644 --- a/composer.json +++ b/composer.json @@ -5,40 +5,60 @@ "keywords": ["video processing", "video", "audio processing", "audio", "avconv", "ffmpeg", "avprobe", "ffprobe"], "license": "MIT", "authors": [ - { - "name": "Romain Neutron", - "email": "imprec@gmail.com", - "homepage": "http://www.lickmychip.com/" - }, - { - "name": "Phraseanet Team", - "email": "info@alchemy.fr", - "homepage": "http://www.phraseanet.com/" - } + { + "name": "Romain Neutron", + "email": "imprec@gmail.com", + "homepage": "http://www.lickmychip.com/" + }, + { + "name": "Phraseanet Team", + "email": "info@alchemy.fr", + "homepage": "http://www.phraseanet.com/" + }, + { + "name": "Patrik Karisch", + "email": "patrik@karisch.guru", + "homepage": "http://www.karisch.guru" + }, + { + "name": "Romain Biard", + "email": "romain.biard@gmail.com", + "homepage": "https://www.strime.io/" + }, + { + "name": "Jens Hausdorf", + "email": "hello@jens-hausdorf.de", + "homepage": "https://jens-hausdorf.de" + } ], "require": { - "php" : ">=5.3.3", - "alchemy/binary-driver" : "~1.5", - "doctrine/cache" : "~1.0", - "evenement/evenement" : "~1.0", - "neutron/temporary-filesystem" : "~2.1, >=2.1.1" + "php": "^5.3.9 || ^7.0", + "alchemy/binary-driver": "^1.5", + "doctrine/cache": "^1.0", + "evenement/evenement": "^2.0 || ^1.0", + "neutron/temporary-filesystem": "^2.1.1" }, "suggest": { - "php-ffmpeg/extras" : "A compilation of common audio & video drivers for PHP-FFMpeg" + "php-ffmpeg/extras": "A compilation of common audio & video drivers for PHP-FFMpeg" }, "require-dev": { - "sami/sami" : "~1.0", - "silex/silex" : "~1.0", - "phpunit/phpunit" : "~3.7" + "sami/sami": "~1.0", + "silex/silex": "~1.0", + "phpunit/phpunit": "^4.8.36" }, "autoload": { "psr-0": { "FFMpeg": "src" } }, + "autoload-dev": { + "psr-4": { + "Tests\\FFMpeg\\": "tests" + } + }, "extra": { "branch-alias": { - "dev-master": "0.5-dev" + "dev-master": "0.7-dev" } } } diff --git a/docs/source/API/API/FFMpeg/Format/Video/X264.html b/docs/source/API/API/FFMpeg/Format/Video/X264.html index 399b173..bcf7d52 100644 --- a/docs/source/API/API/FFMpeg/Format/Video/X264.html +++ b/docs/source/API/API/FFMpeg/Format/Video/X264.html @@ -119,7 +119,17 @@ - string + integer + + + setPasses(integer $passes) +

Sets the number of passes.

+ + + + + + integer getPasses() @@ -499,12 +509,37 @@ + + + +

+
in X264 at line 68
+ public integer + setPasses(integer $passes) +

+
+

Sets the number of passes.

+

+

+
+ +

Parameters

+ + + + + + +
integer$passes
+ + +

-
at line 68
- public string +
in X264 at line 79
+ public integer getPasses()

@@ -517,7 +552,7 @@ - + diff --git a/docs/source/API/API/FFMpeg/Media/Audio.html b/docs/source/API/API/FFMpeg/Media/Audio.html index 3a8be2c..afdb3fe 100644 --- a/docs/source/API/API/FFMpeg/Media/Audio.html +++ b/docs/source/API/API/FFMpeg/Media/Audio.html @@ -171,6 +171,16 @@

Exports the audio in the desired format, applies registered filters.

+ + + + +
stringinteger
+ Audio + + waveform(integer $width, integer $height) +

Generates an image file representing the waveform of the audio file.

+
@@ -609,6 +619,59 @@
+

+
at line 113
+ public Audio + save(FormatInterface $format, string $outputPathfile) +

+
+

Exports the audio in the desired format, applies registered filters.

+

+

+
+

Parameters

+ + + + + + + + + + + + +
FormatInterface$format +
string$outputPathfile +
+ + +

Return Value

+ + + + + + +
Audio +
+ + +

Exceptions

+ + + + + + +
RuntimeException +
+ + +
+
+