├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .sami.php ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── composer.json ├── docs └── source │ └── API │ └── API │ ├── FFMpeg.html │ ├── FFMpeg │ ├── Coordinate.html │ ├── Coordinate │ │ ├── AspectRatio.html │ │ ├── Dimension.html │ │ ├── FrameRate.html │ │ ├── Point.html │ │ ├── TimeCode.html │ │ └── namespace-frame.html │ ├── Driver.html │ ├── Driver │ │ ├── FFMpegDriver.html │ │ ├── FFProbeDriver.html │ │ └── namespace-frame.html │ ├── Exception.html │ ├── Exception │ │ ├── ExceptionInterface.html │ │ ├── ExecutableNotFoundException.html │ │ ├── InvalidArgumentException.html │ │ ├── LogicException.html │ │ ├── RuntimeException.html │ │ └── namespace-frame.html │ ├── FFMpeg.html │ ├── FFMpegServiceProvider.html │ ├── FFProbe.html │ ├── FFProbe │ │ ├── DataMapping.html │ │ ├── DataMapping │ │ │ ├── AbstractData.html │ │ │ ├── Format.html │ │ │ ├── Stream.html │ │ │ ├── StreamCollection.html │ │ │ └── namespace-frame.html │ │ ├── Mapper.html │ │ ├── MapperInterface.html │ │ ├── OptionsTester.html │ │ ├── OptionsTesterInterface.html │ │ ├── OutputParser.html │ │ ├── OutputParserInterface.html │ │ └── namespace-frame.html │ ├── Filters.html │ ├── Filters │ │ ├── Audio.html │ │ ├── Audio │ │ │ ├── AudioFilterInterface.html │ │ │ ├── AudioFilters.html │ │ │ ├── AudioResamplableFilter.html │ │ │ ├── SimpleFilter.html │ │ │ └── namespace-frame.html │ │ ├── FilterInterface.html │ │ ├── FiltersCollection.html │ │ ├── Frame.html │ │ ├── Frame │ │ │ ├── DisplayRatioFixerFilter.html │ │ │ ├── FrameFilterInterface.html │ │ │ ├── FrameFilters.html │ │ │ └── namespace-frame.html │ │ ├── Video.html │ │ ├── Video │ │ │ ├── ClipFilter.html │ │ │ ├── CustomFilter.html │ │ │ ├── FrameRateFilter.html │ │ │ ├── ResizeFilter.html │ │ │ ├── RotateFilter.html │ │ │ ├── SynchronizeFilter.html │ │ │ ├── VideoFilterInterface.html │ │ │ ├── VideoFilters.html │ │ │ ├── WatermarkFilter.html │ │ │ └── namespace-frame.html │ │ └── namespace-frame.html │ ├── Format.html │ ├── Format │ │ ├── Audio.html │ │ ├── Audio │ │ │ ├── Aac.html │ │ │ ├── DefaultAudio.html │ │ │ ├── Flac.html │ │ │ ├── Mp3.html │ │ │ ├── Vorbis.html │ │ │ ├── Wav.html │ │ │ └── namespace-frame.html │ │ ├── AudioInterface.html │ │ ├── FormatInterface.html │ │ ├── FrameInterface.html │ │ ├── ProgressListener.html │ │ ├── ProgressListener │ │ │ ├── AbstractProgressListener.html │ │ │ ├── AudioProgressListener.html │ │ │ ├── VideoProgressListener.html │ │ │ └── namespace-frame.html │ │ ├── ProgressableInterface.html │ │ ├── Video.html │ │ ├── Video │ │ │ ├── DefaultVideo.html │ │ │ ├── Ogg.html │ │ │ ├── WMV.html │ │ │ ├── WMV3.html │ │ │ ├── WebM.html │ │ │ ├── X264.html │ │ │ └── namespace-frame.html │ │ ├── VideoInterface.html │ │ └── namespace-frame.html │ ├── Media.html │ ├── Media │ │ ├── AbstractMediaType.html │ │ ├── AbstractStreamableMedia.html │ │ ├── Audio.html │ │ ├── Frame.html │ │ ├── MediaTypeInterface.html │ │ ├── Video.html │ │ ├── Waveform.html │ │ └── namespace-frame.html │ └── namespace-frame.html │ ├── PROJECT_VERSION │ ├── SAMI_VERSION │ ├── classes-frame.html │ ├── classes.html │ ├── css │ ├── main.css │ ├── panel.css │ └── reset.css │ ├── doc-index.html │ ├── i │ ├── arrows.png │ ├── loader.gif │ ├── results_bg.png │ └── tree_bg.png │ ├── index.html │ ├── interfaces.html │ ├── js │ ├── jquery-1.3.2.min.js │ ├── permalink.js │ └── searchdoc.js │ ├── namespaces-frame.html │ ├── namespaces.html │ ├── opensearch.xml │ ├── panel.html │ ├── renderer.index │ ├── search_index.js │ ├── stylesheet.css │ ├── traits.html │ └── tree.js ├── phpunit.xml.dist ├── src └── FFMpeg │ ├── Coordinate │ ├── AspectRatio.php │ ├── Dimension.php │ ├── FrameRate.php │ ├── Point.php │ └── TimeCode.php │ ├── Driver │ ├── FFMpegDriver.php │ └── FFProbeDriver.php │ ├── Exception │ ├── ExceptionInterface.php │ ├── ExecutableNotFoundException.php │ ├── InvalidArgumentException.php │ ├── LogicException.php │ └── RuntimeException.php │ ├── FFMpeg.php │ ├── FFMpegServiceProvider.php │ ├── FFProbe.php │ ├── FFProbe │ ├── DataMapping │ │ ├── AbstractData.php │ │ ├── Format.php │ │ ├── Stream.php │ │ └── StreamCollection.php │ ├── Mapper.php │ ├── MapperInterface.php │ ├── OptionsTester.php │ ├── OptionsTesterInterface.php │ ├── OutputParser.php │ └── OutputParserInterface.php │ ├── Filters │ ├── Audio │ │ ├── AddMetadataFilter.php │ │ ├── AudioClipFilter.php │ │ ├── AudioFilterInterface.php │ │ ├── AudioFilters.php │ │ ├── AudioResamplableFilter.php │ │ └── SimpleFilter.php │ ├── Concat │ │ ├── ConcatFilterInterface.php │ │ └── ConcatFilters.php │ ├── FilterInterface.php │ ├── FiltersCollection.php │ ├── Frame │ │ ├── DisplayRatioFixerFilter.php │ │ ├── FrameFilterInterface.php │ │ └── FrameFilters.php │ ├── Gif │ │ ├── GifFilterInterface.php │ │ └── GifFilters.php │ ├── Video │ │ ├── ClipFilter.php │ │ ├── CropFilter.php │ │ ├── CustomFilter.php │ │ ├── ExtractMultipleFramesFilter.php │ │ ├── FrameRateFilter.php │ │ ├── PadFilter.php │ │ ├── ResizeFilter.php │ │ ├── RotateFilter.php │ │ ├── SynchronizeFilter.php │ │ ├── VideoFilterInterface.php │ │ ├── VideoFilters.php │ │ └── WatermarkFilter.php │ └── Waveform │ │ ├── WaveformDownmixFilter.php │ │ ├── WaveformFilterInterface.php │ │ └── WaveformFilters.php │ ├── Format │ ├── Audio │ │ ├── Aac.php │ │ ├── DefaultAudio.php │ │ ├── Flac.php │ │ ├── Mp3.php │ │ ├── Vorbis.php │ │ └── Wav.php │ ├── AudioInterface.php │ ├── FormatInterface.php │ ├── FrameInterface.php │ ├── ProgressListener │ │ ├── AbstractProgressListener.php │ │ ├── AudioProgressListener.php │ │ └── VideoProgressListener.php │ ├── ProgressableInterface.php │ ├── Video │ │ ├── DefaultVideo.php │ │ ├── Ogg.php │ │ ├── WMV.php │ │ ├── WMV3.php │ │ ├── WebM.php │ │ └── X264.php │ └── VideoInterface.php │ └── Media │ ├── AbstractMediaType.php │ ├── AbstractStreamableMedia.php │ ├── Audio.php │ ├── Concat.php │ ├── Frame.php │ ├── Gif.php │ ├── MediaTypeInterface.php │ ├── Video.php │ └── Waveform.php └── tests ├── Functional ├── FFProbeTest.php ├── FunctionalTestCase.php ├── VideoTranscodeTest.php └── output │ └── .placeholder ├── Unit ├── Coordinate │ ├── AspectRatioTest.php │ ├── DimensionTest.php │ ├── FrameRateTest.php │ ├── PointTest.php │ └── TimeCodeTest.php ├── Driver │ ├── FFMpegDriverTest.php │ └── FFProbeDriverTest.php ├── FFMpegServiceProviderTest.php ├── FFMpegTest.php ├── FFProbe │ ├── DataMapping │ │ ├── AbstractDataTest.php │ │ ├── StreamCollectionTest.php │ │ └── StreamTest.php │ ├── MapperTest.php │ ├── OptionsTesterTest.php │ └── OutputParserTest.php ├── FFProbeTest.php ├── Filters │ ├── Audio │ │ ├── AudioClipTest.php │ │ ├── AudioFiltersTest.php │ │ ├── AudioMetadataTest.php │ │ └── AudioResamplableFilterTest.php │ ├── FiltersCollectionTest.php │ ├── Frame │ │ ├── DisplayRatioFixerFilterTest.php │ │ └── FrameFiltersTest.php │ ├── Video │ │ ├── CropFilterTest.php │ │ ├── CustomFilterTest.php │ │ ├── ExtractMultipleFramesFilterTest.php │ │ ├── FrameRateFilterTest.php │ │ ├── PadFilterTest.php │ │ ├── ResizeFilterTest.php │ │ ├── RotateFilterTest.php │ │ ├── SynchronizeFilterTest.php │ │ ├── VideoFiltersTest.php │ │ └── WatermarkFilterTest.php │ └── Waveform │ │ ├── WaveformDownmixFilterTest.php │ │ └── WaveformFiltersTest.php ├── Format │ ├── Audio │ │ ├── AacTest.php │ │ ├── AudioTestCase.php │ │ ├── FlacTest.php │ │ ├── Mp3Test.php │ │ ├── VorbisTest.php │ │ └── WavTest.php │ ├── ProgressListener │ │ ├── AudioProgressListenerTest.php │ │ └── VideoProgressListenerTest.php │ └── Video │ │ ├── OggTest.php │ │ ├── VideoTestCase.php │ │ ├── WMV3Test.php │ │ ├── WMVTest.php │ │ ├── WebMTest.php │ │ └── X264Test.php ├── Media │ ├── AbstractMediaTestCase.php │ ├── AbstractStreamableTestCase.php │ ├── AudioProg.php │ ├── AudioTest.php │ ├── ConcatTest.php │ ├── FrameTest.php │ ├── GifTest.php │ ├── Prog.php │ ├── VideoTest.php │ └── WaveformTest.php └── TestCase.php ├── bootstrap.php ├── files ├── Audio.mp3 ├── Test.ogv ├── WrongFile.mp4 ├── concat-list.txt ├── portrait.MOV ├── sample.3gp └── watermark.png └── fixtures └── ffprobe ├── help.raw ├── show_format.json ├── show_format.raw ├── show_streams.json └── show_streams.raw /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | | Q | A 2 | | -------------- | --- 3 | | Bug? | no 4 | | New Feature? | no 5 | | Version Used | Specific tag or commit sha 6 | | FFmpeg Version | FFmpeg or AVConv and version 7 | | OS | Your OS and version 8 | 9 | #### Actual Behavior 10 | 11 | How does PHP-FFMpeg behave at the moment? 12 | 13 | #### Expected Behavior 14 | 15 | What is the behavior you expect? 16 | 17 | #### Steps to Reproduce 18 | 19 | What are the steps to reproduce this bug? Please add code examples, 20 | screenshots or links to GitHub repositories that reproduce the problem. 21 | 22 | #### Possible Solutions 23 | 24 | If you have already ideas how to solve the issue, add them here. 25 | Otherwise remove this section. 26 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | | Q | A 2 | | ------------------ | --- 3 | | Bug fix? | no 4 | | New feature? | no 5 | | BC breaks? | no 6 | | Deprecations? | no 7 | | Fixed tickets | fixes #issuenum 8 | | Related issues/PRs | #issuenum 9 | | License | MIT 10 | 11 | #### What's in this PR? 12 | 13 | Explain the contents of the PR. 14 | 15 | #### Why? 16 | 17 | Which problem does the PR fix? 18 | 19 | #### Example Usage 20 | 21 | ```php 22 | $foo = new Foo(); 23 | 24 | // Now we can do 25 | $foo->doSomething(); 26 | 27 | // Remove this section if not needed 28 | ~~~ 29 | 30 | #### BC Breaks/Deprecations 31 | 32 | Describe BC breaks/deprecations here (Remove this section if not needed). 33 | 34 | #### To Do 35 | 36 | - [ ] Create tests 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #/nbproject/ 2 | /vendor/ 3 | /docs/build 4 | composer.phar 5 | composer.lock 6 | phpunit.xml 7 | sami.phar 8 | .idea/ -------------------------------------------------------------------------------- /.sami.php: -------------------------------------------------------------------------------- 1 | files() 10 | ->name('*.php') 11 | ->in($dir = 'src') 12 | ; 13 | 14 | return new Sami($iterator, array( 15 | 'title' => 'PHP-FFMpeg API', 16 | 'theme' => 'enhanced', 17 | 'build_dir' => __DIR__.'/docs/source/API/API', 18 | 'cache_dir' => __DIR__.'/docs/source/API/API/cache', 19 | 'default_opened_level' => 2, 20 | )); 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | dist: trusty 4 | 5 | branches: 6 | only: 7 | - master 8 | - v1.x 9 | 10 | cache: 11 | directories: 12 | - $HOME/.composer/cache 13 | - $HOME/.cache 14 | 15 | php: 16 | - 5.4 17 | - 5.5 18 | - 5.6 19 | - 7.0 20 | - 7.1 21 | - 7.2 22 | 23 | matrix: 24 | include: 25 | - php: 5.4 26 | env: COMPOSER_FLAGS="--prefer-lowest" 27 | 28 | before_install: 29 | - sudo add-apt-repository ppa:mc3man/trusty-media -y 30 | - sudo apt-get update -q 31 | - composer self-update 32 | - if [ "$COMPOSER_FLAGS" == "--prefer-lowest" ]; then composer require "roave/security-advisories" dev-master --no-update; fi; 33 | 34 | install: 35 | - sudo apt-get install -y ffmpeg 36 | - composer update --prefer-dist $COMPOSER_FLAGS 37 | 38 | script: 39 | - vendor/bin/phpunit --verbose 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | PHP-FFmpeg is released with MIT License : 2 | 3 | Copyright (c) 2012 Alchemy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), 7 | to deal in the Software without restriction, including without limitation 8 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | and/or sell copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "php-ffmpeg/php-ffmpeg", 3 | "type": "library", 4 | "description": "FFMpeg PHP, an Object Oriented library to communicate with AVconv / ffmpeg", 5 | "keywords": ["video processing", "video", "audio processing", "audio", "avconv", "ffmpeg", "avprobe", "ffprobe"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Romain Neutron", 10 | "email": "imprec@gmail.com", 11 | "homepage": "http://www.lickmychip.com/" 12 | }, 13 | { 14 | "name": "Phraseanet Team", 15 | "email": "info@alchemy.fr", 16 | "homepage": "http://www.phraseanet.com/" 17 | }, 18 | { 19 | "name": "Patrik Karisch", 20 | "email": "patrik@karisch.guru", 21 | "homepage": "http://www.karisch.guru" 22 | }, 23 | { 24 | "name": "Romain Biard", 25 | "email": "romain.biard@gmail.com", 26 | "homepage": "https://www.strime.io/" 27 | }, 28 | { 29 | "name": "Jens Hausdorf", 30 | "email": "hello@jens-hausdorf.de", 31 | "homepage": "https://jens-hausdorf.de" 32 | } 33 | ], 34 | "require": { 35 | "php": "^5.3.9 || ^7.0", 36 | "alchemy/binary-driver": "^1.5", 37 | "doctrine/cache": "^1.0", 38 | "evenement/evenement": "^2.0 || ^1.0", 39 | "neutron/temporary-filesystem": "^2.1.1" 40 | }, 41 | "suggest": { 42 | "php-ffmpeg/extras": "A compilation of common audio & video drivers for PHP-FFMpeg" 43 | }, 44 | "require-dev": { 45 | "sami/sami": "~1.0", 46 | "silex/silex": "~1.0", 47 | "phpunit/phpunit": "^4.8.36" 48 | }, 49 | "autoload": { 50 | "psr-0": { 51 | "FFMpeg": "src" 52 | } 53 | }, 54 | "autoload-dev": { 55 | "psr-4": { 56 | "Tests\\FFMpeg\\": "tests" 57 | } 58 | }, 59 | "extra": { 60 | "branch-alias": { 61 | "dev-master": "0.7-dev" 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg | PHP-FFMpeg API 7 | 8 | 9 | 10 |
11 | 19 | 20 |
PHP-FFMpeg API
21 | 22 |
Namespace
23 |

FFMpeg

24 |
25 |
26 | 27 | 28 | 29 | 31 | 32 | 33 | 34 | 36 | 37 | 38 | 39 | 41 | 42 |
FFMpeg 30 |
FFMpegServiceProvider 35 |
FFProbe 40 |
43 | 44 | 45 |
46 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Coordinate.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Coordinate | PHP-FFMpeg API 7 | 8 | 9 | 10 |
11 | 19 | 20 |
PHP-FFMpeg API
21 | 22 |
Namespace
23 |

