|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Soluble\MediaTools\Video\Info; |
|
6
|
|
|
|
|
7
|
|
|
use Psr\Log\LoggerInterface; |
|
8
|
|
|
use Soluble\MediaTools\Video\Info\Util\MetadataTypeSafeReader; |
|
9
|
|
|
|
|
10
|
|
|
class VideoStream implements VideoStreamInterface |
|
11
|
|
|
{ |
|
12
|
|
|
/** @var array<string, mixed> */ |
|
13
|
|
|
private $streamMetadata; |
|
14
|
|
|
|
|
15
|
|
|
/** @var MetadataTypeSafeReader */ |
|
16
|
|
|
private $tsReader; |
|
17
|
|
|
|
|
18
|
8 |
|
public function __construct(array $streamMetadata, ?LoggerInterface $logger = null) |
|
19
|
|
|
{ |
|
20
|
8 |
|
$this->streamMetadata = $streamMetadata; |
|
21
|
8 |
|
$this->tsReader = new MetadataTypeSafeReader($streamMetadata, $logger); |
|
22
|
8 |
|
} |
|
23
|
|
|
|
|
24
|
2 |
|
public function getIndex(): int |
|
25
|
|
|
{ |
|
26
|
2 |
|
return $this->tsReader->getKeyIntValue('index'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
1 |
|
public function getCodecName(): string |
|
30
|
|
|
{ |
|
31
|
1 |
|
return $this->streamMetadata['codec_name']; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
1 |
|
public function getCodecLongName(): ?string |
|
35
|
|
|
{ |
|
36
|
1 |
|
return $this->tsReader->getKeyStringOrNullValue('codec_long_name'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
1 |
|
public function getCodecTimeBase(): ?string |
|
40
|
|
|
{ |
|
41
|
1 |
|
return $this->tsReader->getKeyStringOrNullValue('codec_time_base'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
1 |
|
public function getCodecTagString(): ?string |
|
45
|
|
|
{ |
|
46
|
1 |
|
return $this->tsReader->getKeyStringOrNullValue('codec_tag_string'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
3 |
|
public function getWidth(): int |
|
50
|
|
|
{ |
|
51
|
3 |
|
return $this->tsReader->getKeyIntValue('width'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
3 |
|
public function getHeight(): int |
|
55
|
|
|
{ |
|
56
|
3 |
|
return $this->tsReader->getKeyIntValue('height'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
1 |
|
public function getCodedWidth(): ?int |
|
60
|
|
|
{ |
|
61
|
1 |
|
return $this->tsReader->getKeyIntOrNullValue('coded_width'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
1 |
|
public function getCodedHeight(): ?int |
|
65
|
|
|
{ |
|
66
|
1 |
|
return $this->tsReader->getKeyIntOrNullValue('coded_height'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
1 |
|
public function getSampleAspectRatio(): ?string |
|
70
|
|
|
{ |
|
71
|
1 |
|
return $this->tsReader->getKeyStringOrNullValue('sample_aspect_ratio'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
1 |
|
public function getDisplayAspectRatio(): string |
|
75
|
|
|
{ |
|
76
|
1 |
|
return $this->streamMetadata['display_aspect_ratio']; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
3 |
|
public function getPixFmt(): ?string |
|
80
|
|
|
{ |
|
81
|
3 |
|
return $this->tsReader->getKeyStringOrNullValue('pix_fmt'); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
1 |
|
public function getAvgFrameRate(): string |
|
85
|
|
|
{ |
|
86
|
1 |
|
return $this->streamMetadata['avg_frame_rate']; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
1 |
|
public function getRFrameRate(): ?string |
|
90
|
|
|
{ |
|
91
|
1 |
|
return $this->tsReader->getKeyStringOrNullValue('r_frame_rate'); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
1 |
|
public function getTimeBase(): ?string |
|
95
|
|
|
{ |
|
96
|
1 |
|
return $this->tsReader->getKeyStringOrNullValue('time_base'); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
1 |
|
public function getDurationTs(): ?int |
|
100
|
|
|
{ |
|
101
|
1 |
|
return $this->tsReader->getKeyIntOrNullValue('duration_ts'); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
1 |
|
public function getDuration(): float |
|
105
|
|
|
{ |
|
106
|
1 |
|
return $this->tsReader->getKeyFloatValue('duration'); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function getProfile(): ?string |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->tsReader->getKeyStringOrNullValue('profile'); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
3 |
|
public function getBitRate(): ?int |
|
115
|
|
|
{ |
|
116
|
3 |
|
return $this->tsReader->getKeyIntOrNullValue('bit_rate'); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
1 |
|
public function getNbFrames(): int |
|
120
|
|
|
{ |
|
121
|
1 |
|
return $this->tsReader->getKeyIntValue('nb_frames'); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
2 |
|
public function isAvc(): ?bool |
|
125
|
|
|
{ |
|
126
|
2 |
|
if (!isset($this->streamMetadata['is_avc'])) { |
|
127
|
1 |
|
return null; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
1 |
|
return $this->streamMetadata['is_avc'] === 'true'; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
1 |
|
public function getLevel(): ?int |
|
134
|
|
|
{ |
|
135
|
1 |
|
return $this->tsReader->getKeyIntOrNullValue('level'); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
1 |
|
public function getColorRange(): ?string |
|
139
|
|
|
{ |
|
140
|
1 |
|
return $this->tsReader->getKeyStringOrNullValue('color_range'); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
1 |
|
public function getColorSpace(): ?string |
|
144
|
|
|
{ |
|
145
|
1 |
|
return $this->tsReader->getKeyStringOrNullValue('color_space'); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
1 |
|
public function getColorTransfer(): ?string |
|
149
|
|
|
{ |
|
150
|
1 |
|
return $this->tsReader->getKeyStringOrNullValue('color_transfer'); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @return array<string, string> |
|
155
|
|
|
*/ |
|
156
|
1 |
|
public function getTags(): array |
|
157
|
|
|
{ |
|
158
|
1 |
|
return $this->streamMetadata['tags'] ?? []; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* Return underlying ffprobe json metadata. |
|
163
|
|
|
* |
|
164
|
|
|
* @return array<string, mixed> |
|
165
|
|
|
*/ |
|
166
|
1 |
|
public function getStreamMetadata(): array |
|
167
|
|
|
{ |
|
168
|
1 |
|
return $this->streamMetadata; |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|