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 = pathinfo($media->getPath()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $path |
42
|
|
|
* @param bool $analyse |
43
|
|
|
* @param bool $delete_original_video |
44
|
|
|
* @return mixed |
45
|
|
|
*/ |
46
|
|
|
public function save(string $path = null, $analyse = true, $delete_original_video = false) |
47
|
|
|
{ |
48
|
|
|
$path = $this->getPath($path); |
49
|
|
|
|
50
|
|
|
$this->setFilter(); |
51
|
|
|
|
52
|
|
|
$this->media->addFilter( |
53
|
|
|
$this->getFilter() |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
$this->media->save( |
57
|
|
|
$this->getFormat(), |
58
|
|
|
$path |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
if ($delete_original_video) { |
62
|
|
|
sleep(1); |
63
|
|
|
@unlink($this->media->getPath()); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return ($analyse) ? (new StreamingAnalytics($this))->analyse() : $path; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return Filter |
71
|
|
|
*/ |
72
|
|
|
abstract protected function getFilter(): Filter; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return mixed |
76
|
|
|
*/ |
77
|
|
|
abstract protected function setFilter(); |
78
|
|
|
|
79
|
|
|
private function getPath($path): string |
80
|
|
|
{ |
81
|
|
|
if (null !== $path) { |
82
|
|
|
$this->path_info = pathinfo($path); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$dirname = str_replace("\\", "/", $this->path_info["dirname"]); |
86
|
|
|
$filename = substr($this->path_info["filename"], -50); |
87
|
|
|
|
88
|
|
|
Helper::makeDir($dirname); |
89
|
|
|
|
90
|
|
|
if ($this instanceof DASH) { |
91
|
|
|
$path = $dirname . "/" . $filename . ".mpd"; |
92
|
|
|
} elseif ($this instanceof HLS) { |
93
|
|
|
$representations = $this->getRepresentations(); |
94
|
|
|
$path = $dirname . "/" . $filename . "_" . end($representations)->getHeight() . "p.m3u8"; |
95
|
|
|
ExportHLSPlaylist::savePlayList($dirname . "/" . $filename . ".m3u8", $this->getRepresentations(), $filename); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $path; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return array |
103
|
|
|
*/ |
104
|
|
|
public function getPathInfo(): array |
105
|
|
|
{ |
106
|
|
|
return $this->path_info; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return object|Media |
111
|
|
|
*/ |
112
|
|
|
public function getMedia() |
113
|
|
|
{ |
114
|
|
|
return $this->media; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: