diff --git a/src/FFMpeg/Filters/Video/PadFilter.php b/src/FFMpeg/Filters/Video/PadFilter.php new file mode 100644 index 0000000..551604c --- /dev/null +++ b/src/FFMpeg/Filters/Video/PadFilter.php @@ -0,0 +1,60 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FFMpeg\Filters\Video; + +use FFMpeg\Coordinate\Dimension; +use FFMpeg\Exception\RuntimeException; +use FFMpeg\Media\Video; +use FFMpeg\Format\VideoInterface; + +class PadFilter implements VideoFilterInterface +{ + /** @var Dimension */ + private $dimension; + /** @var integer */ + private $priority; + + public function __construct(Dimension $dimension, $priority = 0) + { + $this->dimension = $dimension; + $this->priority = $priority; + } + + /** + * {@inheritdoc} + */ + public function getPriority() + { + return $this->priority; + } + + /** + * @return Dimension + */ + public function getDimension() + { + return $this->dimension; + } + + /** + * {@inheritdoc} + */ + public function apply(Video $video, VideoInterface $format) + { + $commands = array(); + + $commands[] = '-vf'; + $commands[] = 'pad=' . $this->dimension->getWidth() . ':' . $this->dimension->getHeight() . ':(' . $this->dimension->getWidth() . '-iw)/2:(' . $this->dimension->getHeight() .'-ih)/2'; + + return $commands; + } +} diff --git a/src/FFMpeg/Filters/Video/VideoFilters.php b/src/FFMpeg/Filters/Video/VideoFilters.php index 00a99d9..a5caa32 100644 --- a/src/FFMpeg/Filters/Video/VideoFilters.php +++ b/src/FFMpeg/Filters/Video/VideoFilters.php @@ -98,6 +98,20 @@ class VideoFilters extends AudioFilters return $this; } + /** + * Adds padding (black bars) to a video. + * + * @param Dimension $dimension + * + * @return VideoFilters + */ + public function pad(Dimension $dimension) + { + $this->media->addFilter(new PadFilter($dimension)); + + return $this; + } + public function rotate($angle) { $this->media->addFilter(new RotateFilter($angle, 30));