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 StreamingAnalytics |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var Export |
20
|
|
|
*/ |
21
|
|
|
private $export; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* StreamingAnalytics constructor. |
25
|
|
|
* @param Export $export |
26
|
|
|
*/ |
27
|
|
|
public function __construct(Export $export) |
28
|
|
|
{ |
29
|
|
|
$this->export = $export; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
|
|
public function __toString() |
36
|
|
|
{ |
37
|
|
|
return json_encode($this->analyse()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return mixed |
42
|
|
|
*/ |
43
|
|
|
public function analyse() |
44
|
|
|
{ |
45
|
|
|
$metadata["original"] = $this->getOriginalMetadata(); |
|
|
|
|
46
|
|
|
$metadata["streams"] = $this->getStreamsMetadata(); |
47
|
|
|
$metadata["general"] = $this->getGeneralMetadata(); |
48
|
|
|
|
49
|
|
|
$filename = $this->export->getPathInfo()["dirname"] . DIRECTORY_SEPARATOR . "analyse.json"; |
50
|
|
|
file_put_contents($filename, json_encode($metadata)); |
51
|
|
|
|
52
|
|
|
return $metadata; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return mixed |
57
|
|
|
*/ |
58
|
|
|
private function getOriginalMetadata() |
59
|
|
|
{ |
60
|
|
|
$streams = $this->export |
61
|
|
|
->getMedia() |
62
|
|
|
->getAllStreams(); |
63
|
|
|
|
64
|
|
|
foreach ($streams as $key => $stream){ |
65
|
|
|
$streams[$key] = $stream->all(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $streams; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return mixed |
73
|
|
|
*/ |
74
|
|
|
private function getStreamsMetadata() |
75
|
|
|
{ |
76
|
|
|
$metadata["qualities"] = $this->getQualities(); |
|
|
|
|
77
|
|
|
|
78
|
|
|
$format_class = explode("\\" ,get_class($this->export->getFormat())); |
79
|
|
|
$metadata["format"] = end($format_class); |
80
|
|
|
|
81
|
|
|
$export_class = explode("\\" ,get_class($this->export)); |
82
|
|
|
$metadata["streaming_technique"] = end($export_class); |
83
|
|
|
|
84
|
|
|
if ($this->export instanceof DASH) { |
85
|
|
|
$metadata["dash_adaption"] = $this->export->getAdaption(); |
86
|
|
|
} elseif ($this->export instanceof HLS) { |
87
|
|
|
$metadata["hls_time"] = $this->export->getHlsTime(); |
88
|
|
|
$metadata["hls_cache"] = $this->export->isHlsAllowCache(); |
89
|
|
|
$metadata["encrypted_hls"] = ($this->export->getHlsKeyInfoFile() !== "") ? true : false; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return $metadata; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
private function getQualities() |
96
|
|
|
{ |
97
|
|
|
$qualities = []; |
98
|
|
|
foreach ($this->export->getRepresentations() as $key => $representation) { |
|
|
|
|
99
|
|
|
if ($representation instanceof Representation) { |
100
|
|
|
$qualities[$key]["dimensions"] = strtoupper($representation->getResize()); |
101
|
|
|
$qualities[$key]["kilobitrate"] = $representation->getKiloBitrate(); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
return $qualities; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
private function getGeneralMetadata() |
109
|
|
|
{ |
110
|
|
|
$video_path = $this->export->getMedia()->getPath(); |
111
|
|
|
$metadata["path_to_video"] = $video_path; |
|
|
|
|
112
|
|
|
$metadata["dir_path_to_video"] = pathinfo($video_path)["dirname"]; |
113
|
|
|
$metadata["basename_of_video"] = pathinfo($video_path)["basename"]; |
114
|
|
|
$metadata["extension_of_video"] = pathinfo($video_path)["extension"]; |
115
|
|
|
$metadata["mime_content_type_of_video"] = !is_file($video_path)?:mime_content_type($video_path); |
116
|
|
|
$metadata["size_of_video"] = !is_file($video_path)?:filesize($video_path); |
117
|
|
|
|
118
|
|
|
$stream_path = $this->export->getPathInfo(); |
119
|
|
|
$metadata["dir_path_to_stream"] = $stream_path["dirname"]; |
120
|
|
|
$metadata["path_to_stream"] = $stream_path["dirname"] . DIRECTORY_SEPARATOR . $stream_path["basename"]; |
121
|
|
|
$metadata["size_of_stream_dir"] = Helper::directorySize($stream_path["dirname"]); |
122
|
|
|
$metadata["datetime"] = date("Y-m-d H:i:s"); |
123
|
|
|
$metadata["time"] = time(); |
124
|
|
|
|
125
|
|
|
return $metadata; |
126
|
|
|
} |
127
|
|
|
} |