scratch – Blame information for rev
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
115 | office | 1 | <?php |
2 | |||
3 | /* |
||
4 | * This file is part of PHP-FFmpeg. |
||
5 | * |
||
6 | * (c) Alchemy <info@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\Format\Video; |
||
13 | |||
14 | use FFMpeg\FFProbe; |
||
15 | use FFMpeg\Exception\InvalidArgumentException; |
||
16 | use FFMpeg\Format\Audio\DefaultAudio; |
||
17 | use FFMpeg\Format\VideoInterface; |
||
18 | use FFMpeg\Media\MediaTypeInterface; |
||
19 | use FFMpeg\Format\ProgressListener\VideoProgressListener; |
||
20 | |||
21 | /** |
||
22 | * The abstract default Video format |
||
23 | */ |
||
24 | abstract class DefaultVideo extends DefaultAudio implements VideoInterface |
||
25 | { |
||
26 | /** @var string */ |
||
27 | protected $videoCodec; |
||
28 | |||
29 | /** @var Integer */ |
||
30 | protected $kiloBitrate = 1000; |
||
31 | |||
32 | /** @var Integer */ |
||
33 | protected $modulus = 16; |
||
34 | |||
35 | /** @var Array */ |
||
36 | protected $additionalParamaters; |
||
37 | |||
38 | /** |
||
39 | * {@inheritdoc} |
||
40 | */ |
||
41 | public function getKiloBitrate() |
||
42 | { |
||
43 | return $this->kiloBitrate; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Sets the kiloBitrate value. |
||
48 | * |
||
49 | * @param integer $kiloBitrate |
||
50 | * @throws InvalidArgumentException |
||
51 | */ |
||
52 | public function setKiloBitrate($kiloBitrate) |
||
53 | { |
||
54 | if ($kiloBitrate < 1) { |
||
55 | throw new InvalidArgumentException('Wrong kiloBitrate value'); |
||
56 | } |
||
57 | |||
58 | $this->kiloBitrate = (int) $kiloBitrate; |
||
59 | |||
60 | return $this; |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | public function getVideoCodec() |
||
67 | { |
||
68 | return $this->videoCodec; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Sets the video codec, Should be in the available ones, otherwise an |
||
73 | * exception is thrown. |
||
74 | * |
||
75 | * @param string $videoCodec |
||
76 | * @throws InvalidArgumentException |
||
77 | */ |
||
78 | public function setVideoCodec($videoCodec) |
||
79 | { |
||
80 | if ( ! in_array($videoCodec, $this->getAvailableVideoCodecs())) { |
||
81 | throw new InvalidArgumentException(sprintf( |
||
82 | 'Wrong videocodec value for %s, available formats are %s' |
||
83 | , $videoCodec, implode(', ', $this->getAvailableVideoCodecs()) |
||
84 | )); |
||
85 | } |
||
86 | |||
87 | $this->videoCodec = $videoCodec; |
||
88 | |||
89 | return $this; |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @return integer |
||
94 | */ |
||
95 | public function getModulus() |
||
96 | { |
||
97 | return $this->modulus; |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | public function getAdditionalParameters() |
||
104 | { |
||
105 | return $this->additionalParamaters; |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * Sets additional parameters. |
||
110 | * |
||
111 | * @param array $additionalParamaters |
||
112 | * @throws InvalidArgumentException |
||
113 | */ |
||
114 | public function setAdditionalParameters($additionalParamaters) |
||
115 | { |
||
116 | if (!is_array($additionalParamaters)) { |
||
117 | throw new InvalidArgumentException('Wrong additionalParamaters value'); |
||
118 | } |
||
119 | |||
120 | $this->additionalParamaters = $additionalParamaters; |
||
121 | |||
122 | return $this; |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * {@inheritdoc} |
||
127 | */ |
||
128 | public function createProgressListener(MediaTypeInterface $media, FFProbe $ffprobe, $pass, $total) |
||
129 | { |
||
130 | $format = $this; |
||
131 | $listeners = array(new VideoProgressListener($ffprobe, $media->getPathfile(), $pass, $total)); |
||
132 | |||
133 | foreach ($listeners as $listener) { |
||
134 | $listener->on('progress', function () use ($format, $media) { |
||
135 | $format->emit('progress', array_merge(array($media, $format), func_get_args())); |
||
136 | }); |
||
137 | } |
||
138 | |||
139 | return $listeners; |
||
140 | } |
||
141 | } |