1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ProtoneMedia\LaravelFFMpeg\FFMpeg; |
4
|
|
|
|
5
|
|
|
use FFMpeg\Format\FormatInterface; |
6
|
|
|
use FFMpeg\Format\Video\DefaultVideo; |
7
|
|
|
use FFMpeg\Media\AdvancedMedia; |
8
|
|
|
use ProtoneMedia\LaravelFFMpeg\Filesystem\Media; |
9
|
|
|
|
10
|
|
|
class AdvancedOutputMapping |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var array |
14
|
|
|
*/ |
15
|
|
|
private $outs; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var \FFMpeg\Format\FormatInterface |
19
|
|
|
*/ |
20
|
|
|
private $format; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var \ProtoneMedia\LaravelFFMpeg\Filesystem\Media |
24
|
|
|
*/ |
25
|
|
|
private $output; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var boolean |
29
|
|
|
*/ |
30
|
|
|
private $forceDisableAudio = false; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var boolean |
34
|
|
|
*/ |
35
|
|
|
private $forceDisableVideo = false; |
36
|
|
|
|
37
|
|
|
public function __construct(array $outs, FormatInterface $format, Media $output, bool $forceDisableAudio = false, bool $forceDisableVideo = false) |
38
|
|
|
{ |
39
|
|
|
$this->outs = $outs; |
40
|
|
|
$this->format = $format; |
41
|
|
|
$this->output = $output; |
42
|
|
|
$this->forceDisableAudio = $forceDisableAudio; |
43
|
|
|
$this->forceDisableVideo = $forceDisableVideo; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Applies the attributes to the format and specifies the video |
48
|
|
|
* bitrate if it's missing. |
49
|
|
|
*/ |
50
|
|
|
public function apply(AdvancedMedia $advancedMedia): void |
51
|
|
|
{ |
52
|
|
|
if ($this->format instanceof DefaultVideo) { |
53
|
|
|
$parameters = $this->format->getAdditionalParameters() ?: []; |
54
|
|
|
|
55
|
|
|
if (!in_array('-b:v', $parameters)) { |
56
|
|
|
$parameters = ['-b:v', $this->format->getKiloBitrate() . 'k'] + $parameters; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$this->format->setAdditionalParameters($parameters); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$advancedMedia->map($this->outs, $this->format, $this->output->getLocalPath(), $this->forceDisableAudio, $this->forceDisableVideo); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getFormat(): FormatInterface |
66
|
|
|
{ |
67
|
|
|
return $this->format; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getOutputMedia(): Media |
71
|
|
|
{ |
72
|
|
|
return $this->output; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function hasOut(string $out): bool |
76
|
|
|
{ |
77
|
|
|
return in_array($out, $this->outs); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|