1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pbmedia\LaravelFFMpeg; |
4
|
|
|
|
5
|
|
|
class SegmentedExporter extends MediaExporter |
6
|
|
|
{ |
7
|
|
|
protected $filter; |
8
|
|
|
|
9
|
|
|
protected $playlistPath; |
10
|
|
|
|
11
|
|
|
protected $segmentLength = 10; |
12
|
|
|
|
13
|
|
|
protected $saveMethod = 'saveStream'; |
14
|
|
|
|
15
|
|
|
public function setPlaylistPath(string $playlistPath): MediaExporter |
16
|
|
|
{ |
17
|
|
|
$this->playlistPath = $playlistPath; |
18
|
|
|
|
19
|
|
|
return $this; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function setSegmentLength(int $segmentLength): MediaExporter |
23
|
|
|
{ |
24
|
|
|
$this->segmentLength = $segmentLength; |
25
|
|
|
|
26
|
|
|
return $this; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function getFilter(): SegmentedFilter |
30
|
|
|
{ |
31
|
|
|
if ($this->filter) { |
32
|
|
|
return $this->filter; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
return $this->filter = new SegmentedFilter( |
36
|
|
|
$this->getPlaylistFilename(), |
37
|
|
|
$this->segmentLength |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function saveStream(string $playlistPath): MediaExporter |
42
|
|
|
{ |
43
|
|
|
$this->setPlaylistPath($playlistPath); |
44
|
|
|
|
45
|
|
|
$this->media->addFilter( |
46
|
|
|
$this->getFilter() |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
$this->media->save( |
50
|
|
|
$this->getFormat(), |
|
|
|
|
51
|
|
|
$this->getSegmentFullPath() |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
return $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getSegmentFullPath(): string |
58
|
|
|
{ |
59
|
|
|
return implode(DIRECTORY_SEPARATOR, [ |
60
|
|
|
pathinfo($this->playlistPath, PATHINFO_DIRNAME), |
61
|
|
|
$this->getSegmentFilename(), |
62
|
|
|
]); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getPlaylistPath(): string |
66
|
|
|
{ |
67
|
|
|
return $this->playlistPath; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getPlaylistName(): string |
71
|
|
|
{ |
72
|
|
|
return pathinfo($this->getPlaylistPath(), PATHINFO_FILENAME); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function getPlaylistFilename(): string |
76
|
|
|
{ |
77
|
|
|
return $this->getFormattedFilename('.m3u8'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getSegmentFilename(): string |
81
|
|
|
{ |
82
|
|
|
return $this->getFormattedFilename('_%05d.ts'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
protected function getFormattedFilename(string $suffix = ''): string |
86
|
|
|
{ |
87
|
|
|
return implode([ |
88
|
|
|
$this->getPlaylistName(), |
89
|
|
|
'_', |
90
|
|
|
$this->getFormat()->getKiloBitrate(), |
|
|
|
|
91
|
|
|
]) . $suffix; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: