1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the PHP-FFmpeg-video-streaming package. |
5
|
|
|
* |
6
|
|
|
* (c) Amin Yazdanpanah <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Streaming; |
13
|
|
|
|
14
|
|
|
use Streaming\Filters\Filter; |
15
|
|
|
use Streaming\Traits\Formats; |
16
|
|
|
|
17
|
|
|
abstract class Export |
18
|
|
|
{ |
19
|
|
|
use Formats; |
20
|
|
|
|
21
|
|
|
/** @var object */ |
22
|
|
|
protected $media; |
23
|
|
|
|
24
|
|
|
/** @var Filter */ |
25
|
|
|
protected $filter; |
26
|
|
|
|
27
|
|
|
/** @var array */ |
28
|
|
|
protected $path_info; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Export constructor. |
32
|
|
|
* @param Media $media |
33
|
|
|
*/ |
34
|
|
|
public function __construct(Media $media) |
35
|
|
|
{ |
36
|
|
|
$this->media = $media; |
37
|
|
|
$this->path_info = $media->getPathInfo(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $path |
42
|
|
|
* @return Export |
43
|
|
|
*/ |
44
|
|
|
public function save(string $path = null): Export |
45
|
|
|
{ |
46
|
|
|
$path = $this->getPath($path); |
47
|
|
|
|
48
|
|
|
$this->setFilter(); |
49
|
|
|
|
50
|
|
|
$this->media->addFilter( |
51
|
|
|
$this->getFilter() |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$this->media->save( |
55
|
|
|
$this->getFormat(), |
56
|
|
|
$path |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return Filter |
64
|
|
|
*/ |
65
|
|
|
abstract protected function getFilter(): Filter; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return mixed |
69
|
|
|
*/ |
70
|
|
|
abstract protected function setFilter(); |
71
|
|
|
|
72
|
|
|
private function getPath($path): string |
73
|
|
|
{ |
74
|
|
|
if(null !== $path){ |
75
|
|
|
$this->path_info = pathinfo($path); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$dirname = str_replace("\\", "/", $this->path_info["dirname"]); |
79
|
|
|
$filename = substr($this->path_info["filename"], -50); |
80
|
|
|
|
81
|
|
|
Helper::makeDir($dirname); |
82
|
|
|
|
83
|
|
|
if ($this instanceof DASH) { |
84
|
|
|
$path = $dirname . "/" . $filename . ".mpd"; |
85
|
|
|
} elseif ($this instanceof HLS) { |
86
|
|
|
$representations = $this->getRepresentations(); |
87
|
|
|
$path = $dirname . "/" . $filename . "_" . end($representations)->getHeight() . "p.m3u8"; |
88
|
|
|
ExportHLSPlaylist::savePlayList($dirname . "/" . $filename . ".m3u8", $this->getRepresentations(), $filename); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return $path; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return array |
96
|
|
|
*/ |
97
|
|
|
public function getPathInfo(): array |
98
|
|
|
{ |
99
|
|
|
return $this->path_info; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|