Skip to content

Commit fbe44c4

Browse files
committed
Create TrimFilter
1 parent 2255db8 commit fbe44c4

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

FfmpegExtensions.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,42 @@ public function apply(FFMpeg\Media\Video $video, FFMpeg\Format\VideoInterface $f
211211
}
212212
}
213213

214+
Class TrimFilter implements FFmpeg\Filters\Video\VideoFilterInterface {
215+
216+
private $start;
217+
private $end;
218+
private $priority;
219+
220+
public function __construct($start, $end, $priority = 0) {
221+
$this->start = $start ? $start : 0;
222+
$this->end = $end;
223+
$this->priority = $priority;
224+
}
225+
226+
public function getPriority() {
227+
return $this->priority;
228+
}
229+
230+
public function getStart() {
231+
return $this->start;
232+
}
233+
234+
public function getEnd() {
235+
return $this->end;
236+
}
237+
238+
public function apply(FFMpeg\Media\Video $video, FFMpeg\Format\VideoInterface $format) {
239+
$commands = array("-ss", (string) $this->start);
240+
241+
if ($this->end) {
242+
$commands[] = "-to";
243+
$commands[] = (string) $this->end;
244+
}
245+
246+
return $commands;
247+
}
248+
}
249+
214250

215251
Class CropFilter implements FFMpeg\Filters\Video\VideoFilterInterface {
216252

FfmpegVideoTranscoding.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ public static function transcode($source, $options) {
151151
$video->addFilter($filter);
152152
if (@$options["noaudio"])
153153
$video->addFilter(new VideoOnlyFilter());
154-
if (@$options["duration"])
154+
if (@$options["ss"] || @$options["to"]) {
155+
$video->addFilter(new TrimFilter(@$options["ss"], @$options["to"]));
156+
} else if (@$options["duration"])
155157
$video->addFilter(new DurationFilter($options["duration"]));
156158
if (@$options["format"]) {
157159
if ($options["format"] == "mp4") {

0 commit comments

Comments
 (0)