FFMpeg\Coordinate

24 |
25 |
26 | 27 | 28 | 29 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 40 | 41 | 42 | 43 | 45 | 46 | 47 | 48 | 50 | 51 |
AspectRatio 30 |
DimensionDimension object, used for manipulating width and height couples
FrameRate 39 |
Point 44 |
TimeCode 49 |
52 | 53 | 54 |
55 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Coordinate/namespace-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Coordinate | PHP-FFMpeg API 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Driver.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Driver | PHP-FFMpeg API 7 | 8 | 9 | 10 |
11 | 19 | 20 |
PHP-FFMpeg API
21 | 22 |
Namespace
23 |

FFMpeg\Driver

24 |
25 |
26 | 27 | 28 | 29 | 31 | 32 | 33 | 34 | 36 | 37 |
FFMpegDriver 30 |
FFProbeDriver 35 |
38 | 39 | 40 |
41 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Driver/namespace-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Driver | PHP-FFMpeg API 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Exception.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Exception | PHP-FFMpeg API 7 | 8 | 9 | 10 |
11 | 19 | 20 |
PHP-FFMpeg API
21 | 22 |
Namespace
23 |

FFMpeg\Exception

24 |
25 |
26 | 27 | 28 | 29 | 31 | 32 | 33 | 34 | 36 | 37 | 38 | 39 | 41 | 42 | 43 | 44 | 46 | 47 |
ExecutableNotFoundException 30 |
InvalidArgumentException 35 |
LogicException 40 |
RuntimeException 45 |
48 | 49 |

Interfaces

50 | 51 | 52 | 53 | 55 | 56 |
ExceptionInterface 54 |
57 | 58 |
59 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Exception/ExceptionInterface.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Exception\ExceptionInterface | PHP-FFMpeg API 7 | 8 | 9 | 10 |
11 | 19 | 20 |
PHP-FFMpeg API
21 | 22 |
Interface
23 |

FFMpeg\Exception\ExceptionInterface

24 |
25 |
26 |

interface 27 | ExceptionInterface

28 | 29 | 30 | 31 | 32 |
33 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Exception/ExecutableNotFoundException.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Exception\ExecutableNotFoundException | PHP-FFMpeg API 7 | 8 | 9 | 10 |
11 | 19 | 20 |
PHP-FFMpeg API
21 | 22 |
Class
23 |

FFMpeg\Exception\ExecutableNotFoundException

24 |
25 |
26 |

class 27 | ExecutableNotFoundException extends RuntimeException

28 | 29 | 30 | 31 | 32 |
33 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Exception/InvalidArgumentException.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Exception\InvalidArgumentException | PHP-FFMpeg API 7 | 8 | 9 | 10 |
11 | 19 | 20 |
PHP-FFMpeg API
21 | 22 |
Class
23 |

FFMpeg\Exception\InvalidArgumentException

24 |
25 |
26 |

class 27 | InvalidArgumentException extends InvalidArgumentException implements 28 | ExceptionInterface

29 | 30 | 31 | 32 | 33 |
34 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Exception/LogicException.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Exception\LogicException | PHP-FFMpeg API 7 | 8 | 9 | 10 |
11 | 19 | 20 |
PHP-FFMpeg API
21 | 22 |
Class
23 |

FFMpeg\Exception\LogicException

24 |
25 |
26 |

class 27 | LogicException extends LogicException implements 28 | ExceptionInterface

29 | 30 | 31 | 32 | 33 |
34 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Exception/RuntimeException.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Exception\RuntimeException | PHP-FFMpeg API 7 | 8 | 9 | 10 |
11 | 19 | 20 |
PHP-FFMpeg API
21 | 22 |
Class
23 |

FFMpeg\Exception\RuntimeException

24 |
25 |
26 |

class 27 | RuntimeException extends RuntimeException implements 28 | ExceptionInterface

29 | 30 | 31 | 32 | 33 |
34 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Exception/namespace-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Exception | PHP-FFMpeg API 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/FFProbe/DataMapping.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\FFProbe\DataMapping | PHP-FFMpeg API 7 | 8 | 9 | 10 |
11 | 19 | 20 |
PHP-FFMpeg API
21 | 22 |
Namespace
23 |

FFMpeg\FFProbe\DataMapping

24 |
25 |
26 | 27 | 28 | 29 | 31 | 32 | 33 | 34 | 36 | 37 | 38 | 39 | 41 | 42 | 43 | 44 | 46 | 47 |
AbstractData 30 |
Format 35 |
Stream 40 |
StreamCollection 45 |
48 | 49 | 50 |
51 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/FFProbe/DataMapping/namespace-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\FFProbe\DataMapping | PHP-FFMpeg API 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/FFProbe/OptionsTesterInterface.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\FFProbe\OptionsTesterInterface | PHP-FFMpeg API 7 | 8 | 9 | 10 |
11 | 19 | 20 |
PHP-FFMpeg API
21 | 22 |
Interface
23 |

FFMpeg\FFProbe\OptionsTesterInterface

24 |
25 |
26 |

interface 27 | OptionsTesterInterface

28 | 29 | 30 | 31 | 32 |

Methods

33 | 34 | 35 | 36 | 39 | 43 | 44 | 45 |
37 | Boolean 38 | 40 | has(string $name) 41 |

Tells if the given option is supported by ffprobe.

42 |
46 | 47 | 48 |

Details

49 | 50 |

51 |
at line 23
52 | public Boolean 53 | has(string $name) 54 |

55 |
56 |

Tells if the given option is supported by ffprobe.

57 |

58 |

59 |
60 |

Parameters

61 | 62 | 63 | 64 | 65 | 66 | 68 | 69 |
string$name 67 |
70 | 71 | 72 |

Return Value

73 | 74 | 75 | 76 | 77 | 79 | 80 |
Boolean 78 |
81 | 82 | 83 | 84 |
85 |
86 | 87 | 88 |
89 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/FFProbe/namespace-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\FFProbe | PHP-FFMpeg API 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Filters.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Filters | PHP-FFMpeg API 7 | 8 | 9 | 10 |
11 | 19 | 20 |
PHP-FFMpeg API
21 | 22 |
Namespace
23 |

FFMpeg\Filters

24 |
25 |
26 | 27 | 28 | 29 | 31 | 32 |
FiltersCollection 30 |
33 | 34 |

Interfaces

35 | 36 | 37 | 38 | 40 | 41 |
FilterInterface 39 |
42 | 43 |
44 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Filters/Audio.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Filters\Audio | PHP-FFMpeg API 7 | 8 | 9 | 10 |
11 | 19 | 20 |
PHP-FFMpeg API
21 | 22 |
Namespace
23 |

FFMpeg\Filters\Audio

24 |
25 |
26 | 27 | 28 | 29 | 31 | 32 | 33 | 34 | 36 | 37 | 38 | 39 | 41 | 42 |
AudioFilters 30 |
AudioResamplableFilter 35 |
SimpleFilter 40 |
43 | 44 |

Interfaces

45 | 46 | 47 | 48 | 50 | 51 |
AudioFilterInterface 49 |
52 | 53 |
54 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Filters/Audio/namespace-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Filters\Audio | PHP-FFMpeg API 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Filters/FilterInterface.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Filters\FilterInterface | PHP-FFMpeg API 7 | 8 | 9 | 10 |
11 | 19 | 20 |
PHP-FFMpeg API
21 | 22 |
Interface
23 |

FFMpeg\Filters\FilterInterface

24 |
25 |
26 |

interface 27 | FilterInterface

28 | 29 | 30 | 31 | 32 |

Methods

33 | 34 | 35 | 36 | 39 | 43 | 44 | 45 |
37 | integer 38 | 40 | getPriority() 41 |

Returns the priority of the filter.

42 |
46 | 47 | 48 |

Details

49 | 50 |

51 |
at line 21
52 | public integer 53 | getPriority() 54 |

55 |
56 |

Returns the priority of the filter.

57 |

58 |

59 |
60 | 61 |

Return Value

62 | 63 | 64 | 65 | 66 | 68 | 69 |
integer 67 |
70 | 71 | 72 | 73 |
74 |
75 | 76 | 77 |
78 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Filters/Frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Filters\Frame | PHP-FFMpeg API 7 | 8 | 9 | 10 |
11 | 19 | 20 |
PHP-FFMpeg API
21 | 22 |
Namespace
23 |

FFMpeg\Filters\Frame

24 |
25 |
26 | 27 | 28 | 29 | 31 | 32 | 33 | 34 | 36 | 37 |
DisplayRatioFixerFilter 30 |
FrameFilters 35 |
38 | 39 |

Interfaces

40 | 41 | 42 | 43 | 45 | 46 |
FrameFilterInterface 44 |
47 | 48 |
49 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Filters/Frame/namespace-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Filters\Frame | PHP-FFMpeg API 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Filters/Video/namespace-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Filters\Video | PHP-FFMpeg API 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Filters/namespace-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Filters | PHP-FFMpeg API 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Format.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Format | PHP-FFMpeg API 7 | 8 | 9 | 10 |
11 | 19 | 20 |
PHP-FFMpeg API
21 | 22 |
Namespace
23 |

FFMpeg\Format

24 |
25 |
26 | 27 |

Interfaces

28 | 29 | 30 | 31 | 33 | 34 | 35 | 36 | 38 | 39 | 40 | 41 | 43 | 44 | 45 | 46 | 48 | 49 | 50 | 51 | 53 | 54 |
AudioInterface 32 |
FormatInterface 37 |
FrameInterface 42 |
ProgressableInterface 47 |
VideoInterface 52 |
55 | 56 |
57 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Format/Audio.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Format\Audio | PHP-FFMpeg API 7 | 8 | 9 | 10 |
11 | 19 | 20 |
PHP-FFMpeg API
21 | 22 |
Namespace
23 |

FFMpeg\Format\Audio

24 |
25 |
26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 |
AacThe AAC audio format
DefaultAudio 34 |
FlacThe Flac audio format
Mp3The MP3 audio format
VorbisThe Vorbis audio format
WavThe WAV audio format
53 | 54 | 55 |
56 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Format/Audio/namespace-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Format\Audio | PHP-FFMpeg API 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Format/ProgressListener.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Format\ProgressListener | PHP-FFMpeg API 7 | 8 | 9 | 10 |
11 | 19 | 20 |
PHP-FFMpeg API
21 | 22 |
Namespace
23 |

FFMpeg\Format\ProgressListener

24 |
25 |
26 | 27 | 28 | 29 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 |
AbstractProgressListener 30 |
AudioProgressListenerParses ffmpeg stderr progress information.
VideoProgressListenerParses ffmpeg stderr progress information for video files.
41 | 42 | 43 |
44 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Format/ProgressListener/namespace-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Format\ProgressListener | PHP-FFMpeg API 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Format/Video.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Format\Video | PHP-FFMpeg API 7 | 8 | 9 | 10 |
11 | 19 | 20 |
PHP-FFMpeg API
21 | 22 |
Namespace
23 |

FFMpeg\Format\Video

24 |
25 |
26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 |
DefaultVideoThe abstract default Video format
OggThe Ogg video format
WMVThe WMV video format
WMV3The WMV video format
WebMThe WebM video format
X264The X264 video format
52 | 53 | 54 |
55 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Format/Video/namespace-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Format\Video | PHP-FFMpeg API 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Format/namespace-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Format | PHP-FFMpeg API 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Media.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Media | PHP-FFMpeg API 7 | 8 | 9 | 10 |
11 | 19 | 20 |
PHP-FFMpeg API
21 | 22 |
Namespace
23 |

FFMpeg\Media

24 |
25 |
26 | 27 | 28 | 29 | 31 | 32 | 33 | 34 | 36 | 37 | 38 | 39 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 51 | 52 |
AbstractMediaType 30 |
AbstractStreamableMedia 35 |
Audio 40 |
Frame 45 |
Video 50 |
53 | 54 |

Interfaces

