Skip to content

Commit 0138551

Browse files
ABM-Danchar0n
authored andcommitted
Implemented support for multiple file types for getFrameAtTime
Some other generic cleanup.
1 parent 162d37b commit 0138551

5 files changed

Lines changed: 19 additions & 11 deletions

File tree

FFmpegAnimatedGif.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ class FFmpegAnimatedGif implements Serializable {
7272
* @param int $height Height of the animated gif.
7373
* @param int $frameRate Frame rate of the animated gif in frames per second.
7474
* @param int $loopCount Number of times to loop the animation. Put a zero here to loop forever or omit this parameter to disable looping.
75-
* @return FFmpegAnimatedGif
7675
*/
7776
public function __construct($outFilePath, $width, $height, $frameRate, $loopCount) {
7877
$this->outFilePath = $outFilePath;
@@ -105,8 +104,6 @@ public function addFrame(FFmpegFrame $frame) {
105104
* @return void
106105
*/
107106
protected function addGifHeader() {
108-
$cmap = 0;
109-
110107
if (ord($this->frames[0]{10}) & 0x80) {
111108
$cmap = 3 * (2 << (ord($this->frames[0]{10}) & 0x07));
112109

@@ -140,6 +137,8 @@ protected function addFrameData($i, $d) {
140137

141138
$Locals_ext = "!\xF9\x04".chr(($DIS << 2 ) + 0). chr(($d >> 0) & 0xFF).chr(($d >> 8) & 0xFF)."\x0\x0";
142139

140+
$Locals_img = null;
141+
143142
if ($COL > -1 && ord($this->frames[$i]{10}) & 0x80) {
144143
for ($j = 0; $j < (2 << (ord($this->frames[$i]{10}) & 0x07)); $j++) {
145144
if (ord($Locals_rgb{3 * $j + 0}) == (($COL >> 16 ) & 0xFF)

FFmpegFrame.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class FFmpegFrame implements Serializable {
4444
* @param resource $gdImage image resource of type gd
4545
* @param float $pts frame presentation timestamp; OPTIONAL parameter; DEFAULT value 0.0
4646
* @throws Exception
47-
* @return FFmpegFrame
4847
*/
4948
public function __construct($gdImage, $pts = 0.0) {
5049
if (!(is_resource($gdImage) && get_resource_type($gdImage) == 'gd')) {

FFmpegMovie.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ class FFmpegMovie implements Serializable {
196196
* @param string $moviePath full path to the movie file
197197
* @param OutputProvider $outputProvider provides parsable output
198198
* @param string $ffmpegBinary ffmpeg executable, if $outputProvider not specified
199-
* @throws Exception
200-
* @return FFmpegMovie
199+
* @throws Exception
201200
*/
202201
public function __construct($moviePath, OutputProvider $outputProvider = null, $ffmpegBinary = 'ffmpeg') {
203202
$this->movieFile = $moviePath;
@@ -652,7 +651,8 @@ public function getFrame($framenumber = null, $height = null, $width = null, $qu
652651
*/
653652
public function getFrameAtTime($seconds = null, $width = null, $height = null, $quality = null, $frameFilePath = null, &$output = null) {
654653
// Set frame position for frame extraction
655-
$frameTime = ($seconds === null) ? 0 : $seconds;
654+
$frameTime = ($seconds === null) ? 0 : $seconds;
655+
656656

657657
// time out of range
658658
if (!is_numeric($frameTime) || $frameTime < 0 || $frameTime > $this->getDuration()) {
@@ -717,7 +717,17 @@ public function getFrameAtTime($seconds = null, $width = null, $height = null, $
717717
}
718718

719719
// Create gdimage and delete temporary image
720-
$gdImage = imagecreatefromjpeg($frameFilePath);
720+
switch (getimagesize($frameFilePath)[2]) {
721+
case IMAGETYPE_GIF:
722+
$gdImage = imagecreatefromgif($frameFilePath);
723+
break;
724+
case IMAGETYPE_PNG:
725+
$gdImage = imagecreatefrompng($frameFilePath);
726+
break;
727+
default:
728+
$gdImage = imagecreatefromjpeg($frameFilePath);
729+
}
730+
721731
if ($deleteTmp && is_writable($frameFilePath)) {
722732
unlink($frameFilePath);
723733
}

adapter/ffmpeg_animated_gif.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* ffmpeg_animated_gif serves as a compatiblity adapter for old ffmpeg-php extension
3+
* ffmpeg_animated_gif serves as a compatibility adapter for old ffmpeg-php extension
44
*
55
* @author char0n (Vladimír Gorej, gorej@codescale.net)
66
* @package FFmpegPHP

adapter/ffmpeg_frame.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public function getPresentationTimestamp() {
3434
}
3535

3636
public function resize($width, $height, $cropTop = 0, $cropBottom = 0, $cropLeft = 0, $cropRight = 0) {
37-
return $this->adaptee->resize($width, $height, $cropTop, $cropBottom, $cropLeft, $cropRight);
37+
$this->adaptee->resize($width, $height, $cropTop, $cropBottom, $cropLeft, $cropRight);
3838
}
3939

4040
public function crop($cropTop, $cropBottom = 0, $cropLeft = 0, $cropRight = 0) {
41-
return $this->adaptee->crop($cropTop, $cropBottom, $cropLeft, $cropRight);
41+
$this->adaptee->crop($cropTop, $cropBottom, $cropLeft, $cropRight);
4242
}
4343

4444
public function toGDImage() {

0 commit comments

Comments
 (0)