1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the PHP-FFmpeg-video-streaming package. |
5
|
|
|
* |
6
|
|
|
* (c) Amin Yazdanpanah <[email protected]> |
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 Streaming; |
13
|
|
|
|
14
|
|
|
use FFMpeg\Media\MediaTypeInterface; |
15
|
|
|
use Streaming\MediaInfo\MediaInfo; |
16
|
|
|
use Streaming\MediaInfo\Streams\StreamCollection; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @method mixed save(\FFMpeg\Format\FormatInterface $format, $outputPathfile) |
20
|
|
|
* @method mixed addFilter(\FFMpeg\Filters\FilterInterface $filter) |
21
|
|
|
* @method mixed getStreams() |
22
|
|
|
*/ |
23
|
|
|
class Media |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
protected $media; |
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private $path; |
31
|
|
|
/** |
32
|
|
|
* @var bool |
33
|
|
|
*/ |
34
|
|
|
private $is_tmp; |
35
|
|
|
|
36
|
|
|
/** @var string */ |
37
|
|
|
private $mediaInfoBinary = 'mediainfo'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Media constructor. |
41
|
|
|
* @param MediaTypeInterface $media |
42
|
|
|
* @param string $path |
43
|
|
|
* @param bool $is_tmp |
44
|
|
|
*/ |
45
|
|
|
public function __construct(MediaTypeInterface $media, string $path, bool $is_tmp) |
46
|
|
|
{ |
47
|
|
|
$this->media = $media; |
48
|
|
|
$this->path = $path; |
49
|
|
|
$this->is_tmp = $is_tmp; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return DASH |
54
|
|
|
*/ |
55
|
|
|
public function DASH(): DASH |
56
|
|
|
{ |
57
|
|
|
return new DASH($this); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return HLS |
62
|
|
|
*/ |
63
|
|
|
public function HLS(): HLS |
64
|
|
|
{ |
65
|
|
|
return new HLS($this); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return StreamCollection |
70
|
|
|
*/ |
71
|
|
|
public function mediaInfo(): StreamCollection |
72
|
|
|
{ |
73
|
|
|
return MediaInfo::initialize($this->getPath(), $this->mediaInfoBinary); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param $argument |
78
|
|
|
* @return Media |
79
|
|
|
*/ |
80
|
|
|
protected function isInstanceofArgument($argument) |
81
|
|
|
{ |
82
|
|
|
return ($argument instanceof $this->media) ? $this : $argument; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param $method |
87
|
|
|
* @param $parameters |
88
|
|
|
* @return Media |
89
|
|
|
*/ |
90
|
|
|
public function __call($method, $parameters) |
91
|
|
|
{ |
92
|
|
|
return $this->isInstanceofArgument( |
93
|
|
|
call_user_func_array([$this->media, $method], $parameters) |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
|
public function getPath(): string |
101
|
|
|
{ |
102
|
|
|
return $this->path; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return bool |
107
|
|
|
*/ |
108
|
|
|
public function isTmp(): bool |
109
|
|
|
{ |
110
|
|
|
return $this->is_tmp; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param string $mediaInfoBinary |
115
|
|
|
* @return Media |
116
|
|
|
*/ |
117
|
|
|
public function setMediaInfoBinary(string $mediaInfoBinary) |
118
|
|
|
{ |
119
|
|
|
$this->mediaInfoBinary = $mediaInfoBinary; |
120
|
|
|
return $this; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|