-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c570291
commit 104b166
Showing
7 changed files
with
167 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace FFMpegLib\Commands; | ||
|
||
use FFMpegLib\Interfaces\CommandInterface; | ||
use FFMpegLib\Traits\Validation; | ||
use FFMpegLib\Inspectors\VideoInspector; | ||
use FFMpegLib\Util\Time; | ||
use FFMpegLib\Commands\Exceptions\VideoLengthError; | ||
|
||
class CreateImagesCommand implements CommandInterface { | ||
use Validation; | ||
|
||
protected $args; | ||
protected $validation; | ||
protected $imageFullPathName; | ||
protected $framesCreated; | ||
|
||
public function __construct | ||
( | ||
$videoFile = null, | ||
$imageFullPathName = '', | ||
$startPosition = '00:00:00', | ||
$endPosition = '00:00:03', | ||
Time $videoDuration | ||
) { | ||
ffmpegInitialized(); | ||
$this->validation = false; | ||
$this->imageFullPathName = formatImageNameFoFFMpeg($imageFullPathName); | ||
$endPositionTime = Time::createFromString($endPosition); | ||
|
||
$startPositionTime = Time::createFromString($startPosition); | ||
|
||
if ($startPositionTime->getTimeInSeconds() > $videoDuration->getTimeInSeconds()) { | ||
$startPosition = "00:00:00"; | ||
$startPositionTime = Time::createFromString($startPosition); | ||
} | ||
|
||
if ($endPositionTime->getTimeInSeconds() > $videoDuration->getTimeInSeconds()) { | ||
throw new VideoLengthError($endPosition, $videoDuration->getFullTime()); | ||
} | ||
|
||
// create an instance of inpsector | ||
$videoInspector = new VideoInspector($videoFile); | ||
|
||
// check if file is supported | ||
$videoInspector->checkFile(); | ||
|
||
$secondsCombinedFromStartAndEnd = $endPositionTime->getSeconds() - $startPositionTime->getSeconds(); | ||
|
||
$MAX_FRAMES = 25; | ||
$this->framesCreated = $MAX_FRAMES * $secondsCombinedFromStartAndEnd; | ||
|
||
$this->args = [ | ||
'ffmpeg', | ||
'-ss ' . $startPosition, | ||
'-to ' . $endPosition, | ||
'-i ' . $videoFile, | ||
'-frames ' . $this->framesCreated, | ||
$this->imageFullPathName, | ||
'2>&1', | ||
]; | ||
} | ||
|
||
public function getCommandArgs() { | ||
return implode(' ', $this->args); | ||
} | ||
|
||
public function checkOutput($output) { | ||
if (!$output) { | ||
$this->validation = false; | ||
} | ||
|
||
$this->validation = true; | ||
} | ||
|
||
public function framesCreated() { | ||
return $this->framesCreated; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace FFMpegLib\Commands\Exceptions; | ||
|
||
class NotGifFileException extends \Exception { | ||
public function __construct($file = '') { | ||
parent::__construct('Please enter a file with gif extension not ' . $file); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace FFMpegLib\Commands\Exceptions; | ||
|
||
class VideoLengthError extends \Exception { | ||
public function __construct($passedTime = '', $videoTime = '') { | ||
parent::__construct('Passed length ' . $passedTime . ' is longer than video\'s ' . $videoTime); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace FFMpegLib\Commands; | ||
|
||
use FFMpegLib\Interfaces\CommandInterface; | ||
use FFMpegLib\Traits\Validation; | ||
use FFMpegLib\Commands\Exceptions\NotGifFileException; | ||
|
||
class GifCommand implements CommandInterface { | ||
use Validation; | ||
|
||
protected $args; | ||
protected $validation; | ||
|
||
public function __construct($imagesFirstName = 'image%d.png', $outputGifFile = 'video.gif') { | ||
ffmpegInitialized(); | ||
|
||
if (!preg_match('~\.gif$~', $outputGifFile)) { | ||
throw new NotGifFileException($outputGifFile); | ||
} | ||
|
||
$this->validation = false; | ||
$imagesFirstName = formatImageNameFoFFMpeg($imagesFirstName); | ||
|
||
$this->args = [ | ||
'ffmpeg', | ||
'-i ' . $imagesFirstName, | ||
$outputGifFile, | ||
'2>&1', | ||
]; | ||
} | ||
|
||
public function getCommandArgs() { | ||
return implode(' ', $this->args); | ||
} | ||
|
||
public function checkOutput($output) { | ||
if (!$output) { | ||
$this->validation = false; | ||
} | ||
|
||
$this->validation = true; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters