Failed Conditions
Push — master ( 34f957...606500 )
by Sébastien
02:10
created

VideoStream::getDimensions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
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 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
    /**
19
     * @param array<string, mixed> $streamMetadata
20
     */
21 9
    public function __construct(array $streamMetadata, ?LoggerInterface $logger = null)
22
    {
23 9
        $this->streamMetadata = $streamMetadata;
24 9
        $this->tsReader       = new MetadataTypeSafeReader($streamMetadata, $logger);
25 9
    }
26
27 2
    public function getIndex(): int
28
    {
29 2
        return $this->tsReader->getKeyIntValue('index');
30
    }
31
32 1
    public function getCodecType(): string
33
    {
34 1
        return $this->tsReader->getKeyStringValue('codec_type');
35
    }
36
37 1
    public function getCodecName(): string
38
    {
39 1
        return $this->tsReader->getKeyStringValue('codec_name');
40
    }
41
42 1
    public function getCodecLongName(): ?string
43
    {
44 1
        return $this->tsReader->getKeyStringOrNullValue('codec_long_name');
45
    }
46
47 1
    public function getCodecTimeBase(): ?string
48
    {
49 1
        return $this->tsReader->getKeyStringOrNullValue('codec_time_base');
50
    }
51
52 1
    public function getCodecTagString(): ?string
53
    {
54 1
        return $this->tsReader->getKeyStringOrNullValue('codec_tag_string');
55
    }
56
57 4
    public function getWidth(): int
58
    {
59 4
        return $this->tsReader->getKeyIntValue('width');
60
    }
61
62 4
    public function getHeight(): int
63
    {
64 4
        return $this->tsReader->getKeyIntValue('height');
65
    }
66
67 1
    public function getCodedWidth(): ?int
68
    {
69 1
        return $this->tsReader->getKeyIntOrNullValue('coded_width');
70
    }
71
72 1
    public function getCodedHeight(): ?int
73
    {
74 1
        return $this->tsReader->getKeyIntOrNullValue('coded_height');
75
    }
76
77 1
    public function getSampleAspectRatio(): ?string
78
    {
79 1
        return $this->tsReader->getKeyStringOrNullValue('sample_aspect_ratio');
80
    }
81
82 1
    public function getDisplayAspectRatio(): ?string
83
    {
84 1
        return $this->tsReader->getKeyStringOrNullValue('display_aspect_ratio');
85
    }
86
87 3
    public function getPixFmt(): ?string
88
    {
89 3
        return $this->tsReader->getKeyStringOrNullValue('pix_fmt');
90
    }
91
92 1
    public function getAvgFrameRate(): ?string
93
    {
94 1
        return $this->tsReader->getKeyStringOrNullValue('avg_frame_rate');
95
    }
96
97 1
    public function getRFrameRate(): ?string
98
    {
99 1
        return $this->tsReader->getKeyStringOrNullValue('r_frame_rate');
100
    }
101
102 1
    public function getTimeBase(): ?string
103
    {
104 1
        return $this->tsReader->getKeyStringOrNullValue('time_base');
105
    }
106
107 1
    public function getDurationTs(): ?int
108
    {
109 1
        return $this->tsReader->getKeyIntOrNullValue('duration_ts');
110
    }
111
112 1
    public function getDuration(): float
113
    {
114 1
        return $this->tsReader->getKeyFloatValue('duration');
115
    }
116
117 1
    public function getProfile(): ?string
118
    {
119 1
        return $this->tsReader->getKeyStringOrNullValue('profile');
120
    }
121
122 3
    public function getBitRate(): ?int
123
    {
124 3
        return $this->tsReader->getKeyIntOrNullValue('bit_rate');
125
    }
126
127 2
    public function getNbFrames(): ?int
128
    {
129 2
        return $this->tsReader->getKeyIntOrNullValue('nb_frames');
130
    }
131
132 2
    public function isAvc(): ?bool
133
    {
134 2
        if (!isset($this->streamMetadata['is_avc'])) {
135 2
            return null;
136
        }
137
138 1
        return $this->streamMetadata['is_avc'] === 'true';
139
    }
140
141 1
    public function getLevel(): ?int
142
    {
143 1
        return $this->tsReader->getKeyIntOrNullValue('level');
144
    }
145
146 1
    public function getStartTime(): ?float
147
    {
148 1
        return $this->tsReader->getKeyFloatOrNullValue('start_time');
149
    }
150
151 1
    public function getColorRange(): ?string
152
    {
153 1
        return $this->tsReader->getKeyStringOrNullValue('color_range');
154
    }
155
156 1
    public function getColorSpace(): ?string
157
    {
158 1
        return $this->tsReader->getKeyStringOrNullValue('color_space');
159
    }
160
161 1
    public function getColorTransfer(): ?string
162
    {
163 1
        return $this->tsReader->getKeyStringOrNullValue('color_transfer');
164
    }
165
166 1
    public function getDimensions(): array
167
    {
168
        return [
169 1
            'width'  => $this->getWidth(),
170 1
            'height' => $this->getHeight()
171
        ];
172
    }
173
174
    /**
175
     * @return array<string, string>
176
     */
177 1
    public function getTags(): array
178
    {
179 1
        return $this->streamMetadata['tags'] ?? [];
180
    }
181
182
    /**
183
     * Return underlying ffprobe json metadata.
184
     *
185
     * @return array<string, mixed>
186
     */
187 1
    public function getStreamMetadata(): array
188
    {
189 1
        return $this->streamMetadata;
190
    }
191
}
192