Completed
Branch v7 (f01542)
by Pascal
08:46
created

HandlesConcatenation   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 17
c 1
b 0
f 0
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A concatWithTranscoding() 0 7 1
A addConcatFilterAndMapping() 0 14 3
1
<?php
2
3
namespace Pbmedia\LaravelFFMpeg\Exporters;
4
5
use Pbmedia\LaravelFFMpeg\Filesystem\Media;
6
7
trait HandlesConcatenation
8
{
9
    protected bool $concatWithTranscoding = false;
10
    protected bool $concatWithVideo       = false;
11
    protected bool $concatWithAudio       = false;
12
13
    public function concatWithTranscoding($hasVideo = true, $hasAudio = true): self
14
    {
15
        $this->concatWithTranscoding = true;
16
        $this->concatWithVideo       = $hasVideo;
17
        $this->concatWithAudio       = $hasAudio;
18
19
        return $this;
20
    }
21
22
    private function addConcatFilterAndMapping(Media $outputMedia)
23
    {
24
        $sources = $this->driver->getMediaCollection()->map(function ($media, $key) {
25
            return "[{$key}]";
26
        });
27
28
        $concatWithVideo = $this->concatWithVideo ? 1 : 0;
29
        $concatWithAudio = $this->concatWithAudio ? 1 : 0;
30
31
        $this->addFilter(
0 ignored issues
show
Bug introduced by
It seems like addFilter() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
        $this->/** @scrutinizer ignore-call */ 
32
               addFilter(
Loading history...
32
            $sources->implode(''),
33
            "concat=n={$sources->count()}:v={$concatWithVideo}:a={$concatWithAudio}",
34
            '[concat]'
35
        )->addFormatOutputMapping($this->format, $outputMedia, ['[concat]']);
36
    }
37
}
38