protonemedia /
laravel-ffmpeg
| 1 | <?php |
||
| 2 | |||
| 3 | namespace ProtoneMedia\LaravelFFMpeg\Exporters; |
||
| 4 | |||
| 5 | use ProtoneMedia\LaravelFFMpeg\Filesystem\Media; |
||
| 6 | |||
| 7 | trait HandlesConcatenation |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var boolean |
||
| 11 | */ |
||
| 12 | protected $concatWithTranscoding = false; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var boolean |
||
| 16 | */ |
||
| 17 | protected $concatWithVideo = false; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var boolean |
||
| 21 | */ |
||
| 22 | protected $concatWithAudio = false; |
||
| 23 | |||
| 24 | public function concatWithTranscoding(bool $hasVideo = true, bool $hasAudio = true): self |
||
| 25 | { |
||
| 26 | $this->concatWithTranscoding = true; |
||
| 27 | $this->concatWithVideo = $hasVideo; |
||
| 28 | $this->concatWithAudio = $hasAudio; |
||
| 29 | |||
| 30 | return $this; |
||
| 31 | } |
||
| 32 | |||
| 33 | private function addConcatFilterAndMapping(Media $outputMedia) |
||
| 34 | { |
||
| 35 | $sources = $this->driver->getMediaCollection()->map(function ($media, $key) { |
||
| 36 | return "[{$key}]"; |
||
| 37 | }); |
||
| 38 | |||
| 39 | $concatWithVideo = $this->concatWithVideo ? 1 : 0; |
||
| 40 | $concatWithAudio = $this->concatWithAudio ? 1 : 0; |
||
| 41 | |||
| 42 | $this->addFilter( |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 43 | $sources->implode(''), |
||
| 44 | "concat=n={$sources->count()}:v={$concatWithVideo}:a={$concatWithAudio}", |
||
| 45 | '[concat]' |
||
| 46 | )->addFormatOutputMapping($this->format, $outputMedia, ['[concat]']); |
||
| 47 | } |
||
| 48 | } |
||
| 49 |