scratch – Blame information for rev 115
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
115 | office | 1 | <?php |
2 | |||
3 | /* |
||
4 | * This file is part of PHP-FFmpeg. |
||
5 | * |
||
6 | * (c) Alchemy <dev.team@alchemy.fr> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace FFMpeg\Filters\Video; |
||
13 | |||
14 | use FFMpeg\Coordinate\Dimension; |
||
15 | use FFMpeg\Exception\InvalidArgumentException; |
||
16 | use FFMpeg\Media\Video; |
||
17 | use FFMpeg\Format\VideoInterface; |
||
18 | |||
19 | class RotateFilter implements VideoFilterInterface |
||
20 | { |
||
21 | const ROTATE_90 = 'transpose=1'; |
||
22 | const ROTATE_180 = 'hflip,vflip'; |
||
23 | const ROTATE_270 = 'transpose=2'; |
||
24 | |||
25 | /** @var string */ |
||
26 | private $angle; |
||
27 | /** @var integer */ |
||
28 | private $priority; |
||
29 | |||
30 | public function __construct($angle, $priority = 0) |
||
31 | { |
||
32 | $this->setAngle($angle); |
||
33 | $this->priority = (int) $priority; |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | public function getPriority() |
||
40 | { |
||
41 | return $this->priority; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @return Dimension |
||
46 | */ |
||
47 | public function getAngle() |
||
48 | { |
||
49 | return $this->angle; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | public function apply(Video $video, VideoInterface $format) |
||
56 | { |
||
57 | if (in_array($this->angle, array(self::ROTATE_90, self::ROTATE_270), true)) { |
||
58 | foreach ($video->getStreams()->videos() as $stream) { |
||
59 | if ($stream->has('width') && $stream->has('height')) { |
||
60 | $width = $stream->get('width'); |
||
61 | $stream->set('width', $stream->get('height')); |
||
62 | $stream->set('height', $width); |
||
63 | } |
||
64 | } |
||
65 | } |
||
66 | |||
67 | return array('-vf', $this->angle, '-metadata:s:v:0', 'rotate=0'); |
||
68 | } |
||
69 | |||
70 | private function setAngle($angle) |
||
71 | { |
||
72 | switch ($angle) { |
||
73 | case self::ROTATE_90: |
||
74 | case self::ROTATE_180: |
||
75 | case self::ROTATE_270: |
||
76 | $this->angle = $angle; |
||
77 | break; |
||
78 | default: |
||
79 | throw new InvalidArgumentException('Invalid angle value.'); |
||
80 | } |
||
81 | } |
||
82 | } |