Skip to content

Commit

Permalink
Merge pull request #7 from nshahzad/master
Browse files Browse the repository at this point in the history
Allow quality and size changes through ffmpeg instead of GD
  • Loading branch information
Vladimír Gorej committed Nov 24, 2011
2 parents c5d4638 + 562205d commit 568e84c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
.svn
.buildpath
.project
.settings
Expand Down
34 changes: 30 additions & 4 deletions FFmpegMovie.php
Expand Up @@ -609,20 +609,46 @@ public function hasVideo() {
* * framenumber - Frame from the movie to return. If no framenumber is specified, returns the next frame of the movie.
*
* @param int $framenumber
* @param int $height
* @param int $width
* @param int $quality
* @return FFmpegFrame|boolean
*/
public function getFrame($framenumber = null) {
public function getFrame($framenumber = null, $height = null, $width = null, $quality = null) {
// Set frame position for frame extraction
$framePos = ($framenumber === null) ? $this->frameNumber : (((int) $framenumber) - 1);

// Frame position out of range
if (!is_numeric($framePos) || $framePos < 0 || $framePos > $this->getFrameCount()) {
return false;
}

}

if(is_numeric($height) !== false && is_numeric($width) !== false) {
$image_size = ' -s '.$height.'x'.$width;
} else {
$image_size = '';
}

if(is_numeric($quality) !== false) {
$quality = ' -qscale '.$quality;
} else {
$quality = '';
}

$frameFilePath = sys_get_temp_dir().DIRECTORY_SEPARATOR.uniqid('frame', true).'.jpg';
$frameTime = round((($framePos / $this->getFrameCount()) * $this->getDuration()), 4);
exec($this->ffmpegBinary.' -ss '.$frameTime.' -i '.escapeshellarg($this->movieFile).' -vframes 1 '.$frameFilePath.' 2>&1');

exec(implode(' ', array(
$this->ffmpegBinary,
'-i '.escapeshellarg($this->movieFile),
'-f image2',
'-ss '.$frameTime,
'-vframes 1',
$image_size,
$quality,
$frameFilePath,
'2>&1',
)));

// Cannot write frame to the data storage
if (!file_exists($frameFilePath)) {
Expand Down

0 comments on commit 568e84c

Please sign in to comment.