Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added getRotation() and test #34

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 24 additions & 1 deletion FFmpegMovie.php
Expand Up @@ -31,6 +31,7 @@ class FFmpegMovie implements Serializable {
protected static $REGEX_HAS_AUDIO = '/Stream.+Audio/';
protected static $REGEX_HAS_VIDEO = '/Stream.+Video/';
protected static $REGEX_ERRORS = '/.*(Error|Permission denied|could not seek to position|Invalid pixel format|Unknown encoder|could not find codec|does not contain any stream).*/i';
protected static $REGEX_ROTATION = '/rotate\s*[:=]\s*(-?[0-9]+)/';

/**
* FFmpeg binary
Expand Down Expand Up @@ -132,6 +133,12 @@ class FFmpegMovie implements Serializable {
*/
protected $frameWidth;
/**
* Movie rotiation
*
* @var int
*/
protected $rotation;
/**
* Movie pixel format
*
* @var string
Expand Down Expand Up @@ -445,7 +452,23 @@ public function getFrameWidth() {

return $this->frameWidth;
}


/**
* Return the rotation angle of the video file
*
* @return into
*/
public function getRotation()
{
if ($this->rotation === null) {
$match = array();
preg_match(self::$REGEX_ROTATION, $this->output, $match);
$this->rotation = (array_key_exists(1, $match)) ? intval(trim($match[1])) : 0;
}

return $this->rotation;
}

/**
* Return the pixel format of the movie.
*
Expand Down
7 changes: 6 additions & 1 deletion test/FFmpegMovieTest.php
Expand Up @@ -152,6 +152,11 @@ public function testGetFrameWidth() {
$this->assertEquals(640, $this->movie->getFrameWidth(), 'Frame width should be int(640)');
}

public function ttetGetRotation() {
$this->assertInternalType('int', $this->movie->getRotation(), 'Frame rotation is of integer type');
$this->assertEquals(0, $this->movie->getRotation(), 'Frame roation should be int(0)');
}

public function testGetPixelFormat() {
$this->assertInternalType('string', $this->movie->getPixelFormat(), 'Pixel format is of string type');
$this->assertEquals('yuv420p', $this->movie->getPixelFormat(), 'Pixel format should be string(yuv420p)');
Expand Down Expand Up @@ -273,4 +278,4 @@ public function testSerializeUnserialize() {
$this->assertInternalType('float', $this->movie->getDuration(), 'Duration is of float type');
$this->assertEquals(32.14, $this->movie->getDuration(), 'Duration should be float(32.14)');
}
}
}