Skip to content

Commit abc685d

Browse files
committed
also filter bitrates (closes quasarstream#79)
1 parent 798cced commit abc685d

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/AutoReps.php

+19-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ private function getKiloBitRate(): int
9999

100100
/**
101101
* @param array|null $k_bitrate_values
102-
* @TODO: fix #79
103102
*/
104103
private function kiloBitrate(?array $k_bitrate_values): void
105104
{
@@ -139,13 +138,29 @@ private function sideFilter(int $height): bool
139138
* @param array|null $sides
140139
* @param array|null $k_bitrate
141140
*/
142-
private function sides(?array $sides, ?array $k_bitrate): void
141+
private function sides(?array $sides, ?array &$k_bitrate): void
143142
{
144-
if (!is_null($sides) && is_null($k_bitrate)) {
143+
if (! is_null($sides) && is_null($k_bitrate)) {
145144
sort($sides);
146145
}
147146

148-
$this->sides = array_values(array_filter($sides ?? $this->sides, [$this, 'sideFilter']));
147+
$filtered = [];
148+
149+
foreach ($sides ?? $this->sides as $i => $side) {
150+
if ($this->sideFilter($side)) {
151+
$filtered[] = $side;
152+
} elseif ($k_bitrate !== null) {
153+
// Remove bitrate for filtered side
154+
unset($k_bitrate[$i]);
155+
}
156+
}
157+
158+
$this->sides = $filtered;
159+
160+
if ($k_bitrate !== null) {
161+
// Reindex
162+
$k_bitrate = array_values($k_bitrate);
163+
}
149164
}
150165

151166
/**

tests/HLSTest.php

+16
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ public function testAutoRepresentations()
5151
$this->assertEquals(207, $representations[2]->getKiloBitrate());
5252
}
5353

54+
public function testAutoRepresentationsWithBitrates()
55+
{
56+
$hls = $this->getHLS();
57+
$hls->X264()
58+
->autoGenerateRepresentations([640, 480, 240], [500, 300, 150]);
59+
60+
$representations = $hls->getRepresentations()->all();
61+
62+
$this->assertIsArray($representations);
63+
$this->assertInstanceOf(Representation::class, current($representations));
64+
65+
$this->assertEquals('426x240', $representations[0]->size2string());
66+
67+
$this->assertEquals(150, $representations[0]->getKiloBitrate());
68+
}
69+
5470
public function testSetHlsTime()
5571
{
5672
$hls = $this->getHLS();

0 commit comments

Comments
 (0)