From b3bfb34475465a186aafa2968607e85086e87fb8 Mon Sep 17 00:00:00 2001 From: Ilja Lukin Date: Tue, 20 Nov 2018 23:32:47 +0100 Subject: [PATCH 1/4] added custom frame filter --- .../Filters/Frame/CustomFrameFilter.php | 54 +++++++++++++++++++ src/FFMpeg/Filters/Frame/FrameFilters.php | 14 +++++ 2 files changed, 68 insertions(+) create mode 100644 src/FFMpeg/Filters/Frame/CustomFrameFilter.php diff --git a/src/FFMpeg/Filters/Frame/CustomFrameFilter.php b/src/FFMpeg/Filters/Frame/CustomFrameFilter.php new file mode 100644 index 0000000..8ace0e9 --- /dev/null +++ b/src/FFMpeg/Filters/Frame/CustomFrameFilter.php @@ -0,0 +1,54 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FFMpeg\Filters\Frame; + +use FFMpeg\Exception\RuntimeException; +use FFMpeg\Media\Frame; + +class CustomFrameFilter implements FrameFilterInterface +{ + /** @var string */ + private $filter; + /** @var integer */ + private $priority; + + /** + * A custom filter, useful if you want to build complex filters + * + * @param string $filter + * @param int $priority + */ + public function __construct($filter, $priority = 0) + { + $this->filter = $filter; + $this->priority = $priority; + } + + /** + * {@inheritdoc} + */ + public function getPriority() + { + return $this->priority; + } + + /** + * {@inheritdoc} + */ + public function apply(Frame $frame) + { + $commands = array('-vf', $this->filter); + + return $commands; + } +} + diff --git a/src/FFMpeg/Filters/Frame/FrameFilters.php b/src/FFMpeg/Filters/Frame/FrameFilters.php index e4b9614..ad7e95a 100644 --- a/src/FFMpeg/Filters/Frame/FrameFilters.php +++ b/src/FFMpeg/Filters/Frame/FrameFilters.php @@ -36,4 +36,18 @@ class FrameFilters return $this; } + + /** + * Applies a custom filter: -vf foo bar + * + * @param string $parameters + * + * @return FrameFilters + */ + public function custom($parameters) + { + $this->frame->addFilter(new CustomFrameFilter($parameters)); + + return $this; + } } From 7b98238fa2d92b05321b51774f23d34df5519f3d Mon Sep 17 00:00:00 2001 From: Ilja Lukin Date: Fri, 23 Nov 2018 20:14:26 +0100 Subject: [PATCH 2/4] added unit test for custom frame filter --- .../Filters/Frame/CustomFrameFilterTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/Unit/Filters/Frame/CustomFrameFilterTest.php diff --git a/tests/Unit/Filters/Frame/CustomFrameFilterTest.php b/tests/Unit/Filters/Frame/CustomFrameFilterTest.php new file mode 100644 index 0000000..5308b87 --- /dev/null +++ b/tests/Unit/Filters/Frame/CustomFrameFilterTest.php @@ -0,0 +1,17 @@ +getFrameMock(); + + $filter = new CustomFrameFilter('whatever i put would end up as a filter'); + $this->assertEquals(array('-vf', 'whatever i put would end up as a filter'), $filter->apply($frame)); + } +} From fa2f89a0cff64267c67c1e2b6e6f798f7ce45bae Mon Sep 17 00:00:00 2001 From: Ilja Lukin <41321551+iljalukin@users.noreply.github.com> Date: Fri, 23 Nov 2018 21:27:28 +0100 Subject: [PATCH 3/4] fixed formatting --- tests/Unit/Filters/Frame/CustomFrameFilterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/Filters/Frame/CustomFrameFilterTest.php b/tests/Unit/Filters/Frame/CustomFrameFilterTest.php index 5308b87..69a6665 100644 --- a/tests/Unit/Filters/Frame/CustomFrameFilterTest.php +++ b/tests/Unit/Filters/Frame/CustomFrameFilterTest.php @@ -12,6 +12,6 @@ class CustomFrameFilterTest extends TestCase $frame = $this->getFrameMock(); $filter = new CustomFrameFilter('whatever i put would end up as a filter'); - $this->assertEquals(array('-vf', 'whatever i put would end up as a filter'), $filter->apply($frame)); + $this->assertEquals(array('-vf', 'whatever i put would end up as a filter'), $filter->apply($frame)); } } From bf19f705a81d16a01543921346996a9e84ed895d Mon Sep 17 00:00:00 2001 From: Jens Hausdorf Date: Fri, 23 Nov 2018 21:36:39 +0100 Subject: [PATCH 4/4] Fix formatting --- tests/Unit/Filters/Frame/CustomFrameFilterTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Unit/Filters/Frame/CustomFrameFilterTest.php b/tests/Unit/Filters/Frame/CustomFrameFilterTest.php index 69a6665..98869af 100644 --- a/tests/Unit/Filters/Frame/CustomFrameFilterTest.php +++ b/tests/Unit/Filters/Frame/CustomFrameFilterTest.php @@ -9,9 +9,9 @@ class CustomFrameFilterTest extends TestCase { public function testApplyCustomFrameFilter() { - $frame = $this->getFrameMock(); + $frame = $this->getFrameMock(); - $filter = new CustomFrameFilter('whatever i put would end up as a filter'); - $this->assertEquals(array('-vf', 'whatever i put would end up as a filter'), $filter->apply($frame)); + $filter = new CustomFrameFilter('whatever i put would end up as a filter'); + $this->assertEquals(array('-vf', 'whatever i put would end up as a filter'), $filter->apply($frame)); } }