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 AudioStream implements AudioStreamInterface |
11
|
|
|
{ |
12
|
|
|
/** @var array<string, mixed> */ |
13
|
|
|
private $streamMetadata; |
14
|
|
|
|
15
|
|
|
/** @var MetadataTypeSafeReader */ |
16
|
|
|
private $tsReader; |
17
|
|
|
|
18
|
3 |
|
public function __construct(array $streamMetadata, ?LoggerInterface $logger = null) |
19
|
|
|
{ |
20
|
3 |
|
$this->streamMetadata = $streamMetadata; |
21
|
3 |
|
$this->tsReader = new MetadataTypeSafeReader($streamMetadata, $logger); |
22
|
3 |
|
} |
23
|
|
|
|
24
|
1 |
|
public function getIndex(): int |
25
|
|
|
{ |
26
|
1 |
|
return $this->tsReader->getKeyIntValue('index'); |
27
|
|
|
} |
28
|
|
|
|
29
|
1 |
|
public function getCodecType(): string |
30
|
|
|
{ |
31
|
1 |
|
return $this->tsReader->getKeyStringValue('codec_type'); |
32
|
|
|
} |
33
|
|
|
|
34
|
1 |
|
public function getCodecName(): string |
35
|
|
|
{ |
36
|
1 |
|
return $this->tsReader->getKeyStringValue('codec_name'); |
37
|
|
|
} |
38
|
|
|
|
39
|
1 |
|
public function getCodecLongName(): ?string |
40
|
|
|
{ |
41
|
1 |
|
return $this->tsReader->getKeyStringOrNullValue('codec_long_name'); |
42
|
|
|
} |
43
|
|
|
|
44
|
1 |
|
public function getCodecTimeBase(): ?string |
45
|
|
|
{ |
46
|
1 |
|
return $this->tsReader->getKeyStringOrNullValue('codec_time_base'); |
47
|
|
|
} |
48
|
|
|
|
49
|
1 |
|
public function getCodecTagString(): ?string |
50
|
|
|
{ |
51
|
1 |
|
return $this->tsReader->getKeyStringOrNullValue('codec_tag_string'); |
52
|
|
|
} |
53
|
|
|
|
54
|
1 |
|
public function getStartTime(): ?float |
55
|
|
|
{ |
56
|
1 |
|
return $this->tsReader->getKeyFloatOrNullValue('start_time'); |
57
|
|
|
} |
58
|
|
|
|
59
|
1 |
|
public function getTimeBase(): ?string |
60
|
|
|
{ |
61
|
1 |
|
return $this->tsReader->getKeyStringOrNullValue('time_base'); |
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
public function getDurationTs(): ?int |
65
|
|
|
{ |
66
|
1 |
|
return $this->tsReader->getKeyIntOrNullValue('duration_ts'); |
67
|
|
|
} |
68
|
|
|
|
69
|
1 |
|
public function getDuration(): float |
70
|
|
|
{ |
71
|
1 |
|
return $this->tsReader->getKeyFloatValue('duration'); |
72
|
|
|
} |
73
|
|
|
|
74
|
1 |
|
public function getProfile(): ?string |
75
|
|
|
{ |
76
|
1 |
|
return $this->tsReader->getKeyStringOrNullValue('profile'); |
77
|
|
|
} |
78
|
|
|
|
79
|
1 |
|
public function getBitRate(): ?int |
80
|
|
|
{ |
81
|
1 |
|
return $this->tsReader->getKeyIntOrNullValue('bit_rate'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return array<string, string> |
86
|
|
|
*/ |
87
|
1 |
|
public function getTags(): array |
88
|
|
|
{ |
89
|
1 |
|
return $this->streamMetadata['tags'] ?? []; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Return underlying ffprobe json metadata. |
94
|
|
|
* |
95
|
|
|
* @return array<string, mixed> |
96
|
|
|
*/ |
97
|
1 |
|
public function getStreamMetadata(): array |
98
|
|
|
{ |
99
|
1 |
|
return $this->streamMetadata; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|