Passed
Push — master ( b38e7e...085481 )
by Sébastien
03:00
created

VideoStream::getSampleAspectRatio()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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