Skip to content

Commit ac0e9df

Browse files
bug fixes #33 and other minor improvements
1 parent 4bc7af1 commit ac0e9df

16 files changed

+162
-123
lines changed

src/DASH.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Streaming;
1313

1414
use Streaming\Filters\DASHFilter;
15-
use Streaming\Filters\FilterStreamingInterface;
15+
use Streaming\Filters\StreamFilterInterface;
1616

1717
class DASH extends Streaming
1818
{
@@ -82,7 +82,7 @@ public function isGenerateHlsPlaylist(): bool
8282
/**
8383
* @return DASHFilter
8484
*/
85-
protected function getFilter(): FilterStreamingInterface
85+
protected function getFilter(): StreamFilterInterface
8686
{
8787
return new DASHFilter($this);
8888
}

src/Filters/DASHFilter.php

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,62 +13,62 @@
1313
namespace Streaming\Filters;
1414

1515

16-
use Streaming\DASH;
16+
use Streaming\StreamInterface;
1717
use Streaming\Format\X264;
1818
use Streaming\Representation;
1919

20-
class DASHFilter extends Filter
20+
class DASHFilter extends StreamFilter
2121
{
22+
/** @var \Streaming\DASH */
23+
private $dash;
2224
/**
23-
* @param $media
25+
* @param StreamInterface $stream
2426
*/
25-
public function setFilter($media): void
27+
public function streamFilter(StreamInterface $stream): void
2628
{
27-
$this->filter = $this->DASHFilter($media);
29+
$this->dash = $stream;
30+
$this->set();
2831
}
2932

3033
/**
31-
* @param DASH $dash
3234
* @return array
3335
*/
34-
private function DASHFilter(DASH $dash): array
36+
private function set()
3537
{
36-
$filter = $this->getBaseFilters($dash, count($dash->getRepresentations()));
38+
$this->filter = $this->getBaseFilters();
3739

38-
foreach ($dash->getRepresentations() as $key => $representation) {
39-
$filter[] = "-map";
40-
$filter[] = "0";
41-
$filter[] = "-b:v:" . $key;
42-
$filter[] = $representation->getKiloBitrate() . "k";
43-
$filter = array_merge($filter, $this->getAudioBitrate($representation, $key));
40+
foreach ($this->dash->getRepresentations() as $key => $representation) {
41+
$this->filter[] = "-map";
42+
$this->filter[] = "0";
43+
$this->filter[] = "-b:v:" . $key;
44+
$this->filter[] = $representation->getKiloBitrate() . "k";
45+
$this->filter = array_merge($this->filter, $this->getAudioBitrate($representation, $key));
4446

4547
if (null !== $representation->getResize()) {
46-
$filter[] = "-s:v:" . $key;
47-
$filter[] = $representation->getResize();
48+
$this->filter[] = "-s:v:" . $key;
49+
$this->filter[] = $representation->getResize();
4850
}
4951
}
5052

51-
if ($dash->getAdaption()) {
52-
$filter[] = "-adaptation_sets";
53-
$filter[] = $dash->getAdaption();
53+
if ($this->dash->getAdaption()) {
54+
$this->filter[] = "-adaptation_sets";
55+
$this->filter[] = $this->dash->getAdaption();
5456
}
55-
$filter = array_merge($filter, $dash->getAdditionalParams());
56-
$filter = array_merge($filter, ["-strict", $dash->getStrict()]);
57+
$this->filter = array_merge($this->filter, $this->dash->getAdditionalParams());
58+
$this->filter = array_merge($this->filter, ["-strict", $this->dash->getStrict()]);
5759

58-
return $filter;
60+
return $this->filter;
5961
}
6062

6163
/**
62-
* @param $dash
63-
* @param $count
64+
6465
* @return array
6566
*/
66-
private function getBaseFilters(DASH $dash, int $count): array
67+
private function getBaseFilters(): array
6768
{
68-
$dirname = $dash->getPathInfo(PATHINFO_FILENAME);
69-
$filename = $dash->getPathInfo(PATHINFO_FILENAME);
69+
$filename = $this->dash->getPathInfo(PATHINFO_FILENAME);
7070

71-
$filter = [
71+
$this->filter = [
7272
"-bf", "1",
7373
"-keyint_min", "120",
7474
"-g", "120",
@@ -78,23 +78,25 @@ private function getBaseFilters(DASH $dash, int $count): array
7878
"-use_template", "1",
7979
"-init_seg_name", ($filename . '_init_$RepresentationID$.$ext$'),
8080
"-media_seg_name", ($filename . '_chunk_$RepresentationID$_$Number%05d$.$ext$'),
81-
"-seg_duration", $dash->getSegDuration(),
82-
"-hls_playlist", (int)$dash->isGenerateHlsPlaylist(),
81+
"-seg_duration", $this->dash->getSegDuration(),
82+
"-hls_playlist", (int)$this->dash->isGenerateHlsPlaylist(),
8383
"-f", "dash",
8484
];
8585

86-
if ($dash->getFormat() instanceof X264) {
87-
$filter[] = "-profile:v:0";
88-
$filter[] = "main";
86+
if ($this->dash->getFormat() instanceof X264) {
87+
$this->filter[] = "-profile:v:0";
88+
$this->filter[] = "main";
89+
90+
$count = count($this->dash->getRepresentations());
8991

9092
while ($count > 0) {
91-
$filter[] = "-profile:v:" . $count;
92-
$filter[] = "baseline";
93+
$this->filter[] = "-profile:v:" . $count;
94+
$this->filter[] = "baseline";
9395
$count--;
9496
}
9597
}
9698

97-
return $filter;
99+
return $this->filter;
98100
}
99101

100102
/**

src/Filters/HLSFilter.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111

1212
namespace Streaming\Filters;
1313

14+
use Streaming\StreamInterface;
1415
use Streaming\File;
1516
use Streaming\Representation;
1617
use Streaming\Utiles;
1718

18-
class HLSFilter extends Filter
19+
class HLSFilter extends StreamFilter
1920
{
2021
/** @var \Streaming\HLS */
2122
private $hls;
@@ -97,7 +98,7 @@ private function getInitFilename(): string
9798
*/
9899
private function getSegmentFilename(Representation $rep): string
99100
{
100-
$ext = ($this->hls->getHlsFmp4InitFilename() === "fmp4") ? "m4s" : "ts";
101+
$ext = ($this->hls->getHlsSegmentType() === "fmp4") ? "m4s" : "ts";
101102
return $this->seg_filename . "_" . $rep->getHeight() . "p_%04d." . $ext;
102103
}
103104

@@ -169,12 +170,12 @@ private function setPaths(): void
169170
}
170171

171172
/**
172-
* @param $media
173+
* @param StreamInterface $stream
173174
* @return void
174175
*/
175-
public function setFilter($media): void
176+
public function streamFilter(StreamInterface $stream): void
176177
{
177-
$this->hls = $media;
178+
$this->hls = $stream;
178179
$this->setPaths();
179180

180181
$reps = $this->hls->getRepresentations();

src/Filters/Filter.php renamed to src/Filters/StreamFilter.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,25 @@
1111

1212
namespace Streaming\Filters;
1313

14-
use Streaming\Export;
15-
use FFMpeg\Filters\FilterInterface;
14+
use Streaming\StreamInterface;
1615

17-
abstract class Filter implements FilterInterface, FilterStreamingInterface
16+
abstract class StreamFilter implements StreamFilterInterface
1817
{
1918
private $priority = 2;
2019

2120
protected $filter = [];
2221

2322
/**
2423
* Filter constructor.
25-
* @param Export $media
24+
* @param StreamInterface $stream
2625
*/
27-
public function __construct(Export $media)
26+
public function __construct(StreamInterface $stream)
2827
{
29-
$this->setFilter($media);
28+
$this->streamFilter($stream);
3029
}
3130

3231
/**
33-
* Applies the filter on the the Audio media given an format.
32+
* Applies the filter on the the stream media
3433
*
3534
* @return array An array of arguments
3635
*/

src/Filters/FilterStreamingInterface.php renamed to src/Filters/StreamFilterInterface.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,19 @@
1111

1212
namespace Streaming\Filters;
1313

14-
interface FilterStreamingInterface
14+
use FFMpeg\Filters\FilterInterface;
15+
use Streaming\StreamInterface;
16+
17+
interface StreamFilterInterface extends FilterInterface
1518
{
1619
/**
17-
* @param $media
20+
* @param StreamInterface $stream
1821
* @return mixed
1922
*/
20-
public function setFilter($media): void;
23+
public function streamFilter(StreamInterface $stream): void;
24+
25+
/**
26+
* @return array
27+
*/
28+
public function apply(): array;
2129
}

src/Filters/StreamToFileFilter.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,18 @@
1313
namespace Streaming\Filters;
1414

1515

16+
use Streaming\StreamInterface;
1617
use Streaming\StreamToFile;
1718

18-
class StreamToFileFilter extends Filter
19+
class StreamToFileFilter extends StreamFilter
1920
{
2021

2122
/**
2223
* @param $media
2324
* @return mixed
2425
*/
25-
public function setFilter($media): void
26+
public function streamFilter(StreamInterface $media): void
2627
{
27-
$this->filter = $this->StreamToFileFilter($media);
28-
}
29-
30-
/**
31-
* @param StreamToFile $stf
32-
* @return array
33-
*/
34-
private function StreamToFileFilter(StreamToFile $stf)
35-
{
36-
return array_merge(['-c', 'copy'], $stf->getParams());
28+
$this->filter = array_merge(['-c', 'copy'], $media->getParams());
3729
}
3830
}

src/HLS.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111

1212
namespace Streaming;
1313

14-
use phpDocumentor\Reflection\Types\This;
15-
use Streaming\Filters\FilterStreamingInterface;
1614
use Streaming\Filters\HLSFilter;
15+
use Streaming\Filters\StreamFilterInterface;
1716

1817
class HLS extends Streaming
1918
{
@@ -225,7 +224,7 @@ public function getHlsFmp4InitFilename(): string
225224
/**
226225
* @return HLSFilter
227226
*/
228-
protected function getFilter(): FilterStreamingInterface
227+
protected function getFilter(): StreamFilterInterface
229228
{
230229
return new HLSFilter($this);
231230
}

0 commit comments

Comments
 (0)