1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ProtoneMedia\LaravelFFMpeg\FFMpeg; |
4
|
|
|
|
5
|
|
|
use FFMpeg\FFProbe; |
|
|
|
|
6
|
|
|
use FFMpeg\Format\AudioInterface; |
7
|
|
|
use FFMpeg\Format\ProgressableInterface; |
8
|
|
|
use FFMpeg\Format\VideoInterface; |
9
|
|
|
use FFMpeg\Media\MediaTypeInterface; |
10
|
|
|
use Illuminate\Support\Traits\ForwardsCalls; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Use this decorator to get access to the AbstractProgressListeners0 |
14
|
|
|
* with the `getListeners` method. |
15
|
|
|
*/ |
16
|
|
|
class ProgressListenerDecorator implements ProgressableInterface, AudioInterface |
17
|
|
|
{ |
18
|
|
|
use ForwardsCalls; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var \FFMpeg\Format\AudioInterface|\FFMpeg\Format\VideoInterface |
22
|
|
|
*/ |
23
|
|
|
protected $format; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
protected $listeners = []; |
29
|
|
|
|
30
|
|
|
public function __construct($format) |
31
|
|
|
{ |
32
|
|
|
$this->format = $format; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public static function decorate($format) |
36
|
|
|
{ |
37
|
|
|
if ($format instanceof VideoInterface) { |
38
|
|
|
return new VideoProgressListenerDecorator($format); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return new static($format); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getListeners(): array |
45
|
|
|
{ |
46
|
|
|
return $this->listeners; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function createProgressListener(MediaTypeInterface $media, FFProbe $ffprobe, $pass, $total, $duration = 0) |
50
|
|
|
{ |
51
|
|
|
return tap($this->format->createProgressListener(...func_get_args()), function (array $listeners) { |
|
|
|
|
52
|
|
|
$this->listeners = array_merge($this->listeners, $listeners); |
53
|
|
|
}); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function on($event, callable $listener) |
57
|
|
|
{ |
58
|
|
|
return $this->format->on(...func_get_args()); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function once($event, callable $listener) |
62
|
|
|
{ |
63
|
|
|
return $this->format->once(...func_get_args()); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function removeListener($event, callable $listener) |
67
|
|
|
{ |
68
|
|
|
return $this->format->removeListener(...func_get_args()); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function removeAllListeners($event = null) |
72
|
|
|
{ |
73
|
|
|
return $this->format->removeAllListeners(...func_get_args()); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function listeners($event = null) |
77
|
|
|
{ |
78
|
|
|
return $this->format->listeners(...func_get_args()); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function emit($event, array $arguments = []) |
82
|
|
|
{ |
83
|
|
|
return $this->format->emit(...func_get_args()); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function getPasses() |
87
|
|
|
{ |
88
|
|
|
return $this->format->getPasses(...func_get_args()); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function getExtraParams() |
92
|
|
|
{ |
93
|
|
|
return $this->format->getExtraParams(...func_get_args()); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function getAudioKiloBitrate() |
97
|
|
|
{ |
98
|
|
|
return $this->format->getAudioKiloBitrate(...func_get_args()); |
|
|
|
|
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function getAudioChannels() |
102
|
|
|
{ |
103
|
|
|
return $this->format->getAudioChannels(...func_get_args()); |
|
|
|
|
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function getAudioCodec() |
107
|
|
|
{ |
108
|
|
|
return $this->format->getAudioCodec(...func_get_args()); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function getAvailableAudioCodecs() |
112
|
|
|
{ |
113
|
|
|
return $this->format->getAvailableAudioCodecs(...func_get_args()); |
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function __get($key) |
117
|
|
|
{ |
118
|
|
|
return $this->format->{$key}; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function __call($method, $arguments) |
122
|
|
|
{ |
123
|
|
|
return $this->forwardCallTo($this->format, $method, $arguments); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: