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