diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 9ef5e31..740c884 --- a/README.md +++ b/README.md @@ -175,6 +175,19 @@ filters solves this issue. $video->filters()->synchronize(); ``` +###### Clip + +Cuts the video at a desired point. + +```php +$video->filters()->clip(FFMpeg\Coordinate\TimeCode::fromSeconds(30), FFMpeg\Coordinate\TimeCode::fromSeconds(15)); +``` + +The clip filter takes two parameters: + +- `$start`, an instance of `FFMpeg\Coordinate\TimeCode`, specifies the start point of the clip +- `$duration`, optional, an instance of `FFMpeg\Coordinate\TimeCode`, specifies the duration of the clip + #### Audio `FFMpeg\Media\Audio` can be transcoded, ie : change codec, isolate audio or diff --git a/src/FFMpeg/Filters/Video/ClipFilter.php b/src/FFMpeg/Filters/Video/ClipFilter.php new file mode 100755 index 0000000..5e015a8 --- /dev/null +++ b/src/FFMpeg/Filters/Video/ClipFilter.php @@ -0,0 +1,72 @@ + + * + * 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\Format\VideoInterface; +use FFMpeg\Media\Video; +use FFMpeg\Coordinate\TimeCode; + +class ClipFilter implements VideoFilterInterface +{ + /** @var TimeCode */ + private $start; + /** @var TimeCode */ + private $duration; + /** @var integer */ + private $priority; + + public function __construct(TimeCode $start, TimeCode $duration = null, $priority = 0) + { + $this->start = $start; + $this->duration = $duration; + $this->priority = $priority; + } + + /** + * {@inheritdoc} + */ + public function getPriority() + { + return $this->priority; + } + + /** + * @return TimeCode + */ + public function getStart() + { + return $this->start; + } + + /** + * @return TimeCode + */ + public function getDuration() + { + return $this->duration; + } + + /** + * {@inheritdoc} + */ + public function apply(Video $video, VideoInterface $format) + { + $commands = array('-ss', (string) $this->start); + + if ($this->duration !== null) { + $commands[] = '-t'; + $commands[] = (string) $this->duration; + } + + return $commands; + } +} diff --git a/src/FFMpeg/Filters/Video/VideoFilters.php b/src/FFMpeg/Filters/Video/VideoFilters.php old mode 100644 new mode 100755 index d0ffc8d..c8a31d8 --- a/src/FFMpeg/Filters/Video/VideoFilters.php +++ b/src/FFMpeg/Filters/Video/VideoFilters.php @@ -67,6 +67,21 @@ class VideoFilters extends AudioFilters return $this; } + /** + * Clips (cuts) the video. + * + * @param TimeCode $start + * @param TimeCode $duration + * + * @return VideoFilters + */ + public function clip($start, $duration = null) + { + $this->media->addFilter(new ClipFilter($start, $duration)); + + return $this; + } + /** * Resamples the audio file. *