55 | 56 | 57 | 58 | 60 | 61 |
MediaTypeInterface 59 |
62 | 63 |
64 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/Media/namespace-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg\Media | PHP-FFMpeg API 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/source/API/API/FFMpeg/namespace-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FFMpeg | PHP-FFMpeg API 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/source/API/API/PROJECT_VERSION: -------------------------------------------------------------------------------- 1 | master -------------------------------------------------------------------------------- /docs/source/API/API/SAMI_VERSION: -------------------------------------------------------------------------------- 1 | 1.4-DEV -------------------------------------------------------------------------------- /docs/source/API/API/classes-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | All Classes | PHP-FFMpeg API 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/source/API/API/css/reset.css: -------------------------------------------------------------------------------- 1 | /* http://meyerweb.com/eric/tools/css/reset/ */ 2 | /* v1.0 | 20080212 */ 3 | 4 | html, body, div, span, applet, object, iframe, 5 | h1, h2, h3, h4, h5, h6, p, blockquote, pre, 6 | a, abbr, acronym, address, big, cite, code, 7 | del, dfn, em, font, img, ins, kbd, q, s, samp, 8 | small, strike, strong, sub, sup, tt, var, 9 | b, u, i, center, 10 | dl, dt, dd, ol, ul, li, 11 | fieldset, form, label, legend, 12 | table, caption, tbody, tfoot, thead, tr, th, td { 13 | margin: 0; 14 | padding: 0; 15 | border: 0; 16 | outline: 0; 17 | font-size: 100%; 18 | vertical-align: baseline; 19 | background: transparent; 20 | } 21 | body { 22 | line-height: 1; 23 | } 24 | ol, ul { 25 | list-style: none; 26 | } 27 | blockquote, q { 28 | quotes: none; 29 | } 30 | blockquote:before, blockquote:after, 31 | q:before, q:after { 32 | content: ''; 33 | content: none; 34 | } 35 | 36 | /* remember to define focus styles! */ 37 | :focus { 38 | outline: 0; 39 | } 40 | 41 | /* remember to highlight inserts somehow! */ 42 | ins { 43 | text-decoration: none; 44 | } 45 | del { 46 | text-decoration: line-through; 47 | } 48 | 49 | /* tables still need 'cellspacing="0"' in the markup */ 50 | table { 51 | border-collapse: collapse; 52 | border-spacing: 0; 53 | } -------------------------------------------------------------------------------- /docs/source/API/API/i/arrows.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alchemy-fr/PHP-FFMpeg/a1d5fa51ba94929c93e9a03dce16990d6ca177bc/docs/source/API/API/i/arrows.png -------------------------------------------------------------------------------- /docs/source/API/API/i/loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alchemy-fr/PHP-FFMpeg/a1d5fa51ba94929c93e9a03dce16990d6ca177bc/docs/source/API/API/i/loader.gif -------------------------------------------------------------------------------- /docs/source/API/API/i/results_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alchemy-fr/PHP-FFMpeg/a1d5fa51ba94929c93e9a03dce16990d6ca177bc/docs/source/API/API/i/results_bg.png -------------------------------------------------------------------------------- /docs/source/API/API/i/tree_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alchemy-fr/PHP-FFMpeg/a1d5fa51ba94929c93e9a03dce16990d6ca177bc/docs/source/API/API/i/tree_bg.png -------------------------------------------------------------------------------- /docs/source/API/API/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | PHP-FFMpeg API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | <body> 17 | Your browser does not support frames. Go to the <a href="namespaces.html">non-frame version</a>. 18 | </body> 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/source/API/API/js/permalink.js: -------------------------------------------------------------------------------- 1 | jQuery(document).ready( 2 | function () { 3 | var hash = window.location.hash.replace(/^#/, ''); 4 | 5 | if (hash) { 6 | jQuery('#main-frame').attr('src', hash); 7 | 8 | if (history.pushState) { 9 | history.pushState( 10 | '', 11 | document.title, 12 | window.location.pathname + window.location.search 13 | ); 14 | } 15 | } 16 | } 17 | ); 18 | -------------------------------------------------------------------------------- /docs/source/API/API/namespaces-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Namespaces | PHP-FFMpeg API 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/source/API/API/opensearch.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alchemy-fr/PHP-FFMpeg/a1d5fa51ba94929c93e9a03dce16990d6ca177bc/docs/source/API/API/opensearch.xml -------------------------------------------------------------------------------- /docs/source/API/API/panel.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | PHP-FFMpeg API 5 | 6 | 7 | 8 | 9 | 10 | 46 | 47 | 48 |
49 |
50 | loading... 51 |
52 |
53 | 60 |
61 |
62 | 64 |
65 |
66 | 68 |
69 |
70 | 71 | 72 | -------------------------------------------------------------------------------- /docs/source/API/API/traits.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Traits | PHP-FFMpeg API 7 | 8 | 9 | 10 |
11 | 19 | 20 |
PHP-FFMpeg API
21 | 22 |

Traits

23 |
24 |
25 | 26 |
27 |
28 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | tests/Unit 17 | 18 | 19 | tests/Functional 20 | 21 | 22 | 23 | 24 | 25 | vendor 26 | tests 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/FFMpeg/Coordinate/Dimension.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Coordinate; 13 | 14 | use FFMpeg\Exception\InvalidArgumentException; 15 | 16 | /** 17 | * Dimension object, used for manipulating width and height couples 18 | */ 19 | class Dimension 20 | { 21 | private $width; 22 | private $height; 23 | 24 | /** 25 | * @param integer $width 26 | * @param integer $height 27 | * 28 | * @throws InvalidArgumentException when one of the parameteres is invalid 29 | */ 30 | public function __construct($width, $height) 31 | { 32 | if ($width <= 0 || $height <= 0) { 33 | throw new InvalidArgumentException('Width and height should be positive integer'); 34 | } 35 | 36 | $this->width = (int) $width; 37 | $this->height = (int) $height; 38 | } 39 | 40 | /** 41 | * Returns width. 42 | * 43 | * @return integer 44 | */ 45 | public function getWidth() 46 | { 47 | return $this->width; 48 | } 49 | 50 | /** 51 | * Returns height. 52 | * 53 | * @return integer 54 | */ 55 | public function getHeight() 56 | { 57 | return $this->height; 58 | } 59 | 60 | /** 61 | * Returns the ratio. 62 | * 63 | * @param type $forceStandards Whether or not force the use of standards ratios; 64 | * 65 | * @return AspectRatio 66 | */ 67 | public function getRatio($forceStandards = true) 68 | { 69 | return AspectRatio::create($this, $forceStandards); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/FFMpeg/Coordinate/FrameRate.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Coordinate; 13 | 14 | use FFMpeg\Exception\InvalidArgumentException; 15 | 16 | class FrameRate 17 | { 18 | private $value; 19 | 20 | public function __construct($value) 21 | { 22 | if ($value <= 0) { 23 | throw new InvalidArgumentException('Invalid frame rate, must be positive value.'); 24 | } 25 | 26 | $this->value = $value; 27 | } 28 | 29 | /** 30 | * @return float 31 | */ 32 | public function getValue() 33 | { 34 | return $this->value; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/FFMpeg/Coordinate/Point.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Coordinate; 13 | 14 | class Point 15 | { 16 | private $x; 17 | private $y; 18 | 19 | public function __construct($x, $y, $dynamic = false) 20 | { 21 | if ($dynamic) { 22 | $this->x = $x; 23 | $this->y = $y; 24 | } else { 25 | $this->x = (int)$x; 26 | $this->y = (int)$y; 27 | } 28 | } 29 | 30 | /** 31 | * @return integer 32 | */ 33 | public function getX() 34 | { 35 | return $this->x; 36 | } 37 | 38 | /** 39 | * @return integer 40 | */ 41 | public function getY() 42 | { 43 | return $this->y; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/FFMpeg/Driver/FFMpegDriver.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Driver; 13 | 14 | use Alchemy\BinaryDriver\AbstractBinary; 15 | use Alchemy\BinaryDriver\Configuration; 16 | use Alchemy\BinaryDriver\ConfigurationInterface; 17 | use Alchemy\BinaryDriver\Exception\ExecutableNotFoundException as BinaryDriverExecutableNotFound; 18 | use FFMpeg\Exception\ExecutableNotFoundException; 19 | use Psr\Log\LoggerInterface; 20 | 21 | class FFMpegDriver extends AbstractBinary 22 | { 23 | /** 24 | * {@inheritdoc} 25 | */ 26 | public function getName() 27 | { 28 | return 'ffmpeg'; 29 | } 30 | 31 | /** 32 | * Creates an FFMpegDriver. 33 | * 34 | * @param LoggerInterface $logger 35 | * @param array|Configuration $configuration 36 | * 37 | * @return FFMpegDriver 38 | */ 39 | public static function create(LoggerInterface $logger = null, $configuration = array()) 40 | { 41 | if (!$configuration instanceof ConfigurationInterface) { 42 | $configuration = new Configuration($configuration); 43 | } 44 | 45 | $binaries = $configuration->get('ffmpeg.binaries', array('avconv', 'ffmpeg')); 46 | 47 | if (!$configuration->has('timeout')) { 48 | $configuration->set('timeout', 300); 49 | } 50 | 51 | try { 52 | return static::load($binaries, $logger, $configuration); 53 | } catch (BinaryDriverExecutableNotFound $e) { 54 | throw new ExecutableNotFoundException('Unable to load FFMpeg', $e->getCode(), $e); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/FFMpeg/Driver/FFProbeDriver.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Driver; 13 | 14 | use Alchemy\BinaryDriver\AbstractBinary; 15 | use Alchemy\BinaryDriver\Configuration; 16 | use Alchemy\BinaryDriver\ConfigurationInterface; 17 | use Alchemy\BinaryDriver\Exception\ExecutableNotFoundException as BinaryDriverExecutableNotFound; 18 | use FFMpeg\Exception\ExecutableNotFoundException; 19 | use Psr\Log\LoggerInterface; 20 | 21 | class FFProbeDriver extends AbstractBinary 22 | { 23 | /** 24 | * {@inheritdoc} 25 | */ 26 | public function getName() 27 | { 28 | return 'ffprobe'; 29 | } 30 | 31 | /** 32 | * Creates an FFProbeDriver. 33 | * 34 | * @param array|ConfigurationInterface $configuration 35 | * @param LoggerInterface $logger 36 | * 37 | * @return FFProbeDriver 38 | */ 39 | public static function create($configuration, LoggerInterface $logger = null) 40 | { 41 | if (!$configuration instanceof ConfigurationInterface) { 42 | $configuration = new Configuration($configuration); 43 | } 44 | 45 | $binaries = $configuration->get('ffprobe.binaries', array('avprobe', 'ffprobe')); 46 | 47 | try { 48 | return static::load($binaries, $logger, $configuration); 49 | } catch (BinaryDriverExecutableNotFound $e) { 50 | throw new ExecutableNotFoundException('Unable to load FFProbe', $e->getCode(), $e); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/FFMpeg/Exception/ExceptionInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Exception; 13 | 14 | interface ExceptionInterface 15 | { 16 | } 17 | -------------------------------------------------------------------------------- /src/FFMpeg/Exception/ExecutableNotFoundException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Exception; 13 | 14 | class ExecutableNotFoundException extends RuntimeException 15 | { 16 | } 17 | -------------------------------------------------------------------------------- /src/FFMpeg/Exception/InvalidArgumentException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Exception; 13 | 14 | class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface 15 | { 16 | } 17 | -------------------------------------------------------------------------------- /src/FFMpeg/Exception/LogicException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Exception; 13 | 14 | class LogicException extends \LogicException implements ExceptionInterface 15 | { 16 | } 17 | -------------------------------------------------------------------------------- /src/FFMpeg/Exception/RuntimeException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Exception; 13 | 14 | class RuntimeException extends \RuntimeException implements ExceptionInterface 15 | { 16 | } 17 | -------------------------------------------------------------------------------- /src/FFMpeg/FFMpegServiceProvider.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg; 13 | 14 | use Doctrine\Common\Cache\ArrayCache; 15 | use Silex\Application; 16 | use Silex\ServiceProviderInterface; 17 | 18 | class FFMpegServiceProvider implements ServiceProviderInterface 19 | { 20 | public function register(Application $app) 21 | { 22 | $app['ffmpeg.configuration'] = array(); 23 | $app['ffmpeg.default.configuration'] = array( 24 | 'ffmpeg.threads' => 4, 25 | 'ffmpeg.timeout' => 300, 26 | 'ffmpeg.binaries' => array('avconv', 'ffmpeg'), 27 | 'ffprobe.timeout' => 30, 28 | 'ffprobe.binaries' => array('avprobe', 'ffprobe'), 29 | ); 30 | $app['ffmpeg.logger'] = null; 31 | 32 | $app['ffmpeg.configuration.build'] = $app->share(function (Application $app) { 33 | return array_replace($app['ffmpeg.default.configuration'], $app['ffmpeg.configuration']); 34 | }); 35 | 36 | $app['ffmpeg'] = $app['ffmpeg.ffmpeg'] = $app->share(function (Application $app) { 37 | $configuration = $app['ffmpeg.configuration.build']; 38 | 39 | if (isset($configuration['ffmpeg.timeout'])) { 40 | $configuration['timeout'] = $configuration['ffmpeg.timeout']; 41 | } 42 | 43 | return FFMpeg::create($configuration, $app['ffmpeg.logger'], $app['ffmpeg.ffprobe']); 44 | }); 45 | 46 | $app['ffprobe.cache'] = $app->share(function () { 47 | return new ArrayCache(); 48 | }); 49 | 50 | $app['ffmpeg.ffprobe'] = $app->share(function (Application $app) { 51 | $configuration = $app['ffmpeg.configuration.build']; 52 | 53 | if (isset($configuration['ffmpeg.timeout'])) { 54 | $configuration['timeout'] = $configuration['ffprobe.timeout']; 55 | } 56 | 57 | return FFProbe::create($configuration, $app['ffmpeg.logger'], $app['ffprobe.cache']); 58 | }); 59 | } 60 | 61 | public function boot(Application $app) 62 | { 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/FFMpeg/FFProbe/DataMapping/AbstractData.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\FFProbe\DataMapping; 13 | 14 | abstract class AbstractData implements \Countable 15 | { 16 | private $properties; 17 | 18 | public function __construct(array $properties) 19 | { 20 | $this->properties = $properties; 21 | } 22 | 23 | /** 24 | * Returns true if data has property. 25 | * 26 | * @param string $property 27 | * @return Boolean 28 | */ 29 | public function has($property) 30 | { 31 | return isset($this->properties[$property]); 32 | } 33 | 34 | /** 35 | * Returns the property value given its name. 36 | * 37 | * @param string $property 38 | * @param mixed $default 39 | * 40 | * @return mixed 41 | */ 42 | public function get($property, $default = null) 43 | { 44 | if (!isset($this->properties[$property])) { 45 | return $default; 46 | } 47 | 48 | return $this->properties[$property]; 49 | } 50 | 51 | /** 52 | * Sets the property value given its name. 53 | * 54 | * @param string $property 55 | * @param mixed $value 56 | * 57 | * @return AbstractData 58 | */ 59 | public function set($property, $value) 60 | { 61 | $this->properties[$property] = $value; 62 | 63 | return $this; 64 | } 65 | 66 | /** 67 | * Returns all property names. 68 | * 69 | * @return array 70 | */ 71 | public function keys() 72 | { 73 | return array_keys($this->properties); 74 | } 75 | 76 | /** 77 | * Returns all properties and their values. 78 | * 79 | * @return array 80 | */ 81 | public function all() 82 | { 83 | return $this->properties; 84 | } 85 | 86 | /** 87 | * {@inheritdoc} 88 | */ 89 | public function count() 90 | { 91 | return count($this->properties); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/FFMpeg/FFProbe/DataMapping/Format.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\FFProbe\DataMapping; 13 | 14 | class Format extends AbstractData 15 | { 16 | } 17 | -------------------------------------------------------------------------------- /src/FFMpeg/FFProbe/DataMapping/StreamCollection.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\FFProbe\DataMapping; 13 | 14 | class StreamCollection implements \Countable, \IteratorAggregate 15 | { 16 | private $streams; 17 | 18 | public function __construct(array $streams = array()) 19 | { 20 | $this->streams = array_values($streams); 21 | } 22 | 23 | /** 24 | * Returns the first stream of the collection, null if the collection is 25 | * empty. 26 | * 27 | * @return null|Stream 28 | */ 29 | public function first() 30 | { 31 | $stream = reset($this->streams); 32 | 33 | return $stream ?: null; 34 | } 35 | 36 | /** 37 | * Adds a stream to the collection. 38 | * 39 | * @param Stream $stream 40 | * 41 | * @return StreamCollection 42 | */ 43 | public function add(Stream $stream) 44 | { 45 | $this->streams[] = $stream; 46 | 47 | return $this; 48 | } 49 | 50 | /** 51 | * Returns a new StreamCollection with only video streams. 52 | * 53 | * @return StreamCollection 54 | */ 55 | public function videos() 56 | { 57 | return new static(array_filter($this->streams, function (Stream $stream) { 58 | return $stream->isVideo(); 59 | })); 60 | } 61 | 62 | /** 63 | * Returns a new StreamCollection with only audio streams. 64 | * 65 | * @return StreamCollection 66 | */ 67 | public function audios() 68 | { 69 | return new static(array_filter($this->streams, function (Stream $stream) { 70 | return $stream->isAudio(); 71 | })); 72 | } 73 | 74 | /** 75 | * {@inheritdoc} 76 | */ 77 | public function count() 78 | { 79 | return count($this->streams); 80 | } 81 | 82 | /** 83 | * Returns the array of contained streams. 84 | * 85 | * @return array 86 | */ 87 | public function all() 88 | { 89 | return $this->streams; 90 | } 91 | 92 | /** 93 | * {@inheritdoc} 94 | */ 95 | public function getIterator() 96 | { 97 | return new \ArrayIterator($this->streams); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/FFMpeg/FFProbe/Mapper.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\FFProbe; 13 | 14 | use FFMpeg\FFProbe; 15 | use FFMpeg\FFProbe\DataMapping\Format; 16 | use FFMpeg\FFProbe\DataMapping\StreamCollection; 17 | use FFMpeg\FFProbe\DataMapping\Stream; 18 | use FFMpeg\Exception\InvalidArgumentException; 19 | 20 | class Mapper implements MapperInterface 21 | { 22 | /** 23 | * {@inheritdoc} 24 | */ 25 | public function map($type, $data) 26 | { 27 | switch ($type) { 28 | case FFProbe::TYPE_FORMAT: 29 | return $this->mapFormat($data); 30 | case FFProbe::TYPE_STREAMS: 31 | return $this->mapStreams($data); 32 | default: 33 | throw new InvalidArgumentException(sprintf( 34 | 'Invalid type `%s`.', $type 35 | )); 36 | } 37 | } 38 | 39 | private function mapFormat($data) 40 | { 41 | return new Format($data['format']); 42 | } 43 | 44 | private function mapStreams($data) 45 | { 46 | $streams = new StreamCollection(); 47 | 48 | foreach ($data['streams'] as $properties) { 49 | $streams->add(new Stream($properties)); 50 | } 51 | 52 | return $streams; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/FFMpeg/FFProbe/MapperInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\FFProbe; 13 | 14 | interface MapperInterface 15 | { 16 | /** 17 | * Maps data given its type. 18 | * 19 | * @param string $type One of FFProbe::TYPE_* constant 20 | * @param string $data The data 21 | * 22 | * @return Format|Stream 23 | * 24 | * @throws InvalidArgumentException In case the type is not supported 25 | */ 26 | public function map($type, $data); 27 | } 28 | -------------------------------------------------------------------------------- /src/FFMpeg/FFProbe/OptionsTester.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\FFProbe; 13 | 14 | use Alchemy\BinaryDriver\Exception\ExecutionFailureException; 15 | use Doctrine\Common\Cache\Cache; 16 | use FFMpeg\Driver\FFProbeDriver; 17 | use FFMpeg\Exception\RuntimeException; 18 | 19 | class OptionsTester implements OptionsTesterInterface 20 | { 21 | /** @var FFProbeDriver */ 22 | private $ffprobe; 23 | /** @var Cache */ 24 | private $cache; 25 | 26 | public function __construct(FFProbeDriver $ffprobe, Cache $cache) 27 | { 28 | $this->ffprobe = $ffprobe; 29 | $this->cache = $cache; 30 | } 31 | 32 | /** 33 | * {@inheritdoc} 34 | */ 35 | public function has($name) 36 | { 37 | $id = sprintf('option-%s', $name); 38 | 39 | if ($this->cache->contains($id)) { 40 | return $this->cache->fetch($id); 41 | } 42 | 43 | $output = $this->retrieveHelpOutput(); 44 | 45 | $ret = (Boolean) preg_match('/^'.$name.'/m', $output); 46 | 47 | $this->cache->save($id, $ret); 48 | 49 | return $ret; 50 | } 51 | 52 | private function retrieveHelpOutput() 53 | { 54 | $id = 'help'; 55 | 56 | if ($this->cache->contains($id)) { 57 | return $this->cache->fetch($id); 58 | } 59 | 60 | try { 61 | $output = $this->ffprobe->command(array('-help', '-loglevel', 'quiet')); 62 | } catch (ExecutionFailureException $e) { 63 | throw new RuntimeException('Your FFProbe version is too old and does not support `-help` option, please upgrade.', $e->getCode(), $e); 64 | } 65 | 66 | $this->cache->save($id, $output); 67 | 68 | return $output; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/FFMpeg/FFProbe/OptionsTesterInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\FFProbe; 13 | 14 | interface OptionsTesterInterface 15 | { 16 | /** 17 | * Tells if the given option is supported by ffprobe. 18 | * 19 | * @param string $name 20 | * 21 | * @return Boolean 22 | */ 23 | public function has($name); 24 | } 25 | -------------------------------------------------------------------------------- /src/FFMpeg/FFProbe/OutputParserInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\FFProbe; 13 | 14 | interface OutputParserInterface 15 | { 16 | /** 17 | * Parses ffprobe raw output. 18 | * 19 | * @param string $type One of FFProbe::TYPE_* constant 20 | * @param string $data The data 21 | * 22 | * @return array 23 | * 24 | * @throws InvalidArgumentException In case the type is not supported 25 | */ 26 | public function parse($type, $data); 27 | } 28 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Audio/AddMetadataFilter.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Audio; 13 | 14 | use FFMpeg\Filters\Audio\AudioFilterInterface; 15 | use FFMpeg\Format\AudioInterface; 16 | use FFMpeg\Media\Audio; 17 | 18 | class AddMetadataFilter implements AudioFilterInterface 19 | { 20 | /** @var Array */ 21 | private $metaArr; 22 | /** @var Integer */ 23 | private $priority; 24 | 25 | function __construct($metaArr = null, $priority = 9) 26 | { 27 | $this->metaArr = $metaArr; 28 | $this->priority = $priority; 29 | } 30 | 31 | public function getPriority() 32 | { 33 | //must be of high priority in case theres a second input stream (artwork) to register with audio 34 | return $this->priority; 35 | } 36 | 37 | public function apply(Audio $audio, AudioInterface $format) 38 | { 39 | $meta = $this->metaArr; 40 | 41 | if (is_null($meta)) { 42 | return ['-map_metadata', '-1', '-vn']; 43 | } 44 | 45 | $metadata = []; 46 | 47 | if (array_key_exists("artwork", $meta)) { 48 | array_push($metadata, "-i", $meta['artwork'], "-map", "0", "-map", "1"); 49 | unset($meta['artwork']); 50 | } 51 | 52 | foreach ($meta as $k => $v) { 53 | array_push($metadata, "-metadata", "$k=$v"); 54 | } 55 | 56 | return $metadata; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Audio/AudioClipFilter.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Audio; 13 | 14 | use FFMpeg\Coordinate\TimeCode; 15 | use FFMpeg\Format\AudioInterface; 16 | use FFMpeg\Media\Audio; 17 | 18 | class AudioClipFilter implements AudioFilterInterface { 19 | 20 | /** 21 | * @var TimeCode 22 | */ 23 | private $start; 24 | 25 | /** 26 | * @var TimeCode 27 | */ 28 | private $duration; 29 | 30 | /** 31 | * @var int 32 | */ 33 | private $priority; 34 | 35 | 36 | public function __construct(TimeCode $start, TimeCode $duration = null, $priority = 0) { 37 | $this->start = $start; 38 | $this->duration = $duration; 39 | $this->priority = $priority; 40 | } 41 | 42 | /** 43 | * @inheritDoc 44 | */ 45 | public function getPriority() { 46 | return $this->priority; 47 | } 48 | 49 | /** 50 | * Returns the start position the audio is being cutted 51 | * 52 | * @return TimeCode 53 | */ 54 | public function getStart() { 55 | return $this->start; 56 | } 57 | 58 | /** 59 | * Returns how long the audio is being cutted. Returns null when the duration is infinite, 60 | * 61 | * @return TimeCode|null 62 | */ 63 | public function getDuration() { 64 | return $this->duration; 65 | } 66 | 67 | /** 68 | * @inheritDoc 69 | */ 70 | public function apply(Audio $audio, AudioInterface $format) { 71 | $commands = array('-ss', (string) $this->start); 72 | 73 | if ($this->duration !== null) { 74 | $commands[] = '-t'; 75 | $commands[] = (string) $this->duration; 76 | } 77 | 78 | $commands[] = '-acodec'; 79 | $commands[] = 'copy'; 80 | 81 | return $commands; 82 | } 83 | 84 | } -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Audio/AudioFilterInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Audio; 13 | 14 | use FFMpeg\Filters\FilterInterface; 15 | use FFMpeg\Format\AudioInterface; 16 | use FFMpeg\Media\Audio; 17 | 18 | interface AudioFilterInterface extends FilterInterface 19 | { 20 | /** 21 | * Applies the filter on the the Audio media given an format. 22 | * 23 | * @param Audio $audio 24 | * @param AudioInterface $format 25 | * 26 | * @return array An array of arguments 27 | */ 28 | public function apply(Audio $audio, AudioInterface $format); 29 | } 30 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Audio/AudioFilters.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Audio; 13 | 14 | use FFMpeg\Filters\Audio\AddMetadataFilter; 15 | use FFMpeg\Media\Audio; 16 | use FFMpeg\Coordinate\TimeCode; 17 | 18 | class AudioFilters 19 | { 20 | protected $media; 21 | 22 | public function __construct(Audio $media) 23 | { 24 | $this->media = $media; 25 | } 26 | 27 | /** 28 | * Resamples the audio file. 29 | * 30 | * @param Integer $rate 31 | * 32 | * @return AudioFilters 33 | */ 34 | public function resample($rate) 35 | { 36 | $this->media->addFilter(new AudioResamplableFilter($rate)); 37 | 38 | return $this; 39 | } 40 | 41 | /** 42 | * Add metadata to an audio file. If no arguments are given then filter 43 | * will remove all metadata from the audio file 44 | * @param Array|Null $data If array must contain one of these key/value pairs: 45 | * - "title": Title metadata 46 | * - "artist": Artist metadata 47 | * - "composer": Composer metadata 48 | * - "album": Album metadata 49 | * - "track": Track metadata 50 | * - "artwork": Song artwork. String of file path 51 | * - "year": Year metadata 52 | * - "genre": Genre metadata 53 | * - "description": Description metadata 54 | */ 55 | public function addMetadata($data = null) 56 | { 57 | $this->media->addFilter(new AddMetadataFilter($data)); 58 | 59 | return $this; 60 | } 61 | 62 | /** 63 | * Cuts the audio at `$start`, optionally define the end 64 | * 65 | * @param TimeCode $start Where the clipping starts(seek to time) 66 | * @param TimeCode $duration How long the clipped audio should be 67 | * @return AudioFilters 68 | */ 69 | public function clip($start, $duration = null) { 70 | $this->media->addFilter(new AudioClipFilter($start, $duration)); 71 | 72 | return $this; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Audio/AudioResamplableFilter.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Audio; 13 | 14 | use FFMpeg\Format\AudioInterface; 15 | use FFMpeg\Media\Audio; 16 | 17 | class AudioResamplableFilter implements AudioFilterInterface 18 | { 19 | /** @var string */ 20 | private $rate; 21 | /** @var integer */ 22 | private $priority; 23 | 24 | public function __construct($rate, $priority = 0) 25 | { 26 | $this->rate = $rate; 27 | $this->priority = $priority; 28 | } 29 | 30 | /** 31 | * {@inheritdoc} 32 | */ 33 | public function getPriority() 34 | { 35 | return $this->priority; 36 | } 37 | 38 | /** 39 | * 40 | * @return Integer 41 | */ 42 | public function getRate() 43 | { 44 | return $this->rate; 45 | } 46 | 47 | /** 48 | * {@inheritdoc} 49 | */ 50 | public function apply(Audio $audio, AudioInterface $format) 51 | { 52 | return array('-ac', 2, '-ar', $this->rate); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Audio/SimpleFilter.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Audio; 13 | 14 | use FFMpeg\Media\Audio; 15 | use FFMpeg\Format\AudioInterface; 16 | 17 | class SimpleFilter implements AudioFilterInterface 18 | { 19 | private $params; 20 | private $priority; 21 | 22 | public function __construct(array $params, $priority = 0) 23 | { 24 | $this->params = $params; 25 | $this->priority = $priority; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function getPriority() 32 | { 33 | return $this->priority; 34 | } 35 | 36 | /** 37 | * {@inheritdoc} 38 | */ 39 | public function apply(Audio $audio, AudioInterface $format) 40 | { 41 | return $this->params; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Concat/ConcatFilterInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Concat; 13 | 14 | use FFMpeg\Filters\FilterInterface; 15 | use FFMpeg\Media\Concat; 16 | 17 | interface ConcatFilterInterface extends FilterInterface 18 | { 19 | public function apply(Concat $concat); 20 | } 21 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Concat/ConcatFilters.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Concat; 13 | 14 | use FFMpeg\Media\Concat; 15 | 16 | class ConcatFilters 17 | { 18 | private $concat; 19 | 20 | public function __construct(Concat $concat) 21 | { 22 | $this->concat = $concat; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/FilterInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters; 13 | 14 | interface FilterInterface 15 | { 16 | /** 17 | * Returns the priority of the filter. 18 | * 19 | * @return integer 20 | */ 21 | public function getPriority(); 22 | } 23 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/FiltersCollection.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters; 13 | 14 | class FiltersCollection implements \Countable, \IteratorAggregate 15 | { 16 | private $sorted; 17 | private $filters = array(); 18 | 19 | /** 20 | * @param FilterInterface $filter 21 | * 22 | * @return FiltersCollection 23 | */ 24 | public function add(FilterInterface $filter) 25 | { 26 | $this->filters[$filter->getPriority()][] = $filter; 27 | $this->sorted = null; 28 | 29 | return $this; 30 | } 31 | 32 | /** 33 | * {@inheritdoc} 34 | */ 35 | public function count() 36 | { 37 | if (0 === count($this->filters)) { 38 | return 0; 39 | } 40 | 41 | return count(call_user_func_array('array_merge', $this->filters)); 42 | } 43 | 44 | /** 45 | * {@inheritdoc} 46 | */ 47 | public function getIterator() 48 | { 49 | if (null === $this->sorted) { 50 | if (0 === count($this->filters)) { 51 | $this->sorted = $this->filters; 52 | } else { 53 | krsort($this->filters); 54 | $this->sorted = call_user_func_array('array_merge', $this->filters); 55 | } 56 | } 57 | 58 | return new \ArrayIterator($this->sorted); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Frame/DisplayRatioFixerFilter.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Frame; 13 | 14 | use FFMpeg\Exception\RuntimeException; 15 | use FFMpeg\Media\Frame; 16 | 17 | class DisplayRatioFixerFilter implements FrameFilterInterface 18 | { 19 | /** @var integer */ 20 | private $priority; 21 | 22 | public function __construct($priority = 0) 23 | { 24 | $this->priority = $priority; 25 | } 26 | 27 | /** 28 | * {@inheritdoc} 29 | */ 30 | public function getPriority() 31 | { 32 | return $this->priority; 33 | } 34 | 35 | /** 36 | * {@inheritdoc} 37 | */ 38 | public function apply(Frame $frame) 39 | { 40 | $dimensions = null; 41 | $commands = array(); 42 | 43 | foreach ($frame->getVideo()->getStreams() as $stream) { 44 | if ($stream->isVideo()) { 45 | try { 46 | $dimensions = $stream->getDimensions(); 47 | $commands[] = '-s'; 48 | $commands[] = $dimensions->getWidth() . 'x' . $dimensions->getHeight(); 49 | break; 50 | } catch (RuntimeException $e) { 51 | 52 | } 53 | } 54 | } 55 | 56 | return $commands; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Frame/FrameFilterInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Frame; 13 | 14 | use FFMpeg\Filters\FilterInterface; 15 | use FFMpeg\Media\Frame; 16 | 17 | interface FrameFilterInterface extends FilterInterface 18 | { 19 | public function apply(Frame $frame); 20 | } 21 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Frame/FrameFilters.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Frame; 13 | 14 | use FFMpeg\Media\Frame; 15 | 16 | class FrameFilters 17 | { 18 | private $frame; 19 | 20 | public function __construct(Frame $frame) 21 | { 22 | $this->frame = $frame; 23 | } 24 | 25 | /** 26 | * Fixes the display ratio of the output frame. 27 | * 28 | * In case the sample ratio and display ratio are different, image may be 29 | * anamorphozed. This filter fixes this by specifying the output size. 30 | * 31 | * @return FrameFilters 32 | */ 33 | public function fixDisplayRatio() 34 | { 35 | $this->frame->addFilter(new DisplayRatioFixerFilter()); 36 | 37 | return $this; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Gif/GifFilterInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Gif; 13 | 14 | use FFMpeg\Filters\FilterInterface; 15 | use FFMpeg\Media\Gif; 16 | 17 | interface GifFilterInterface extends FilterInterface 18 | { 19 | public function apply(Gif $gif); 20 | } 21 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Gif/GifFilters.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Gif; 13 | 14 | use FFMpeg\Media\Gif; 15 | 16 | class GifFilters 17 | { 18 | private $gif; 19 | 20 | public function __construct(Gif $gif) 21 | { 22 | $this->gif = $gif; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Video/ClipFilter.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Video; 13 | 14 | use FFMpeg\Format\VideoInterface; 15 | use FFMpeg\Media\Video; 16 | use FFMpeg\Coordinate\TimeCode; 17 | 18 | class ClipFilter implements VideoFilterInterface 19 | { 20 | /** @var TimeCode */ 21 | private $start; 22 | /** @var TimeCode */ 23 | private $duration; 24 | /** @var integer */ 25 | private $priority; 26 | 27 | public function __construct(TimeCode $start, TimeCode $duration = null, $priority = 0) 28 | { 29 | $this->start = $start; 30 | $this->duration = $duration; 31 | $this->priority = $priority; 32 | } 33 | 34 | /** 35 | * {@inheritdoc} 36 | */ 37 | public function getPriority() 38 | { 39 | return $this->priority; 40 | } 41 | 42 | /** 43 | * @return TimeCode 44 | */ 45 | public function getStart() 46 | { 47 | return $this->start; 48 | } 49 | 50 | /** 51 | * @return TimeCode 52 | */ 53 | public function getDuration() 54 | { 55 | return $this->duration; 56 | } 57 | 58 | /** 59 | * {@inheritdoc} 60 | */ 61 | public function apply(Video $video, VideoInterface $format) 62 | { 63 | $commands = array('-ss', (string) $this->start); 64 | 65 | if ($this->duration !== null) { 66 | $commands[] = '-t'; 67 | $commands[] = (string) $this->duration; 68 | } 69 | 70 | return $commands; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Video/CropFilter.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace FFMpeg\Filters\Video; 12 | 13 | use FFMpeg\Coordinate\Dimension; 14 | use FFMpeg\Coordinate\Point; 15 | use FFMpeg\Format\VideoInterface; 16 | use FFMpeg\Media\Video; 17 | 18 | class CropFilter implements VideoFilterInterface 19 | { 20 | /** @var integer */ 21 | protected $priority; 22 | /** @var Dimension */ 23 | protected $dimension; 24 | /** @var Point */ 25 | protected $point; 26 | 27 | public function __construct(Point $point, Dimension $dimension, $priority = 0) 28 | { 29 | $this->priority = $priority; 30 | $this->dimension = $dimension; 31 | $this->point = $point; 32 | } 33 | 34 | /** 35 | * {@inheritdoc} 36 | */ 37 | public function getPriority() 38 | { 39 | return $this->priority; 40 | } 41 | 42 | /** 43 | * {@inheritdoc} 44 | */ 45 | public function apply(Video $video, VideoInterface $format) 46 | { 47 | foreach ($video->getStreams()->videos() as $stream) { 48 | if ($stream->has('width') && $stream->has('height')) { 49 | $stream->set('width', $this->dimension->getWidth()); 50 | $stream->set('height', $this->dimension->getHeight()); 51 | } 52 | } 53 | 54 | return array( 55 | '-filter:v', 56 | 'crop=' . 57 | $this->dimension->getWidth() .':' . $this->dimension->getHeight() . ':' . $this->point->getX() . ':' . $this->point->getY() 58 | ); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Video/CustomFilter.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | namespace FFMpeg\Filters\Video; 12 | 13 | use FFMpeg\Format\VideoInterface; 14 | use FFMpeg\Media\Video; 15 | 16 | class CustomFilter implements VideoFilterInterface 17 | { 18 | /** @var string */ 19 | private $filter; 20 | /** @var integer */ 21 | private $priority; 22 | 23 | /** 24 | * A custom filter, useful if you want to build complex filters 25 | * 26 | * @param string $filter 27 | * @param int $priority 28 | */ 29 | public function __construct($filter, $priority = 0) 30 | { 31 | $this->filter = $filter; 32 | $this->priority = $priority; 33 | } 34 | 35 | /** 36 | * {@inheritdoc} 37 | */ 38 | public function getPriority() 39 | { 40 | return $this->priority; 41 | } 42 | 43 | /** 44 | * {@inheritdoc} 45 | */ 46 | public function apply(Video $video, VideoInterface $format) 47 | { 48 | $commands = array('-vf', $this->filter); 49 | 50 | return $commands; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Video/FrameRateFilter.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Video; 13 | 14 | use FFMpeg\Coordinate\FrameRate; 15 | use FFMpeg\Media\Video; 16 | use FFMpeg\Format\VideoInterface; 17 | 18 | class FrameRateFilter implements VideoFilterInterface 19 | { 20 | private $rate; 21 | private $gop; 22 | private $priority; 23 | 24 | public function __construct(FrameRate $rate, $gop, $priority = 0) 25 | { 26 | $this->rate = $rate; 27 | $this->gop = $gop; 28 | $this->priority = $priority; 29 | } 30 | 31 | /** 32 | * {@inheritdoc} 33 | */ 34 | public function getPriority() 35 | { 36 | return $this->priority; 37 | } 38 | 39 | /** 40 | * Returns the frame rate. 41 | * 42 | * @return FrameRate 43 | */ 44 | public function getFrameRate() 45 | { 46 | return $this->rate; 47 | } 48 | 49 | /** 50 | * Returns the GOP size. 51 | * 52 | * @see https://wikipedia.org/wiki/Group_of_pictures 53 | * 54 | * @return Integer 55 | */ 56 | public function getGOP() 57 | { 58 | return $this->gop; 59 | } 60 | 61 | /** 62 | * {@inheritdoc} 63 | */ 64 | public function apply(Video $video, VideoInterface $format) 65 | { 66 | $commands = array('-r', $this->rate->getValue()); 67 | 68 | /** 69 | * @see http://sites.google.com/site/linuxencoding/x264-ffmpeg-mapping 70 | */ 71 | if ($format->supportBFrames()) { 72 | $commands[] = '-b_strategy'; 73 | $commands[] = '1'; 74 | $commands[] = '-bf'; 75 | $commands[] = '3'; 76 | $commands[] = '-g'; 77 | $commands[] = $this->gop; 78 | } 79 | 80 | return $commands; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Video/PadFilter.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Video; 13 | 14 | use FFMpeg\Coordinate\Dimension; 15 | use FFMpeg\Media\Video; 16 | use FFMpeg\Format\VideoInterface; 17 | 18 | class PadFilter implements VideoFilterInterface 19 | { 20 | /** @var Dimension */ 21 | private $dimension; 22 | /** @var integer */ 23 | private $priority; 24 | 25 | public function __construct(Dimension $dimension, $priority = 0) 26 | { 27 | $this->dimension = $dimension; 28 | $this->priority = $priority; 29 | } 30 | 31 | /** 32 | * {@inheritdoc} 33 | */ 34 | public function getPriority() 35 | { 36 | return $this->priority; 37 | } 38 | 39 | /** 40 | * @return Dimension 41 | */ 42 | public function getDimension() 43 | { 44 | return $this->dimension; 45 | } 46 | 47 | /** 48 | * {@inheritdoc} 49 | */ 50 | public function apply(Video $video, VideoInterface $format) 51 | { 52 | $commands = array(); 53 | 54 | $commands[] = '-vf'; 55 | $commands[] = 'scale=iw*min(' . $this->dimension->getWidth() . '/iw\,' . $this->dimension->getHeight() .'/ih):ih*min(' . $this->dimension->getWidth() . '/iw\,' . $this->dimension->getHeight() .'/ih),pad=' . $this->dimension->getWidth() . ':' . $this->dimension->getHeight() . ':(' . $this->dimension->getWidth() . '-iw)/2:(' . $this->dimension->getHeight() .'-ih)/2'; 56 | 57 | return $commands; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Video/RotateFilter.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Video; 13 | 14 | use FFMpeg\Coordinate\Dimension; 15 | use FFMpeg\Exception\InvalidArgumentException; 16 | use FFMpeg\Media\Video; 17 | use FFMpeg\Format\VideoInterface; 18 | 19 | class RotateFilter implements VideoFilterInterface 20 | { 21 | const ROTATE_90 = 'transpose=1'; 22 | const ROTATE_180 = 'hflip,vflip'; 23 | const ROTATE_270 = 'transpose=2'; 24 | 25 | /** @var string */ 26 | private $angle; 27 | /** @var integer */ 28 | private $priority; 29 | 30 | public function __construct($angle, $priority = 0) 31 | { 32 | $this->setAngle($angle); 33 | $this->priority = (int) $priority; 34 | } 35 | 36 | /** 37 | * {@inheritdoc} 38 | */ 39 | public function getPriority() 40 | { 41 | return $this->priority; 42 | } 43 | 44 | /** 45 | * @return Dimension 46 | */ 47 | public function getAngle() 48 | { 49 | return $this->angle; 50 | } 51 | 52 | /** 53 | * {@inheritdoc} 54 | */ 55 | public function apply(Video $video, VideoInterface $format) 56 | { 57 | if (in_array($this->angle, array(self::ROTATE_90, self::ROTATE_270), true)) { 58 | foreach ($video->getStreams()->videos() as $stream) { 59 | if ($stream->has('width') && $stream->has('height')) { 60 | $width = $stream->get('width'); 61 | $stream->set('width', $stream->get('height')); 62 | $stream->set('height', $width); 63 | } 64 | } 65 | } 66 | 67 | return array('-vf', $this->angle, '-metadata:s:v:0', 'rotate=0'); 68 | } 69 | 70 | private function setAngle($angle) 71 | { 72 | switch ($angle) { 73 | case self::ROTATE_90: 74 | case self::ROTATE_180: 75 | case self::ROTATE_270: 76 | $this->angle = $angle; 77 | break; 78 | default: 79 | throw new InvalidArgumentException('Invalid angle value.'); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Video/SynchronizeFilter.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Video; 13 | 14 | use FFMpeg\Format\VideoInterface; 15 | use FFMpeg\Media\Video; 16 | 17 | /** 18 | * Synchronizes audio and video in case of desynchronized movies. 19 | */ 20 | class SynchronizeFilter implements VideoFilterInterface 21 | { 22 | private $priority; 23 | 24 | public function __construct($priority = 12) 25 | { 26 | $this->priority = $priority; 27 | } 28 | 29 | /** 30 | * {@inheritdoc} 31 | */ 32 | public function getPriority() 33 | { 34 | return $this->priority; 35 | } 36 | 37 | /** 38 | * {@inheritdoc} 39 | */ 40 | public function apply(Video $video, VideoInterface $format) 41 | { 42 | return array('-async', '1', '-metadata:s:v:0', 'start_time=0'); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Video/VideoFilterInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Video; 13 | 14 | use FFMpeg\Filters\FilterInterface; 15 | use FFMpeg\Format\VideoInterface; 16 | use FFMpeg\Media\Video; 17 | 18 | interface VideoFilterInterface extends FilterInterface 19 | { 20 | /** 21 | * Applies the filter on the the Video media given an format. 22 | * 23 | * @param Video $video 24 | * @param VideoInterface $format 25 | * 26 | * @return array An array of arguments 27 | */ 28 | public function apply(Video $video, VideoInterface $format); 29 | } 30 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Video/WatermarkFilter.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Video; 13 | 14 | use FFMpeg\Exception\InvalidArgumentException; 15 | use FFMpeg\Format\VideoInterface; 16 | use FFMpeg\Media\Video; 17 | 18 | class WatermarkFilter implements VideoFilterInterface 19 | { 20 | /** @var string */ 21 | private $watermarkPath; 22 | /** @var array */ 23 | private $coordinates; 24 | /** @var integer */ 25 | private $priority; 26 | 27 | public function __construct($watermarkPath, array $coordinates = array(), $priority = 0) 28 | { 29 | if (!file_exists($watermarkPath)) { 30 | throw new InvalidArgumentException(sprintf('File %s does not exist', $watermarkPath)); 31 | } 32 | 33 | $this->watermarkPath = $watermarkPath; 34 | $this->coordinates = $coordinates; 35 | $this->priority = $priority; 36 | } 37 | 38 | /** 39 | * {@inheritdoc} 40 | */ 41 | public function getPriority() 42 | { 43 | return $this->priority; 44 | } 45 | 46 | /** 47 | * {@inheritdoc} 48 | */ 49 | public function apply(Video $video, VideoInterface $format) 50 | { 51 | $position = isset($this->coordinates['position']) ? $this->coordinates['position'] : 'absolute'; 52 | 53 | switch ($position) { 54 | case 'relative': 55 | if (isset($this->coordinates['top'])) { 56 | $y = $this->coordinates['top']; 57 | } elseif (isset($this->coordinates['bottom'])) { 58 | $y = sprintf('main_h - %d - overlay_h', $this->coordinates['bottom']); 59 | } else { 60 | $y = 0; 61 | } 62 | 63 | if (isset($this->coordinates['left'])) { 64 | $x = $this->coordinates['left']; 65 | } elseif (isset($this->coordinates['right'])) { 66 | $x = sprintf('main_w - %d - overlay_w', $this->coordinates['right']); 67 | } else { 68 | $x = 0; 69 | } 70 | 71 | break; 72 | default: 73 | $x = isset($this->coordinates['x']) ? $this->coordinates['x'] : 0; 74 | $y = isset($this->coordinates['y']) ? $this->coordinates['y'] : 0; 75 | break; 76 | } 77 | 78 | return array('-vf', sprintf('movie=%s [watermark]; [in][watermark] overlay=%s:%s [out]', $this->watermarkPath, $x, $y)); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Waveform/WaveformDownmixFilter.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Waveform; 13 | 14 | use FFMpeg\Exception\RuntimeException; 15 | use FFMpeg\Media\Waveform; 16 | 17 | class WaveformDownmixFilter implements WaveformFilterInterface 18 | { 19 | 20 | /** @var boolean */ 21 | private $downmix; 22 | /** @var integer */ 23 | private $priority; 24 | 25 | // By default, the downmix value is set to FALSE. 26 | public function __construct($downmix = FALSE, $priority = 0) 27 | { 28 | $this->downmix = $downmix; 29 | $this->priority = $priority; 30 | } 31 | 32 | /** 33 | * {@inheritdoc} 34 | */ 35 | public function getDownmix() 36 | { 37 | return $this->downmix; 38 | } 39 | 40 | /** 41 | * {@inheritdoc} 42 | */ 43 | public function getPriority() 44 | { 45 | return $this->priority; 46 | } 47 | 48 | /** 49 | * {@inheritdoc} 50 | */ 51 | public function apply(Waveform $waveform) 52 | { 53 | $commands = array(); 54 | 55 | foreach ($waveform->getAudio()->getStreams() as $stream) { 56 | if ($stream->isAudio()) { 57 | try { 58 | 59 | // If the downmix parameter is set to TRUE, we add an option to the FFMPEG command 60 | if($this->downmix == TRUE) { 61 | $commands[] = '"aformat=channel_layouts=mono"'; 62 | } 63 | 64 | break; 65 | 66 | } catch (RuntimeException $e) { 67 | 68 | } 69 | } 70 | } 71 | 72 | return $commands; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Waveform/WaveformFilterInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Waveform; 13 | 14 | use FFMpeg\Filters\FilterInterface; 15 | use FFMpeg\Media\Waveform; 16 | 17 | interface WaveformFilterInterface extends FilterInterface 18 | { 19 | public function apply(Waveform $waveform); 20 | } 21 | -------------------------------------------------------------------------------- /src/FFMpeg/Filters/Waveform/WaveformFilters.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Filters\Waveform; 13 | 14 | use FFMpeg\Media\Waveform; 15 | 16 | class WaveformFilters 17 | { 18 | private $waveform; 19 | 20 | public function __construct(Waveform $waveform) 21 | { 22 | $this->waveform = $waveform; 23 | } 24 | 25 | /** 26 | * Sets the downmix of the output waveform. 27 | * 28 | * If you want a simpler waveform, sets the downmix to TRUE. 29 | * 30 | * @return WaveformFilters 31 | */ 32 | public function setDownmix() 33 | { 34 | $this->waveform->addFilter(new WaveformDownmixFilter()); 35 | 36 | return $this; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/FFMpeg/Format/Audio/Aac.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Format\Audio; 13 | 14 | /** 15 | * The AAC audio format 16 | */ 17 | class Aac extends DefaultAudio 18 | { 19 | public function __construct() 20 | { 21 | $this->audioCodec = 'libfdk_aac'; 22 | } 23 | 24 | /** 25 | * {@inheritDoc} 26 | */ 27 | public function getAvailableAudioCodecs() 28 | { 29 | return array('libfdk_aac'); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/FFMpeg/Format/Audio/Flac.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Format\Audio; 13 | 14 | /** 15 | * The Flac audio format 16 | */ 17 | class Flac extends DefaultAudio 18 | { 19 | public function __construct() 20 | { 21 | $this->audioCodec = 'flac'; 22 | } 23 | 24 | /** 25 | * {@inheritDoc} 26 | */ 27 | public function getAvailableAudioCodecs() 28 | { 29 | return array('flac'); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/FFMpeg/Format/Audio/Mp3.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Format\Audio; 13 | 14 | /** 15 | * The MP3 audio format 16 | */ 17 | class Mp3 extends DefaultAudio 18 | { 19 | public function __construct() 20 | { 21 | $this->audioCodec = 'libmp3lame'; 22 | } 23 | 24 | /** 25 | * {@inheritDoc} 26 | */ 27 | public function getAvailableAudioCodecs() 28 | { 29 | return array('libmp3lame'); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/FFMpeg/Format/Audio/Vorbis.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Format\Audio; 13 | 14 | /** 15 | * The Vorbis audio format 16 | */ 17 | class Vorbis extends DefaultAudio 18 | { 19 | public function __construct() 20 | { 21 | $this->audioCodec = 'vorbis'; 22 | } 23 | 24 | /** 25 | * {@inheritdoc} 26 | */ 27 | public function getExtraParams() 28 | { 29 | return array('-strict', '-2'); 30 | } 31 | 32 | /** 33 | * {@inheritDoc} 34 | */ 35 | public function getAvailableAudioCodecs() 36 | { 37 | return array('vorbis'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/FFMpeg/Format/Audio/Wav.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Format\Audio; 13 | 14 | /** 15 | * The WAV audio format 16 | */ 17 | class Wav extends DefaultAudio 18 | { 19 | public function __construct() 20 | { 21 | $this->audioCodec = 'pcm_s16le'; 22 | } 23 | 24 | /** 25 | * {@inheritDoc} 26 | */ 27 | public function getAvailableAudioCodecs() 28 | { 29 | return array('pcm_s16le'); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/FFMpeg/Format/AudioInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | namespace FFMpeg\Format; 12 | 13 | interface AudioInterface extends FormatInterface 14 | { 15 | /** 16 | * Gets the audio kiloBitrate value. 17 | * 18 | * @return integer 19 | */ 20 | public function getAudioKiloBitrate(); 21 | 22 | /** 23 | * Gets the audio channels value. 24 | * 25 | * @return integer 26 | */ 27 | public function getAudioChannels(); 28 | 29 | /** 30 | * Returns the audio codec. 31 | * 32 | * @return string 33 | */ 34 | public function getAudioCodec(); 35 | 36 | /** 37 | * Returns the list of available audio codecs for this format. 38 | * 39 | * @return array 40 | */ 41 | public function getAvailableAudioCodecs(); 42 | } 43 | -------------------------------------------------------------------------------- /src/FFMpeg/Format/FormatInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | namespace FFMpeg\Format; 12 | 13 | interface FormatInterface 14 | { 15 | /** 16 | * Returns the number of passes. 17 | * 18 | * @return string 19 | */ 20 | public function getPasses(); 21 | 22 | /** 23 | * Returns an array of extra parameters to add to ffmpeg commandline. 24 | * 25 | * @return array() 26 | */ 27 | public function getExtraParams(); 28 | } 29 | -------------------------------------------------------------------------------- /src/FFMpeg/Format/FrameInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Format; 13 | 14 | interface FrameInterface extends FormatInterface 15 | { 16 | } 17 | -------------------------------------------------------------------------------- /src/FFMpeg/Format/ProgressListener/AudioProgressListener.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Format\ProgressListener; 13 | 14 | /** 15 | * Parses ffmpeg stderr progress information. An example: 16 | * 17 | *
18 |  *       size=    3552kB time=00:03:47.29 bitrate= 128.0kbits/s
19 |  * 
20 | * 21 | * @author Robert Gruendler 22 | */ 23 | class AudioProgressListener extends AbstractProgressListener 24 | { 25 | public function getPattern() 26 | { 27 | return '/size=(.*?) time=(.*?) /'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/FFMpeg/Format/ProgressListener/VideoProgressListener.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Format\ProgressListener; 13 | 14 | /** 15 | * Parses ffmpeg stderr progress information for video files. An example: 16 | * 17 | *
18 |  *       frame=  171 fps=0.0 q=10.0 size=      18kB time=00:00:05.72 bitrate=  26.4kbits/s dup=8 drop=0
19 |  * 
20 | * 21 | * @author Robert Gruendler 22 | */ 23 | class VideoProgressListener extends AbstractProgressListener 24 | { 25 | public function getPattern() 26 | { 27 | return '/size=(.*?) time=(.*?) /'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/FFMpeg/Format/ProgressableInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Format; 13 | 14 | use Evenement\EventEmitterInterface; 15 | use FFMpeg\FFProbe; 16 | use FFMpeg\Media\MediaTypeInterface; 17 | 18 | interface ProgressableInterface extends EventEmitterInterface 19 | { 20 | /** 21 | * Creates the progress listener. 22 | * 23 | * @param MediaTypeInterface $media 24 | * @param FFProbe $ffprobe 25 | * @param Integer $pass The current pas snumber 26 | * @param Integer $total The total pass number 27 | * @param Integer $duration The new video duration 28 | * 29 | * @return array An array of listeners 30 | */ 31 | public function createProgressListener(MediaTypeInterface $media, FFProbe $ffprobe, $pass, $total, $duration = 0); 32 | } 33 | -------------------------------------------------------------------------------- /src/FFMpeg/Format/Video/Ogg.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Format\Video; 13 | 14 | /** 15 | * The Ogg video format 16 | */ 17 | class Ogg extends DefaultVideo 18 | { 19 | public function __construct($audioCodec = 'libvorbis', $videoCodec = 'libtheora') 20 | { 21 | $this 22 | ->setAudioCodec($audioCodec) 23 | ->setVideoCodec($videoCodec); 24 | } 25 | 26 | /** 27 | * {@inheritDoc} 28 | */ 29 | public function supportBFrames() 30 | { 31 | return true; 32 | } 33 | 34 | /** 35 | * {@inheritDoc} 36 | */ 37 | public function getAvailableAudioCodecs() 38 | { 39 | return array('libvorbis'); 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | public function getAvailableVideoCodecs() 46 | { 47 | return array('libtheora'); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/FFMpeg/Format/Video/WMV.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Format\Video; 13 | 14 | /** 15 | * The WMV video format 16 | */ 17 | class WMV extends DefaultVideo 18 | { 19 | public function __construct($audioCodec = 'wmav2', $videoCodec = 'wmv2') 20 | { 21 | $this 22 | ->setAudioCodec($audioCodec) 23 | ->setVideoCodec($videoCodec); 24 | } 25 | 26 | /** 27 | * {@inheritDoc} 28 | */ 29 | public function supportBFrames() 30 | { 31 | return false; 32 | } 33 | 34 | /** 35 | * {@inheritDoc} 36 | */ 37 | public function getAvailableAudioCodecs() 38 | { 39 | return array('wmav2'); 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | public function getAvailableVideoCodecs() 46 | { 47 | return array('wmv2'); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/FFMpeg/Format/Video/WMV3.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Format\Video; 13 | 14 | /** 15 | * The WMV video format 16 | */ 17 | class WMV3 extends DefaultVideo 18 | { 19 | public function __construct($audioCodec = 'wmav3', $videoCodec = 'wmv3') 20 | { 21 | $this 22 | ->setAudioCodec($audioCodec) 23 | ->setVideoCodec($videoCodec); 24 | } 25 | 26 | /** 27 | * {@inheritDoc} 28 | */ 29 | public function supportBFrames() 30 | { 31 | return false; 32 | } 33 | 34 | /** 35 | * {@inheritDoc} 36 | */ 37 | public function getAvailableAudioCodecs() 38 | { 39 | return array('wmav3'); 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | public function getAvailableVideoCodecs() 46 | { 47 | return array('wmv3'); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/FFMpeg/Format/Video/WebM.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Format\Video; 13 | 14 | /** 15 | * The WebM video format 16 | */ 17 | class WebM extends DefaultVideo 18 | { 19 | public function __construct($audioCodec = 'libvorbis', $videoCodec = 'libvpx') 20 | { 21 | $this 22 | ->setAudioCodec($audioCodec) 23 | ->setVideoCodec($videoCodec); 24 | } 25 | 26 | /** 27 | * {@inheritDoc} 28 | */ 29 | public function supportBFrames() 30 | { 31 | return true; 32 | } 33 | 34 | /** 35 | * {@inheritDoc} 36 | */ 37 | public function getExtraParams() 38 | { 39 | return array('-f', 'webm'); 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | public function getAvailableAudioCodecs() 46 | { 47 | return array('libvorbis'); 48 | } 49 | 50 | /** 51 | * {@inheritDoc} 52 | */ 53 | public function getAvailableVideoCodecs() 54 | { 55 | return array('libvpx', 'libvpx-vp9'); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/FFMpeg/Format/Video/X264.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Format\Video; 13 | 14 | /** 15 | * The X264 video format 16 | */ 17 | class X264 extends DefaultVideo 18 | { 19 | /** @var boolean */ 20 | private $bframesSupport = true; 21 | 22 | /** @var integer */ 23 | private $passes = 2; 24 | 25 | public function __construct($audioCodec = 'libfaac', $videoCodec = 'libx264') 26 | { 27 | $this 28 | ->setAudioCodec($audioCodec) 29 | ->setVideoCodec($videoCodec); 30 | } 31 | 32 | /** 33 | * {@inheritDoc} 34 | */ 35 | public function supportBFrames() 36 | { 37 | return $this->bframesSupport; 38 | } 39 | 40 | /** 41 | * @param $support 42 | * 43 | * @return X264 44 | */ 45 | public function setBFramesSupport($support) 46 | { 47 | $this->bframesSupport = $support; 48 | 49 | return $this; 50 | } 51 | 52 | /** 53 | * {@inheritDoc} 54 | */ 55 | public function getAvailableAudioCodecs() 56 | { 57 | return array('aac', 'libvo_aacenc', 'libfaac', 'libmp3lame', 'libfdk_aac'); 58 | } 59 | 60 | /** 61 | * {@inheritDoc} 62 | */ 63 | public function getAvailableVideoCodecs() 64 | { 65 | return array('libx264'); 66 | } 67 | 68 | /** 69 | * @param $passes 70 | * 71 | * @return X264 72 | */ 73 | public function setPasses($passes) 74 | { 75 | $this->passes = $passes; 76 | return $this; 77 | } 78 | 79 | /** 80 | * {@inheritDoc} 81 | */ 82 | public function getPasses() 83 | { 84 | return $this->passes; 85 | } 86 | 87 | /** 88 | * @return int 89 | */ 90 | public function getModulus() 91 | { 92 | return 2; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/FFMpeg/Format/VideoInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Format; 13 | 14 | interface VideoInterface extends AudioInterface 15 | { 16 | /** 17 | * Gets the kiloBitrate value. 18 | * 19 | * @return integer 20 | */ 21 | public function getKiloBitrate(); 22 | 23 | /** 24 | * Returns the modulus used by the Resizable video. 25 | * 26 | * This used to calculate the target dimensions while maintaining the best 27 | * aspect ratio. 28 | * 29 | * @see http://www.undeadborn.net/tools/rescalculator.php 30 | * 31 | * @return integer 32 | */ 33 | public function getModulus(); 34 | 35 | /** 36 | * Returns the video codec. 37 | * 38 | * @return string 39 | */ 40 | public function getVideoCodec(); 41 | 42 | /** 43 | * Returns true if the current format supports B-Frames. 44 | * 45 | * @see https://wikipedia.org/wiki/Video_compression_picture_types 46 | * 47 | * @return Boolean 48 | */ 49 | public function supportBFrames(); 50 | 51 | /** 52 | * Returns the list of available video codecs for this format. 53 | * 54 | * @return array 55 | */ 56 | public function getAvailableVideoCodecs(); 57 | 58 | /** 59 | * Returns the list of available video codecs for this format. 60 | * 61 | * @return array 62 | */ 63 | public function getAdditionalParameters(); 64 | } 65 | -------------------------------------------------------------------------------- /src/FFMpeg/Media/AbstractMediaType.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Media; 13 | 14 | use FFMpeg\Driver\FFMpegDriver; 15 | use FFMpeg\FFProbe; 16 | use FFMpeg\Filters\FiltersCollection; 17 | 18 | abstract class AbstractMediaType implements MediaTypeInterface 19 | { 20 | /** @var string */ 21 | protected $pathfile; 22 | /** @var FFMpegDriver */ 23 | protected $driver; 24 | /** @var FFProbe */ 25 | protected $ffprobe; 26 | /** @var FiltersCollection */ 27 | protected $filters; 28 | 29 | public function __construct($pathfile, FFMpegDriver $driver, FFProbe $ffprobe) 30 | { 31 | $this->pathfile = $pathfile; 32 | $this->driver = $driver; 33 | $this->ffprobe = $ffprobe; 34 | $this->filters = new FiltersCollection(); 35 | } 36 | 37 | /** 38 | * @return FFMpegDriver 39 | */ 40 | public function getFFMpegDriver() 41 | { 42 | return $this->driver; 43 | } 44 | 45 | /** 46 | * @param FFMpegDriver $driver 47 | * 48 | * @return MediaTypeInterface 49 | */ 50 | public function setFFMpegDriver(FFMpegDriver $driver) 51 | { 52 | $this->driver = $driver; 53 | 54 | return $this; 55 | } 56 | 57 | /** 58 | * @return FFProbe 59 | */ 60 | public function getFFProbe() 61 | { 62 | return $this->ffprobe; 63 | } 64 | 65 | /** 66 | * @param FFProbe $ffprobe 67 | * 68 | * @return MediaTypeInterface 69 | */ 70 | public function setFFProbe(FFProbe $ffprobe) 71 | { 72 | $this->ffprobe = $ffprobe; 73 | 74 | return $this; 75 | } 76 | 77 | /** 78 | * @return string 79 | */ 80 | public function getPathfile() 81 | { 82 | return $this->pathfile; 83 | } 84 | 85 | /** 86 | * @param FiltersCollection $filters 87 | * 88 | * @return MediaTypeInterface 89 | */ 90 | public function setFiltersCollection(FiltersCollection $filters) 91 | { 92 | $this->filters = $filters; 93 | 94 | return $this; 95 | } 96 | 97 | /** 98 | * @return MediaTypeInterface 99 | */ 100 | public function getFiltersCollection() 101 | { 102 | return $this->filters; 103 | } 104 | 105 | protected function cleanupTemporaryFile($filename) 106 | { 107 | if (file_exists($filename) && is_writable($filename)) { 108 | unlink($filename); 109 | } 110 | 111 | return $this; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/FFMpeg/Media/AbstractStreamableMedia.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Media; 13 | 14 | use FFMpeg\FFProbe\DataMapping\Format; 15 | use FFMpeg\FFProbe\DataMapping\StreamCollection; 16 | 17 | abstract class AbstractStreamableMedia extends AbstractMediaType 18 | { 19 | private $streams; 20 | 21 | /** 22 | * @return StreamCollection 23 | */ 24 | public function getStreams() 25 | { 26 | if (null === $this->streams) { 27 | $this->streams = $this->ffprobe->streams($this->pathfile); 28 | } 29 | 30 | return $this->streams; 31 | } 32 | 33 | /** 34 | * @return Format 35 | */ 36 | public function getFormat() 37 | { 38 | return $this->ffprobe->format($this->pathfile); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/FFMpeg/Media/MediaTypeInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace FFMpeg\Media; 13 | 14 | interface MediaTypeInterface 15 | { 16 | /** 17 | * Returns the available filters. 18 | */ 19 | public function filters(); 20 | 21 | /** 22 | * @return string 23 | */ 24 | public function getPathfile(); 25 | } 26 | -------------------------------------------------------------------------------- /tests/Functional/FFProbeTest.php: -------------------------------------------------------------------------------- 1 | assertGreaterThan(0, count($ffprobe->streams(__DIR__ . '/../files/Audio.mp3'))); 13 | } 14 | 15 | public function testValidateExistingFile() 16 | { 17 | $ffprobe = FFProbe::create(); 18 | $this->assertTrue($ffprobe->isValid(__DIR__ . '/../files/sample.3gp')); 19 | } 20 | 21 | 22 | public function testValidateNonExistingFile() 23 | { 24 | $ffprobe = FFProbe::create(); 25 | $this->assertFalse($ffprobe->isValid(__DIR__ . '/../files/WrongFile.mp4')); 26 | } 27 | 28 | /** 29 | * @expectedException FFMpeg\Exception\RuntimeException 30 | */ 31 | public function testProbeOnNonExistantFile() 32 | { 33 | $ffprobe = FFProbe::create(); 34 | $ffprobe->streams('/path/to/no/file'); 35 | } 36 | 37 | public function testProbeOnRemoteFile() 38 | { 39 | $ffprobe = FFProbe::create(); 40 | $this->assertGreaterThan(0, count($ffprobe->streams('http://vjs.zencdn.net/v/oceans.mp4'))); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/Functional/FunctionalTestCase.php: -------------------------------------------------------------------------------- 1 | 300)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/Functional/output/.placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alchemy-fr/PHP-FFMpeg/a1d5fa51ba94929c93e9a03dce16990d6ca177bc/tests/Functional/output/.placeholder -------------------------------------------------------------------------------- /tests/Unit/Coordinate/DimensionTest.php: -------------------------------------------------------------------------------- 1 | assertEquals(320, $dimension->getWidth()); 36 | $this->assertEquals(240, $dimension->getHeight()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/Unit/Coordinate/FrameRateTest.php: -------------------------------------------------------------------------------- 1 | assertEquals(23.997, $fr->getValue()); 14 | } 15 | 16 | /** 17 | * @dataProvider provideInvalidFrameRates 18 | * @expectedException FFMpeg\Exception\InvalidArgumentException 19 | */ 20 | public function testInvalidFrameRate($value) 21 | { 22 | new FrameRate($value); 23 | } 24 | 25 | public function provideInvalidFrameRates() 26 | { 27 | return array( 28 | array(0), array(-1.5), array(-2), 29 | ); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/Unit/Coordinate/PointTest.php: -------------------------------------------------------------------------------- 1 | assertEquals(4, $point->getX()); 14 | $this->assertEquals(25, $point->getY()); 15 | } 16 | 17 | public function testDynamicPointGetters() 18 | { 19 | $point = new Point("t*100", "t", true); 20 | $this->assertEquals("t*100", $point->getX()); 21 | $this->assertEquals("t", $point->getY()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/Unit/Coordinate/TimeCodeTest.php: -------------------------------------------------------------------------------- 1 | assertEquals((string) $tc, $expected); 17 | } 18 | 19 | public function provideTimeCodes() 20 | { 21 | return array( 22 | array('1:02:04:05:20', '26:04:05.20'), 23 | array('1:02:04:05.20', '26:04:05.20'), 24 | array('02:04:05:20', '02:04:05.20'), 25 | array('02:04:05.20', '02:04:05.20'), 26 | array('00:00:05.20', '00:00:05.20'), 27 | array('00:00:00.00', '00:00:00.00'), 28 | ); 29 | } 30 | 31 | /** 32 | * @expectedException FFMpeg\Exception\InvalidArgumentException 33 | */ 34 | public function testFromInvalidString() 35 | { 36 | TimeCode::fromString('lalali lala'); 37 | } 38 | 39 | /** 40 | * @dataProvider provideSeconds 41 | */ 42 | public function testFromSeconds($seconds, $expected) 43 | { 44 | $tc = TimeCode::fromSeconds($seconds); 45 | $this->assertEquals($expected, (string) $tc); 46 | } 47 | 48 | public function provideSeconds() 49 | { 50 | return array( 51 | array(0.467, '00:00:00.47'), 52 | array(12.467, '00:00:12.47'), 53 | array(59.867, '00:00:59.87'), 54 | array(72.467, '00:01:12.47'), 55 | array(3599.467, '00:59:59.47'), 56 | array(3600.467, '01:00:00.47'), 57 | array(86422.467, '24:00:22.47'), 58 | ); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /tests/Unit/Driver/FFMpegDriverTest.php: -------------------------------------------------------------------------------- 1 | find($name)) { 19 | $found = true; 20 | break; 21 | } 22 | } 23 | 24 | if (!$found) { 25 | $this->markTestSkipped('Neither ffmpeg or avconv found'); 26 | } 27 | } 28 | 29 | public function testCreate() 30 | { 31 | $logger = $this->getLoggerMock(); 32 | $ffmpeg = FFMpegDriver::create($logger, array()); 33 | $this->assertInstanceOf('FFMpeg\Driver\FFMpegDriver', $ffmpeg); 34 | $this->assertEquals($logger, $ffmpeg->getProcessRunner()->getLogger()); 35 | } 36 | 37 | public function testCreateWithConfig() 38 | { 39 | $conf = new Configuration(); 40 | $ffmpeg = FFMpegDriver::create($this->getLoggerMock(), $conf); 41 | $this->assertEquals($conf, $ffmpeg->getConfiguration()); 42 | } 43 | 44 | /** 45 | * @expectedException FFMpeg\Exception\ExecutableNotFoundException 46 | */ 47 | public function testCreateFailureThrowsAnException() 48 | { 49 | FFMpegDriver::create($this->getLoggerMock(), array('ffmpeg.binaries' => '/path/to/nowhere')); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/Unit/Driver/FFProbeDriverTest.php: -------------------------------------------------------------------------------- 1 | find($name)) { 19 | $found = true; 20 | break; 21 | } 22 | } 23 | 24 | if (!$found) { 25 | $this->markTestSkipped('Neither ffprobe or avprobe found'); 26 | } 27 | } 28 | 29 | public function testCreate() 30 | { 31 | $logger = $this->getLoggerMock(); 32 | $ffprobe = FFProbeDriver::create(array(), $logger); 33 | $this->assertInstanceOf('FFMpeg\Driver\FFProbeDriver', $ffprobe); 34 | $this->assertEquals($logger, $ffprobe->getProcessRunner()->getLogger()); 35 | } 36 | 37 | public function testCreateWithConfig() 38 | { 39 | $conf = new Configuration(); 40 | $ffprobe = FFProbeDriver::create($conf, $this->getLoggerMock()); 41 | $this->assertEquals($conf, $ffprobe->getConfiguration()); 42 | } 43 | 44 | /** 45 | * @expectedException FFMpeg\Exception\ExecutableNotFoundException 46 | */ 47 | public function testCreateFailureThrowsAnException() 48 | { 49 | FFProbeDriver::create(array('ffprobe.binaries' => '/path/to/nowhere')); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/Unit/FFMpegServiceProviderTest.php: -------------------------------------------------------------------------------- 1 | register(new FFMpegServiceProvider(), array( 15 | 'ffmpeg.configuration' => array( 16 | 'ffmpeg.threads' => 12, 17 | 'ffmpeg.timeout' => 10666, 18 | 'ffprobe.timeout' => 4242, 19 | ) 20 | )); 21 | 22 | $this->assertInstanceOf('FFMpeg\FFMpeg', $app['ffmpeg']); 23 | $this->assertSame($app['ffmpeg'], $app['ffmpeg.ffmpeg']); 24 | $this->assertInstanceOf('FFMpeg\FFProbe', $app['ffmpeg.ffprobe']); 25 | 26 | $this->assertEquals(12, $app['ffmpeg']->getFFMpegDriver()->getConfiguration()->get('ffmpeg.threads')); 27 | $this->assertEquals(10666, $app['ffmpeg']->getFFMpegDriver()->getProcessBuilderFactory()->getTimeout()); 28 | $this->assertEquals(4242, $app['ffmpeg.ffprobe']->getFFProbeDriver()->getProcessBuilderFactory()->getTimeout()); 29 | } 30 | 31 | public function testWithoutConfig() 32 | { 33 | $app = new Application(); 34 | $app->register(new FFMpegServiceProvider()); 35 | 36 | $this->assertInstanceOf('FFMpeg\FFMpeg', $app['ffmpeg']); 37 | $this->assertSame($app['ffmpeg'], $app['ffmpeg.ffmpeg']); 38 | $this->assertInstanceOf('FFMpeg\FFProbe', $app['ffmpeg.ffprobe']); 39 | 40 | $this->assertEquals(4, $app['ffmpeg']->getFFMpegDriver()->getConfiguration()->get('ffmpeg.threads')); 41 | $this->assertEquals(300, $app['ffmpeg']->getFFMpegDriver()->getProcessBuilderFactory()->getTimeout()); 42 | $this->assertEquals(30, $app['ffmpeg.ffprobe']->getFFProbeDriver()->getProcessBuilderFactory()->getTimeout()); 43 | } 44 | 45 | public function testWithFFMpegBinaryConfig() 46 | { 47 | $app = new Application(); 48 | $app->register(new FFMpegServiceProvider(), array( 49 | 'ffmpeg.configuration' => array( 50 | 'ffmpeg.binaries' => '/path/to/ffmpeg', 51 | ) 52 | )); 53 | 54 | $this->setExpectedException('FFMpeg\Exception\ExecutableNotFoundException', 'Unable to load FFMpeg'); 55 | $app['ffmpeg']; 56 | } 57 | 58 | public function testWithFFMprobeBinaryConfig() 59 | { 60 | $app = new Application(); 61 | $app->register(new FFMpegServiceProvider(), array( 62 | 'ffmpeg.configuration' => array( 63 | 'ffprobe.binaries' => '/path/to/ffprobe', 64 | ) 65 | )); 66 | 67 | $this->setExpectedException('FFMpeg\Exception\ExecutableNotFoundException', 'Unable to load FFProbe'); 68 | $app['ffmpeg.ffprobe']; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /tests/Unit/FFProbe/DataMapping/AbstractDataTest.php: -------------------------------------------------------------------------------- 1 | 'value1', 'key2' => 'value2')); 13 | 14 | $this->assertTrue($imp->has('key1')); 15 | $this->assertTrue($imp->has('key2')); 16 | $this->assertFalse($imp->has('value1')); 17 | $this->assertFalse($imp->has('key3')); 18 | } 19 | 20 | public function testGet() 21 | { 22 | $imp = new Implementation(array('key1' => 'value1', 'key2' => 'value2')); 23 | 24 | $this->assertEquals('value1', $imp->get('key1')); 25 | $this->assertEquals('value2', $imp->get('key2')); 26 | } 27 | 28 | public function testGetDefault() 29 | { 30 | $imp = new Implementation(array('key1' => 'value1', 'key2' => 'value2')); 31 | $this->assertSame('yololo', $imp->get('key3', 'yololo')); 32 | } 33 | 34 | public function testKeys() 35 | { 36 | $imp = new Implementation(array('key1' => 'value1', 'key2' => 'value2')); 37 | 38 | $this->assertEquals(array('key1', 'key2'), $imp->keys()); 39 | } 40 | 41 | public function testAll() 42 | { 43 | $values = array('key1' => 'value1', 'key2' => 'value2'); 44 | $imp = new Implementation($values); 45 | 46 | $this->assertEquals($values, $imp->all()); 47 | } 48 | } 49 | 50 | class Implementation extends AbstractData 51 | { 52 | } 53 | -------------------------------------------------------------------------------- /tests/Unit/FFProbe/DataMapping/StreamCollectionTest.php: -------------------------------------------------------------------------------- 1 | getStreamMock(); 13 | 14 | $collection = new StreamCollection(); 15 | $this->assertEquals(array(), $collection->all()); 16 | $collection->add($stream); 17 | $this->assertEquals(array($stream), $collection->all()); 18 | $collection->add($stream); 19 | $this->assertEquals(array($stream, $stream), $collection->all()); 20 | } 21 | 22 | public function testVideos() 23 | { 24 | $audio = $this->getStreamMock(); 25 | $audio->expects($this->once()) 26 | ->method('isVideo') 27 | ->will($this->returnValue(false)); 28 | 29 | $video = $this->getStreamMock(); 30 | $video->expects($this->once()) 31 | ->method('isVideo') 32 | ->will($this->returnValue(true)); 33 | 34 | $collection = new StreamCollection(array($audio, $video)); 35 | $videos = $collection->videos(); 36 | 37 | $this->assertInstanceOf('FFMpeg\FFProbe\DataMapping\StreamCollection', $videos); 38 | $this->assertCount(1, $videos); 39 | $this->assertEquals(array($video), $videos->all()); 40 | } 41 | 42 | public function testAudios() 43 | { 44 | $audio = $this->getStreamMock(); 45 | $audio->expects($this->once()) 46 | ->method('isAudio') 47 | ->will($this->returnValue(true)); 48 | 49 | $video = $this->getStreamMock(); 50 | $video->expects($this->once()) 51 | ->method('isAudio') 52 | ->will($this->returnValue(false)); 53 | 54 | $collection = new StreamCollection(array($audio, $video)); 55 | $audios = $collection->audios(); 56 | 57 | $this->assertInstanceOf('FFMpeg\FFProbe\DataMapping\StreamCollection', $audios); 58 | $this->assertCount(1, $audios); 59 | $this->assertEquals(array($audio), $audios->all()); 60 | } 61 | 62 | public function testCount() 63 | { 64 | $stream = $this->getStreamMock(); 65 | 66 | $collection = new StreamCollection(array($stream)); 67 | $this->assertCount(1, $collection); 68 | } 69 | 70 | public function testGetIterator() 71 | { 72 | $audio = $this->getStreamMock(); 73 | $video = $this->getStreamMock(); 74 | 75 | $collection = new StreamCollection(array($audio, $video)); 76 | $this->assertInstanceOf('\Iterator', $collection->getIterator()); 77 | $this->assertCount(2, $collection->getIterator()); 78 | } 79 | 80 | public function testFirst() 81 | { 82 | $stream1 = $this->getStreamMock(); 83 | $stream2 = $this->getStreamMock(); 84 | 85 | $coll = new StreamCollection(array($stream1, $stream2)); 86 | 87 | $this->assertSame($stream1, $coll->first()); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /tests/Unit/FFProbe/MapperTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($expected, $mapper->map($type, $data)); 21 | } 22 | 23 | /** 24 | * @expectedException FFMpeg\Exception\InvalidArgumentException 25 | */ 26 | public function testMapInvalidArgument() 27 | { 28 | $mapper = new Mapper(); 29 | $mapper->map('cool type', 'data'); 30 | } 31 | 32 | public function provideMappings() 33 | { 34 | $format = json_decode(file_get_contents(__DIR__ . '/../../fixtures/ffprobe/show_format.json'), true); 35 | $streams = json_decode(file_get_contents(__DIR__ . '/../../fixtures/ffprobe/show_streams.json'), true); 36 | 37 | return array( 38 | array(FFProbe::TYPE_FORMAT, $format, new Format($format['format'])), 39 | array(FFProbe::TYPE_STREAMS, $streams, new StreamCollection(array_map(function ($streamData) { 40 | return new Stream($streamData); 41 | }, $streams['streams']))), 42 | ); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/Unit/FFProbe/OutputParserTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($expectedOutput, $parser->parse($type, $data)); 18 | } 19 | 20 | /** 21 | * @expectedException FFMpeg\Exception\InvalidArgumentException 22 | */ 23 | public function testParseWithInvalidArgument() 24 | { 25 | $parser = new OutputParser(); 26 | $parser->parse('comme ca', 'data'); 27 | } 28 | 29 | public function provideTypeDataAndOutput() 30 | { 31 | $expectedFormat = json_decode(file_get_contents(__DIR__ . '/../../fixtures/ffprobe/show_format.json'), true); 32 | $expectedStreams = json_decode(file_get_contents(__DIR__ . '/../../fixtures/ffprobe/show_streams.json'), true); 33 | 34 | $rawFormat = file_get_contents(__DIR__ . '/../../fixtures/ffprobe/show_format.raw'); 35 | $rawStreams = file_get_contents(__DIR__ . '/../../fixtures/ffprobe/show_streams.raw'); 36 | 37 | return array( 38 | array(FFProbe::TYPE_FORMAT, $rawFormat, $expectedFormat), 39 | array(FFProbe::TYPE_STREAMS, $rawStreams, $expectedStreams), 40 | ); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/Unit/Filters/Audio/AudioClipTest.php: -------------------------------------------------------------------------------- 1 | getAudioMock(); 15 | $audio->expects($this->once()) 16 | ->method('addFilter') 17 | ->with($this->isInstanceOf('FFMpeg\Filters\Audio\AudioClipFilter')) 18 | ->will($this->returnCallback(function ($filter) use (&$capturedFilter) { 19 | $capturedFilter = $filter; 20 | })); 21 | $format = $this->getMock('FFMpeg\Format\AudioInterface'); 22 | 23 | $filters = new AudioFilters($audio); 24 | 25 | $filters->clip(TimeCode::fromSeconds(5)); 26 | $this->assertEquals(array(0 => '-ss', 1 => '00:00:05.00', 2 => '-acodec', 3 => 'copy'), $capturedFilter->apply($audio, $format)); 27 | } 28 | 29 | public function testClippingWithDuration() { 30 | $capturedFilter = null; 31 | 32 | $audio = $this->getAudioMock(); 33 | $audio->expects($this->once()) 34 | ->method('addFilter') 35 | ->with($this->isInstanceOf('FFMpeg\Filters\Audio\AudioClipFilter')) 36 | ->will($this->returnCallback(function ($filter) use (&$capturedFilter) { 37 | $capturedFilter = $filter; 38 | })); 39 | $format = $this->getMock('FFMpeg\Format\AudioInterface'); 40 | 41 | $filters = new AudioFilters($audio); 42 | 43 | $filters->clip(TimeCode::fromSeconds(5), TimeCode::fromSeconds(5)); 44 | $this->assertEquals(array(0 => '-ss', 1 => '00:00:05.00', 2 => '-t', 3 => '00:00:05.00', 4 => '-acodec', 5 => 'copy'), $capturedFilter->apply($audio, $format)); 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /tests/Unit/Filters/Audio/AudioFiltersTest.php: -------------------------------------------------------------------------------- 1 | getAudioMock(); 15 | $audio->expects($this->once()) 16 | ->method('addFilter') 17 | ->with($this->isInstanceOf('FFMpeg\Filters\Audio\AudioResamplableFilter')) 18 | ->will($this->returnCallback(function ($filter) use (&$capturedFilter) { 19 | $capturedFilter = $filter; 20 | })); 21 | 22 | $filters = new AudioFilters($audio); 23 | $filters->resample(8000); 24 | $this->assertEquals(8000, $capturedFilter->getRate()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/Unit/Filters/Audio/AudioMetadataTest.php: -------------------------------------------------------------------------------- 1 | getAudioMock(); 15 | $audio->expects($this->once()) 16 | ->method('addFilter') 17 | ->with($this->isInstanceOf('FFMpeg\Filters\Audio\AddMetadataFilter')) 18 | ->will($this->returnCallback(function ($filter) use (&$capturedFilter) { 19 | $capturedFilter = $filter; 20 | })); 21 | $format = $this->getMock('FFMpeg\Format\AudioInterface'); 22 | 23 | $filters = new AudioFilters($audio); 24 | $filters->addMetadata(array('title' => "Hello World")); 25 | $this->assertEquals(array(0 => "-metadata", 1 => "title=Hello World"), $capturedFilter->apply($audio, $format)); 26 | } 27 | 28 | public function testAddArtwork() 29 | { 30 | $capturedFilter = null; 31 | 32 | $audio = $this->getAudioMock(); 33 | $audio->expects($this->once()) 34 | ->method('addFilter') 35 | ->with($this->isInstanceOf('FFMpeg\Filters\Audio\AddMetadataFilter')) 36 | ->will($this->returnCallback(function ($filter) use (&$capturedFilter) { 37 | $capturedFilter = $filter; 38 | })); 39 | $format = $this->getMock('FFMpeg\Format\AudioInterface'); 40 | 41 | $filters = new AudioFilters($audio); 42 | $filters->addMetadata(array('genre' => 'Some Genre', 'artwork' => "/path/to/file.jpg")); 43 | $this->assertEquals(array(0 => "-i", 1 => "/path/to/file.jpg", 2 => "-map", 3 => "0", 4 => "-map", 5 => "1", 6 => "-metadata", 7 => "genre=Some Genre"), $capturedFilter->apply($audio, $format)); 44 | $this->assertEquals(array(0 => "-i", 1 => "/path/to/file.jpg", 2 => "-map", 3 => "0", 4 => "-map", 5 => "1", 6 => "-metadata", 7 => "genre=Some Genre"), $capturedFilter->apply($audio, $format)); 45 | } 46 | 47 | public function testRemoveMetadata() 48 | { 49 | $capturedFilter = null; 50 | 51 | $audio = $this->getAudioMock(); 52 | $audio->expects($this->once()) 53 | ->method('addFilter') 54 | ->with($this->isInstanceOf('FFMpeg\Filters\Audio\AddMetadataFilter')) 55 | ->will($this->returnCallback(function ($filter) use (&$capturedFilter) { 56 | $capturedFilter = $filter; 57 | })); 58 | $format = $this->getMock('FFMpeg\Format\AudioInterface'); 59 | 60 | $filters = new AudioFilters($audio); 61 | $filters->addMetadata(); 62 | $this->assertEquals(array(0 => "-map_metadata", 1 => "-1", 2 => "-vn"), $capturedFilter->apply($audio, $format)); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /tests/Unit/Filters/Audio/AudioResamplableFilterTest.php: -------------------------------------------------------------------------------- 1 | assertEquals(500, $filter->getRate()); 14 | } 15 | 16 | public function testApply() 17 | { 18 | $audio = $this->getAudioMock(); 19 | $format = $this->getMock('FFMpeg\Format\AudioInterface'); 20 | 21 | $filter = new AudioResamplableFilter(500); 22 | $this->assertEquals(array('-ac', 2, '-ar', 500), $filter->apply($audio, $format)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/Unit/Filters/FiltersCollectionTest.php: -------------------------------------------------------------------------------- 1 | assertCount(0, $coll); 15 | 16 | $coll->add($this->getMock('FFMpeg\Filters\FilterInterface')); 17 | $this->assertCount(1, $coll); 18 | 19 | $coll->add($this->getMock('FFMpeg\Filters\FilterInterface')); 20 | $this->assertCount(2, $coll); 21 | } 22 | 23 | public function testIterator() 24 | { 25 | $coll = new FiltersCollection(); 26 | $coll->add($this->getMock('FFMpeg\Filters\FilterInterface')); 27 | $coll->add($this->getMock('FFMpeg\Filters\FilterInterface')); 28 | 29 | $this->assertInstanceOf('\ArrayIterator', $coll->getIterator()); 30 | $this->assertCount(2, $coll->getIterator()); 31 | } 32 | 33 | public function testEmptyIterator() 34 | { 35 | $coll = new FiltersCollection(); 36 | $this->assertInstanceOf('\ArrayIterator', $coll->getIterator()); 37 | } 38 | 39 | public function testIteratorSort() 40 | { 41 | $coll = new FiltersCollection(); 42 | $coll->add(new SimpleFilter(array('a'))); 43 | $coll->add(new SimpleFilter(array('1'), 12)); 44 | $coll->add(new SimpleFilter(array('b'))); 45 | $coll->add(new SimpleFilter(array('2'), 12)); 46 | $coll->add(new SimpleFilter(array('c'))); 47 | $coll->add(new SimpleFilter(array('3'), 10)); 48 | $coll->add(new SimpleFilter(array('d'))); 49 | $coll->add(new SimpleFilter(array('4'), -2)); 50 | $coll->add(new SimpleFilter(array('e'))); 51 | 52 | $data = array(); 53 | $video = $this->getVideoMock(); 54 | $format = $this->getMock('FFMpeg\Format\AudioInterface'); 55 | 56 | foreach ($coll as $filter) { 57 | $data = array_merge($data, $filter->apply($video, $format)); 58 | } 59 | 60 | $this->assertEquals(array('1', '2', '3', 'a', 'b', 'c', 'd', 'e', '4'), $data); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /tests/Unit/Filters/Frame/DisplayRatioFixerFilterTest.php: -------------------------------------------------------------------------------- 1 | 'video', 'width' => 960, 'height' => 720)); 17 | $streams = new StreamCollection(array($stream)); 18 | 19 | $video = $this->getVideoMock(__FILE__); 20 | $video->expects($this->once()) 21 | ->method('getStreams') 22 | ->will($this->returnValue($streams)); 23 | 24 | $frame = new Frame($video, $this->getFFMpegDriverMock(), $this->getFFProbeMock(), new TimeCode(0, 0, 0, 0)); 25 | $filter = new DisplayRatioFixerFilter(); 26 | $this->assertEquals(array('-s', '960x720'), $filter->apply($frame)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/Unit/Filters/Frame/FrameFiltersTest.php: -------------------------------------------------------------------------------- 1 | getFrameMock(); 13 | $filters = new FrameFilters($frame); 14 | 15 | $frame->expects($this->once()) 16 | ->method('addFilter') 17 | ->with($this->isInstanceOf('FFMpeg\Filters\Frame\DisplayRatioFixerFilter')); 18 | 19 | $filters->fixDisplayRatio(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/Unit/Filters/Video/CropFilterTest.php: -------------------------------------------------------------------------------- 1 | 320, 'height' => 240, 'codec_type' => 'video')); 18 | $streams = new StreamCollection(array($stream)); 19 | 20 | $video = $this->getVideoMock(); 21 | $video->expects($this->once()) 22 | ->method('getStreams') 23 | ->will($this->returnValue($streams)); 24 | 25 | $format = $this->getMock('FFMpeg\Format\VideoInterface'); 26 | 27 | $dimension = new Dimension(200, 150); 28 | $point = new Point(25, 35); 29 | $filter = new CropFilter($point, $dimension); 30 | $expected = array( 31 | '-filter:v', 32 | 'crop=' . $dimension->getWidth() . ":" . $dimension->getHeight() . ":" . $point->getX() . ":" . $point->getY() 33 | ); 34 | $this->assertEquals($expected, $filter->apply($video, $format)); 35 | 36 | $this->assertEquals(200, $stream->get('width')); 37 | $this->assertEquals(150, $stream->get('height')); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /tests/Unit/Filters/Video/CustomFilterTest.php: -------------------------------------------------------------------------------- 1 | getVideoMock(); 15 | $format = $this->getMock('FFMpeg\Format\VideoInterface'); 16 | 17 | $filter = new CustomFilter('whatever i put would end up as a filter'); 18 | $this->assertEquals(array('-vf', 'whatever i put would end up as a filter'), $filter->apply($video, $format)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/Unit/Filters/Video/ExtractMultipleFramesFilterTest.php: -------------------------------------------------------------------------------- 1 | getVideoMock(); 18 | $pathfile = '/path/to/file'.mt_rand(); 19 | 20 | $format = $this->getMock('FFMpeg\Format\VideoInterface'); 21 | $format->expects($this->any()) 22 | ->method('getModulus') 23 | ->will($this->returnValue($modulus)); 24 | 25 | $streams = new StreamCollection(array( 26 | new Stream(array( 27 | 'codec_type' => 'video', 28 | 'duration' => $duration, 29 | )) 30 | )); 31 | 32 | $video->expects($this->once()) 33 | ->method('getStreams') 34 | ->will($this->returnValue($streams)); 35 | 36 | $filter = new ExtractMultipleFramesFilter($frameRate, $destinationFolder); 37 | $this->assertEquals($expected, $filter->apply($video, $format)); 38 | } 39 | 40 | public function provideFrameRates() 41 | { 42 | return array( 43 | array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_SEC, '/', 100, 2, array('-vf', 'fps=1/1', '/frame-%03d.jpg')), 44 | array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_2SEC, '/', 100, 2, array('-vf', 'fps=1/2', '/frame-%02d.jpg')), 45 | array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_5SEC, '/', 100, 2, array('-vf', 'fps=1/5', '/frame-%02d.jpg')), 46 | array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_10SEC, '/', 100, 2, array('-vf', 'fps=1/10', '/frame-%02d.jpg')), 47 | array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_30SEC, '/', 100, 2, array('-vf', 'fps=1/30', '/frame-%02d.jpg')), 48 | array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_60SEC, '/', 100, 2, array('-vf', 'fps=1/60', '/frame-%02d.jpg')), 49 | ); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/Unit/Filters/Video/FrameRateFilterTest.php: -------------------------------------------------------------------------------- 1 | getVideoMock(); 17 | $format = $this->getMock('FFMpeg\Format\VideoInterface'); 18 | $format->expects($this->any()) 19 | ->method('supportBFrames') 20 | ->will($this->returnValue(true)); 21 | 22 | $expected = array('-r', 54, '-b_strategy', '1', '-bf', '3', '-g', 42); 23 | 24 | $filter = new FrameRateFilter($framerate, $gop); 25 | $this->assertEquals($expected, $filter->apply($video, $format)); 26 | } 27 | 28 | public function testApplyWithAFormatThatDoesNotSupportsBFrames() 29 | { 30 | $framerate = new FrameRate(54); 31 | $gop = 42; 32 | 33 | $video = $this->getVideoMock(); 34 | $format = $this->getMock('FFMpeg\Format\VideoInterface'); 35 | $format->expects($this->any()) 36 | ->method('supportBFrames') 37 | ->will($this->returnValue(false)); 38 | 39 | $expected = array('-r', 54); 40 | 41 | $filter = new FrameRateFilter($framerate, $gop); 42 | $this->assertEquals($expected, $filter->apply($video, $format)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/Unit/Filters/Video/PadFilterTest.php: -------------------------------------------------------------------------------- 1 | getVideoMock(); 19 | $pathfile = '/path/to/file'.mt_rand(); 20 | 21 | $format = $this->getMock('FFMpeg\Format\VideoInterface'); 22 | 23 | $streams = new StreamCollection(array( 24 | new Stream(array( 25 | 'codec_type' => 'video', 26 | 'width' => $width, 27 | 'height' => $height, 28 | )) 29 | )); 30 | 31 | $filter = new PadFilter($dimension); 32 | $this->assertEquals($expected, $filter->apply($video, $format)); 33 | } 34 | 35 | public function provideDimensions() 36 | { 37 | return array( 38 | array(new Dimension(1000, 800), 640, 480, array('-vf', 'scale=iw*min(1000/iw\,800/ih):ih*min(1000/iw\,800/ih),pad=1000:800:(1000-iw)/2:(800-ih)/2')), 39 | array(new Dimension(300, 600), 640, 480, array('-vf', 'scale=iw*min(300/iw\,600/ih):ih*min(300/iw\,600/ih),pad=300:600:(300-iw)/2:(600-ih)/2')), 40 | array(new Dimension(100, 900), 640, 480, array('-vf', 'scale=iw*min(100/iw\,900/ih):ih*min(100/iw\,900/ih),pad=100:900:(100-iw)/2:(900-ih)/2')), 41 | array(new Dimension(1200, 200), 640, 480, array('-vf', 'scale=iw*min(1200/iw\,200/ih):ih*min(1200/iw\,200/ih),pad=1200:200:(1200-iw)/2:(200-ih)/2')), 42 | ); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/Unit/Filters/Video/RotateFilterTest.php: -------------------------------------------------------------------------------- 1 | 320, 'height' => 240, 'codec_type' => 'video')); 18 | $streams = new StreamCollection(array($stream)); 19 | 20 | $video = $this->getVideoMock(); 21 | $video->expects($this->once()) 22 | ->method('getStreams') 23 | ->will($this->returnValue($streams)); 24 | 25 | $format = $this->getMock('FFMpeg\Format\VideoInterface'); 26 | 27 | $filter = new RotateFilter($value); 28 | $this->assertEquals(array('-vf', $value, '-metadata:s:v:0', 'rotate=0'), $filter->apply($video, $format)); 29 | 30 | $this->assertEquals(240, $stream->get('width')); 31 | $this->assertEquals(320, $stream->get('height')); 32 | } 33 | 34 | public function provide90degresTranspositions() 35 | { 36 | return array( 37 | array(RotateFilter::ROTATE_90), 38 | array(RotateFilter::ROTATE_270), 39 | ); 40 | } 41 | 42 | /** 43 | * @dataProvider provideDegresWithoutTranspositions 44 | */ 45 | public function testApplyWithoutSizeTransformation($value) 46 | { 47 | $video = $this->getVideoMock(); 48 | $video->expects($this->never()) 49 | ->method('getStreams'); 50 | 51 | $format = $this->getMock('FFMpeg\Format\VideoInterface'); 52 | 53 | $filter = new RotateFilter($value); 54 | $this->assertEquals(array('-vf', $value, '-metadata:s:v:0', 'rotate=0'), $filter->apply($video, $format)); 55 | } 56 | 57 | public function provideDegresWithoutTranspositions() 58 | { 59 | return array( 60 | array(RotateFilter::ROTATE_180), 61 | ); 62 | } 63 | 64 | /** 65 | * @expectedException \FFMpeg\Exception\InvalidArgumentException 66 | * @expectedExceptionMessage Invalid angle value. 67 | */ 68 | public function testApplyInvalidAngle() 69 | { 70 | new RotateFilter('90'); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /tests/Unit/Filters/Video/SynchronizeFilterTest.php: -------------------------------------------------------------------------------- 1 | getVideoMock(); 13 | $format = $this->getMock('FFMpeg\Format\VideoInterface'); 14 | 15 | $filter = new SynchronizeFilter(); 16 | $this->assertEquals(array('-async', '1', '-metadata:s:v:0', 'start_time=0'), $filter->apply($video, $format)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/Unit/Filters/Video/VideoFiltersTest.php: -------------------------------------------------------------------------------- 1 | getVideoMock(); 19 | $filters = new VideoFilters($video); 20 | $dimension = $this->getDimensionMock(); 21 | 22 | $video->expects($this->once()) 23 | ->method('addFilter') 24 | ->with($this->isInstanceOf('FFMpeg\Filters\Video\ResizeFilter')) 25 | ->will($this->returnCallback(function ($filter) use (&$capturedFilter) { 26 | $capturedFilter = $filter; 27 | })); 28 | 29 | $filters->resize($dimension, $mode, $forceStandards); 30 | 31 | $this->assertSame($mode, $capturedFilter->getMode()); 32 | $this->assertSame($forceStandards, $capturedFilter->areStandardsForced()); 33 | $this->assertSame($dimension, $capturedFilter->getDimension()); 34 | } 35 | 36 | public function provideResizeOptions() 37 | { 38 | return array( 39 | array(ResizeFilter::RESIZEMODE_FIT, true), 40 | array(ResizeFilter::RESIZEMODE_SCALE_WIDTH, true), 41 | array(ResizeFilter::RESIZEMODE_SCALE_HEIGHT, false), 42 | array(ResizeFilter::RESIZEMODE_INSET, false), 43 | ); 44 | } 45 | 46 | public function testResample() 47 | { 48 | $capturedFilter = null; 49 | 50 | $video = $this->getVideoMock(); 51 | $filters = new VideoFilters($video); 52 | $framerate = $this->getFramerateMock(); 53 | $gop = 42; 54 | 55 | $video->expects($this->once()) 56 | ->method('addFilter') 57 | ->with($this->isInstanceOf('FFMpeg\Filters\Video\FrameRateFilter')) 58 | ->will($this->returnCallback(function ($filter) use (&$capturedFilter) { 59 | $capturedFilter = $filter; 60 | })); 61 | 62 | $filters->framerate($framerate, $gop); 63 | 64 | $this->assertSame($framerate, $capturedFilter->getFramerate()); 65 | $this->assertSame($gop, $capturedFilter->getGOP()); 66 | } 67 | 68 | public function testSynchronize() 69 | { 70 | $video = $this->getVideoMock(); 71 | $filters = new VideoFilters($video); 72 | 73 | $video->expects($this->once()) 74 | ->method('addFilter') 75 | ->with($this->isInstanceOf('FFMpeg\Filters\Video\SynchronizeFilter')); 76 | 77 | $filters->synchronize(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /tests/Unit/Filters/Video/WatermarkFilterTest.php: -------------------------------------------------------------------------------- 1 | 320, 'height' => 240, 'codec_type' => 'video')); 16 | $streams = new StreamCollection(array($stream)); 17 | 18 | $video = $this->getVideoMock(); 19 | 20 | $format = $this->getMock('FFMpeg\Format\VideoInterface'); 21 | 22 | $filter = new WatermarkFilter(__DIR__ . '/../../../files/watermark.png'); 23 | $this->assertEquals(array('-vf', 'movie='.__DIR__ .'/../../../files/watermark.png [watermark]; [in][watermark] overlay=0:0 [out]'), $filter->apply($video, $format)); 24 | 25 | // check size of video is unchanged 26 | $this->assertEquals(320, $stream->get('width')); 27 | $this->assertEquals(240, $stream->get('height')); 28 | } 29 | 30 | public function testDifferentCoordinaates() 31 | { 32 | $video = $this->getVideoMock(); 33 | $format = $this->getMock('FFMpeg\Format\VideoInterface'); 34 | 35 | // test position absolute 36 | $filter = new WatermarkFilter(__DIR__ . '/../../../files/watermark.png', array( 37 | 'position' => 'absolute', 38 | 'x' => 10, 'y' => 5 39 | )); 40 | $this->assertEquals(array('-vf', 'movie='.__DIR__ .'/../../../files/watermark.png [watermark]; [in][watermark] overlay=10:5 [out]'), $filter->apply($video, $format)); 41 | 42 | // test position relative 43 | $filter = new WatermarkFilter(__DIR__ . '/../../../files/watermark.png', array( 44 | 'position' => 'relative', 45 | 'bottom' => 10, 'left' => 5 46 | )); 47 | $this->assertEquals(array('-vf', 'movie='.__DIR__ .'/../../../files/watermark.png [watermark]; [in][watermark] overlay=5:main_h - 10 - overlay_h [out]'), $filter->apply($video, $format)); 48 | 49 | // test position relative 50 | $filter = new WatermarkFilter(__DIR__ . '/../../../files/watermark.png', array( 51 | 'position' => 'relative', 52 | 'bottom' => 5, 'right' => 4 53 | )); 54 | $this->assertEquals(array('-vf', 'movie='.__DIR__ .'/../../../files/watermark.png [watermark]; [in][watermark] overlay=main_w - 4 - overlay_w:main_h - 5 - overlay_h [out]'), $filter->apply($video, $format)); 55 | 56 | // test position relative 57 | $filter = new WatermarkFilter(__DIR__ . '/../../../files/watermark.png', array( 58 | 'position' => 'relative', 59 | 'left' => 5, 'top' => 11 60 | )); 61 | $this->assertEquals(array('-vf', 'movie='.__DIR__ .'/../../../files/watermark.png [watermark]; [in][watermark] overlay=5:11 [out]'), $filter->apply($video, $format)); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /tests/Unit/Filters/Waveform/WaveformDownmixFilterTest.php: -------------------------------------------------------------------------------- 1 | 'audio', 'width' => 960, 'height' => 720)); 17 | $streams = new StreamCollection(array($stream)); 18 | 19 | $audio = $this->getAudioMock(__FILE__); 20 | $audio->expects($this->once()) 21 | ->method('getStreams') 22 | ->will($this->returnValue($streams)); 23 | 24 | $waveform = new Waveform($audio, $this->getFFMpegDriverMock(), $this->getFFProbeMock(), 640, 120); 25 | $filter = new WaveformDownmixFilter(TRUE); 26 | $this->assertEquals(array('"aformat=channel_layouts=mono"'), $filter->apply($waveform)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/Unit/Filters/Waveform/WaveformFiltersTest.php: -------------------------------------------------------------------------------- 1 | getWaveformMock(); 13 | $filters = new WaveformFilters($Waveform); 14 | 15 | $Waveform->expects($this->once()) 16 | ->method('addFilter') 17 | ->with($this->isInstanceOf('FFMpeg\Filters\Waveform\WaveformDownmixFilter')); 18 | 19 | $filters->setDownmix(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/Unit/Format/Audio/AacTest.php: -------------------------------------------------------------------------------- 1 | getClassName(); 10 | $ffprobe = $this->getFFProbeMock(); 11 | $format = $this->getFormatMock(); 12 | 13 | $ffprobe->expects($this->once()) 14 | ->method('format') 15 | ->with(__FILE__) 16 | ->will($this->returnValue($format)); 17 | 18 | $media = new $classname(__FILE__, $this->getFFMpegDriverMock(), $ffprobe); 19 | $this->assertSame($format, $media->getFormat()); 20 | } 21 | 22 | public function testGetFormat() 23 | { 24 | $classname = $this->getClassName(); 25 | $ffprobe = $this->getFFProbeMock(); 26 | $streams = $this->getStreamCollectionMock(); 27 | 28 | $ffprobe->expects($this->once()) 29 | ->method('streams') 30 | ->with(__FILE__) 31 | ->will($this->returnValue($streams)); 32 | 33 | $media = new $classname(__FILE__, $this->getFFMpegDriverMock(), $ffprobe); 34 | $this->assertSame($streams, $media->getStreams()); 35 | } 36 | 37 | abstract protected function getClassName(); 38 | } 39 | -------------------------------------------------------------------------------- /tests/Unit/Media/AudioProg.php: -------------------------------------------------------------------------------- 1 | getFFMpegDriverMock(); 13 | $ffprobe = $this->getFFProbeMock(); 14 | 15 | $waveform = new Waveform($this->getAudioMock(__FILE__), $driver, $ffprobe, 640, 120); 16 | $this->assertInstanceOf('FFMpeg\Filters\Waveform\WaveformFilters', $waveform->filters()); 17 | } 18 | 19 | public function testAddFiltersAddsAFilter() 20 | { 21 | $driver = $this->getFFMpegDriverMock(); 22 | $ffprobe = $this->getFFProbeMock(); 23 | 24 | $filters = $this->getMockBuilder('FFMpeg\Filters\FiltersCollection') 25 | ->disableOriginalConstructor() 26 | ->getMock(); 27 | 28 | $filter = $this->getMock('FFMpeg\Filters\Waveform\WaveformFilterInterface'); 29 | 30 | $filters->expects($this->once()) 31 | ->method('add') 32 | ->with($filter); 33 | 34 | $waveform = new Waveform($this->getAudioMock(__FILE__), $driver, $ffprobe, 640, 120); 35 | $waveform->setFiltersCollection($filters); 36 | $waveform->addFilter($filter); 37 | } 38 | 39 | /** 40 | * @dataProvider provideSaveOptions 41 | */ 42 | public function testSave($commands) 43 | { 44 | $driver = $this->getFFMpegDriverMock(); 45 | $ffprobe = $this->getFFProbeMock(); 46 | 47 | $pathfile = '/tests/files/Audio.mp3'; 48 | 49 | array_push($commands, $pathfile); 50 | 51 | $driver->expects($this->once()) 52 | ->method('command') 53 | ->with($commands); 54 | 55 | $waveform = new Waveform($this->getAudioMock(__FILE__), $driver, $ffprobe, 640, 120, ['#FFFFFF']); 56 | $this->assertSame($waveform, $waveform->save($pathfile)); 57 | } 58 | 59 | public function provideSaveOptions() 60 | { 61 | return array( 62 | array( 63 | array( 64 | '-y', '-i', NULL, '-filter_complex', 65 | 'showwavespic=colors=#FFFFFF:s=640x120', 66 | '-frames:v', '1', 67 | ), 68 | ), 69 | ); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /tests/bootstrap.php: -------------------------------------------------------------------------------- 1 |