1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2019 Amin Yazdanpanah<http://www.aminyazdanpanah.com>. |
5
|
|
|
* |
6
|
|
|
* Licensed under the MIT License; |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* https://opensource.org/licenses/MIT |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace AYazdanpanah\FFMpegStreaming\Traits; |
20
|
|
|
|
21
|
|
|
use AYazdanpanah\FFMpegStreaming\Exception\Exception; |
22
|
|
|
use AYazdanpanah\FFMpegStreaming\Format\HEVC; |
23
|
|
|
use AYazdanpanah\FFMpegStreaming\Format\Video; |
24
|
|
|
use AYazdanpanah\FFMpegStreaming\Format\VP9; |
25
|
|
|
use AYazdanpanah\FFMpegStreaming\Format\X264; |
26
|
|
|
use FFMpeg\Format\FormatInterface; |
27
|
|
|
|
28
|
|
|
trait Formats |
29
|
|
|
{ |
30
|
|
|
/** @var object */ |
31
|
|
|
public $format; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param string $audioCodec |
35
|
|
|
* @param string $videoCodec |
36
|
|
|
* @return $this |
37
|
|
|
* @throws Exception |
38
|
|
|
*/ |
39
|
|
|
public function X264($audioCodec = 'libmp3lame', $videoCodec = 'libx264') |
40
|
|
|
{ |
41
|
|
|
$this->setFormat(new X264($audioCodec, $videoCodec)); |
42
|
|
|
return $this; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $audioCodec |
47
|
|
|
* @param string $videoCodec |
48
|
|
|
* @return $this |
49
|
|
|
* @throws Exception |
50
|
|
|
*/ |
51
|
|
|
public function HEVC($audioCodec = 'libmp3lame', $videoCodec = 'libx265') |
52
|
|
|
{ |
53
|
|
|
$this->setFormat(new HEVC($audioCodec, $videoCodec)); |
54
|
|
|
return $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $audioCodec |
59
|
|
|
* @param string $videoCodec |
60
|
|
|
* @return $this |
61
|
|
|
* @throws Exception |
62
|
|
|
*/ |
63
|
|
|
public function WebM($audioCodec = 'libvorbis', $videoCodec = 'libvpx-vp9') |
64
|
|
|
{ |
65
|
|
|
$this->setFormat(new VP9($audioCodec, $videoCodec)); |
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return FormatInterface|mixed |
71
|
|
|
*/ |
72
|
|
|
private function getFormat(): FormatInterface |
73
|
|
|
{ |
74
|
|
|
return $this->format; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param mixed $format |
79
|
|
|
* @return $this |
80
|
|
|
* @throws Exception |
81
|
|
|
*/ |
82
|
|
|
public function setFormat($format) |
83
|
|
|
{ |
84
|
|
|
if(!$format instanceof Video){ |
85
|
|
|
throw new Exception("Sorry! we only accept formats that inherent from AYazdanpanah\FFMpegStreaming\Format\Video"); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$this->format = $format; |
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
} |