1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2019 Amin Yazdanpanah<http://www.aminyazdanpanah.com>. |
5
|
|
|
* |
6
|
|
|
* Licensed under the MIT License; |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* https://opensource.org/licenses/MIT |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace AYazdanpanah\FFMpegStreaming; |
20
|
|
|
|
21
|
|
|
use FFMpeg\FFProbe\DataMapping\Stream; |
22
|
|
|
use FFMpeg\Media\MediaTypeInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @method mixed save(\FFMpeg\Format\FormatInterface $format, $outputPathfile) |
26
|
|
|
* @method mixed addFilter(\FFMpeg\Filters\FilterInterface $filter) |
27
|
|
|
* @method mixed getStreams() |
28
|
|
|
*/ |
29
|
|
|
class Media |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
protected $media; |
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
private $path; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Media constructor. |
40
|
|
|
* @param MediaTypeInterface $media |
41
|
|
|
* @param string $path |
42
|
|
|
*/ |
43
|
|
|
public function __construct(MediaTypeInterface $media, string $path) |
44
|
|
|
{ |
45
|
|
|
$this->media = $media; |
46
|
|
|
$this->path = $path; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return DASH |
51
|
|
|
*/ |
52
|
|
|
public function DASH(): DASH |
53
|
|
|
{ |
54
|
|
|
return new DASH($this); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return HLS |
59
|
|
|
*/ |
60
|
|
|
public function HLS(): HLS |
61
|
|
|
{ |
62
|
|
|
return new HLS($this); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param $argument |
67
|
|
|
* @return Media |
68
|
|
|
*/ |
69
|
|
|
protected function isInstanceofArgument($argument) |
70
|
|
|
{ |
71
|
|
|
return ($argument instanceof $this->media) ? $this : $argument; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param $method |
76
|
|
|
* @param $parameters |
77
|
|
|
* @return Media |
78
|
|
|
*/ |
79
|
|
|
public function __call($method, $parameters) |
80
|
|
|
{ |
81
|
|
|
return $this->isInstanceofArgument( |
82
|
|
|
call_user_func_array([$this->media, $method], $parameters) |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return mixed |
88
|
|
|
*/ |
89
|
|
|
public function getFirstStream(): Stream |
90
|
|
|
{ |
91
|
|
|
return $this->media->getStreams()->first(); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return array |
96
|
|
|
*/ |
97
|
|
|
public function getPathInfo(): array |
98
|
|
|
{ |
99
|
|
|
return pathinfo($this->path); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|