diff --git a/src/AutoReps.php b/src/AutoReps.php index 63aa200..2207d32 100644 --- a/src/AutoReps.php +++ b/src/AutoReps.php @@ -99,7 +99,6 @@ private function getKiloBitRate(): int /** * @param array|null $k_bitrate_values - * @TODO: fix #79 */ private function kiloBitrate(?array $k_bitrate_values): void { @@ -139,13 +138,29 @@ private function sideFilter(int $height): bool * @param array|null $sides * @param array|null $k_bitrate */ - private function sides(?array $sides, ?array $k_bitrate): void + private function sides(?array $sides, ?array &$k_bitrate): void { - if (!is_null($sides) && is_null($k_bitrate)) { + if (! is_null($sides) && is_null($k_bitrate)) { sort($sides); } - $this->sides = array_values(array_filter($sides ?? $this->sides, [$this, 'sideFilter'])); + $filtered = []; + + foreach ($sides ?? $this->sides as $i => $side) { + if ($this->sideFilter($side)) { + $filtered[] = $side; + } elseif ($k_bitrate !== null) { + // Remove bitrate for filtered side + unset($k_bitrate[$i]); + } + } + + $this->sides = $filtered; + + if ($k_bitrate !== null) { + // Reindex + $k_bitrate = array_values($k_bitrate); + } } /** diff --git a/tests/HLSTest.php b/tests/HLSTest.php index 2bc01ca..96f18fc 100644 --- a/tests/HLSTest.php +++ b/tests/HLSTest.php @@ -51,6 +51,22 @@ public function testAutoRepresentations() $this->assertEquals(207, $representations[2]->getKiloBitrate()); } + public function testAutoRepresentationsWithBitrates() + { + $hls = $this->getHLS(); + $hls->X264() + ->autoGenerateRepresentations([640, 480, 240], [500, 300, 150]); + + $representations = $hls->getRepresentations()->all(); + + $this->assertIsArray($representations); + $this->assertInstanceOf(Representation::class, current($representations)); + + $this->assertEquals('426x240', $representations[0]->size2string()); + + $this->assertEquals(150, $representations[0]->getKiloBitrate()); + } + public function testSetHlsTime() { $hls = $this->getHLS();