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
|
|
|
|
13
|
|
|
namespace Streaming; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
class Metadata |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var Export |
20
|
|
|
*/ |
21
|
|
|
private $export; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Metadata constructor. |
25
|
|
|
* @param Export $export |
26
|
|
|
*/ |
27
|
|
|
public function __construct(Export $export) |
28
|
|
|
{ |
29
|
|
|
$this->export = $export; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return mixed |
34
|
|
|
*/ |
35
|
|
|
public function extract() |
36
|
|
|
{ |
37
|
|
|
$metadata["video"] = $this->getVideoMetadata(); |
|
|
|
|
38
|
|
|
$metadata["streams"] = $this->getStreamsMetadata(); |
39
|
|
|
|
40
|
|
|
$filename = $this->export->getPathInfo()["dirname"] . DIRECTORY_SEPARATOR . "_" . Helper::randomString(20) . "_metadata.json"; |
41
|
|
|
file_put_contents($filename, json_encode($metadata, JSON_PRETTY_PRINT)); |
42
|
|
|
|
43
|
|
|
return [ |
44
|
|
|
'filename' => $filename, |
45
|
|
|
'metadata' => $metadata |
46
|
|
|
]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return mixed |
51
|
|
|
*/ |
52
|
|
|
private function getVideoMetadata() |
53
|
|
|
{ |
54
|
|
|
$probe = $this->export->getMedia()->probe(); |
55
|
|
|
$streams = $probe['streams']->all(); |
56
|
|
|
$format = $probe['format']->all(); |
57
|
|
|
|
58
|
|
|
foreach ($streams as $key => $stream) { |
59
|
|
|
$streams[$key] = $stream->all(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return [ |
63
|
|
|
'format' => $format, |
64
|
|
|
'streams' => $streams |
65
|
|
|
]; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return mixed |
70
|
|
|
*/ |
71
|
|
|
private function getStreamsMetadata() |
72
|
|
|
{ |
73
|
|
|
$stream_path = $this->export->getPathInfo(); |
74
|
|
|
$metadata["filename"] = $stream_path["dirname"] . DIRECTORY_SEPARATOR . $stream_path["basename"]; |
|
|
|
|
75
|
|
|
$metadata["size_of_stream_dir"] = FileManager::directorySize($stream_path["dirname"]); |
76
|
|
|
$metadata["created_at"] = date("Y-m-d H:i:s"); |
77
|
|
|
|
78
|
|
|
$metadata["qualities"] = $this->getQualities(); |
79
|
|
|
|
80
|
|
|
$format_class = explode("\\", get_class($this->export->getFormat())); |
81
|
|
|
$metadata["format"] = end($format_class); |
82
|
|
|
|
83
|
|
|
$export_class = explode("\\", get_class($this->export)); |
84
|
|
|
$metadata["streaming_technique"] = end($export_class); |
85
|
|
|
|
86
|
|
|
if ($this->export instanceof DASH) { |
87
|
|
|
$metadata["dash_adaption"] = $this->export->getAdaption(); |
88
|
|
|
} elseif ($this->export instanceof HLS) { |
89
|
|
|
$metadata["hls_time"] = $this->export->getHlsTime(); |
90
|
|
|
$metadata["hls_cache"] = $this->export->isHlsAllowCache(); |
91
|
|
|
$metadata["encrypted_hls"] = (bool)$this->export->getHlsKeyInfoFile(); |
92
|
|
|
$metadata["ts_sub_directory"] = $this->export->getTsSubDirectory(); |
93
|
|
|
$metadata["base_url"] = $this->export->getHlsBaseUrl(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return $metadata; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return array |
101
|
|
|
*/ |
102
|
|
|
private function getQualities() |
103
|
|
|
{ |
104
|
|
|
$qualities = []; |
105
|
|
|
foreach ($this->export->getRepresentations() as $key => $representation) { |
|
|
|
|
106
|
|
|
if ($representation instanceof Representation) { |
107
|
|
|
$qualities[$key]["dimensions"] = strtoupper($representation->getResize()); |
108
|
|
|
$qualities[$key]["video_bitrate"] = $representation->getKiloBitrate() * 1024; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return $qualities; |
113
|
|
|
} |
114
|
|
|
} |