Video   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 38
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A convert() 0 20 3
A requirementsAreInstalled() 0 4 1
A supportedExtensions() 0 4 1
A supportedMimeTypes() 0 4 1
1
<?php
2
3
namespace Spatie\MediaLibrary\ImageGenerators\FileTypes;
4
5
use FFMpeg\Coordinate\TimeCode;
6
use FFMpeg\FFMpeg;
7
use Illuminate\Support\Collection;
8
use Spatie\MediaLibrary\Conversion\Conversion;
9
use Spatie\MediaLibrary\ImageGenerators\BaseGenerator;
10
11
class Video extends BaseGenerator
12
{
13
    public function convert(string $file, Conversion $conversion = null): string
14
    {
15
        $imageFile = pathinfo($file, PATHINFO_DIRNAME).'/'.pathinfo($file, PATHINFO_FILENAME).'.jpg';
16
17
        $ffmpeg = FFMpeg::create([
18
            'ffmpeg.binaries' => config('medialibrary.ffmpeg_path'),
19
            'ffprobe.binaries' => config('medialibrary.ffprobe_path'),
20
        ]);
21
22
        $video = $ffmpeg->open($file);
23
        $duration = $ffmpeg->getFFProbe()->format($file)->get('duration');
24
25
        $seconds = $conversion ? $conversion->getExtractVideoFrameAtSecond() : 0;
26
        $seconds = $duration < $seconds ? 0 : $seconds;
27
28
        $frame = $video->frame(TimeCode::fromSeconds($seconds));
29
        $frame->save($imageFile);
30
31
        return $imageFile;
32
    }
33
34
    public function requirementsAreInstalled(): bool
35
    {
36
        return class_exists('\\FFMpeg\\FFMpeg');
37
    }
38
39
    public function supportedExtensions(): Collection
40
    {
41
        return collect(['webm', 'mov', 'mp4']);
42
    }
43
44
    public function supportedMimeTypes(): Collection
45
    {
46
        return collect(['video/webm', 'video/mpeg', 'video/mp4', 'video/quicktime']);
47
    }
48
}
49