scratch – Blame information for rev

Subversion Repositories:
Rev:
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\Audio;
13  
14 use Evenement\EventEmitter;
15 use FFMpeg\Exception\InvalidArgumentException;
16 use FFMpeg\Format\AudioInterface;
17 use FFMpeg\Media\MediaTypeInterface;
18 use FFMpeg\Format\ProgressableInterface;
19 use FFMpeg\Format\ProgressListener\AudioProgressListener;
20 use FFMpeg\FFProbe;
21  
22 abstract class DefaultAudio extends EventEmitter implements AudioInterface, ProgressableInterface
23 {
24 /** @var string */
25 protected $audioCodec;
26  
27 /** @var integer */
28 protected $audioKiloBitrate = 128;
29  
30 /** @var integer */
31 protected $audioChannels = null;
32  
33 /**
34 * {@inheritdoc}
35 */
36 public function getExtraParams()
37 {
38 return array();
39 }
40  
41 /**
42 * {@inheritdoc}
43 */
44 public function getAudioCodec()
45 {
46 return $this->audioCodec;
47 }
48  
49 /**
50 * Sets the audio codec, Should be in the available ones, otherwise an
51 * exception is thrown.
52 *
53 * @param string $audioCodec
54 *
55 * @throws InvalidArgumentException
56 */
57 public function setAudioCodec($audioCodec)
58 {
59 if ( ! in_array($audioCodec, $this->getAvailableAudioCodecs())) {
60 throw new InvalidArgumentException(sprintf(
61 'Wrong audiocodec value for %s, available formats are %s'
62 , $audioCodec, implode(', ', $this->getAvailableAudioCodecs())
63 ));
64 }
65  
66 $this->audioCodec = $audioCodec;
67  
68 return $this;
69 }
70  
71 /**
72 * {@inheritdoc}
73 */
74 public function getAudioKiloBitrate()
75 {
76 return $this->audioKiloBitrate;
77 }
78  
79 /**
80 * Sets the kiloBitrate value.
81 *
82 * @param integer $kiloBitrate
83 * @throws InvalidArgumentException
84 */
85 public function setAudioKiloBitrate($kiloBitrate)
86 {
87 if ($kiloBitrate < 1) {
88 throw new InvalidArgumentException('Wrong kiloBitrate value');
89 }
90  
91 $this->audioKiloBitrate = (int) $kiloBitrate;
92  
93 return $this;
94 }
95  
96 /**
97 * {@inheritdoc}
98 */
99 public function getAudioChannels()
100 {
101 return $this->audioChannels;
102 }
103  
104 /**
105 * Sets the channels value.
106 *
107 * @param integer $channels
108 * @throws InvalidArgumentException
109 */
110 public function setAudioChannels($channels)
111 {
112 if ($channels < 1) {
113 throw new InvalidArgumentException('Wrong channels value');
114 }
115  
116 $this->audioChannels = (int) $channels;
117  
118 return $this;
119 }
120  
121 /**
122 * {@inheritdoc}
123 */
124 public function createProgressListener(MediaTypeInterface $media, FFProbe $ffprobe, $pass, $total)
125 {
126 $format = $this;
127 $listener = new AudioProgressListener($ffprobe, $media->getPathfile(), $pass, $total);
128 $listener->on('progress', function () use ($media, $format) {
129 $format->emit('progress', array_merge(array($media, $format), func_get_args()));
130 });
131  
132 return array($listener);
133 }
134  
135 /**
136 * {@inheritDoc}
137 */
138 public function getPasses()
139 {
140 return 1;
141 }
142 }