1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\MediaLibrary\ImageGenerators\FileTypes; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
6
|
|
|
use Spatie\MediaLibrary\Conversion\Conversion; |
7
|
|
|
use Spatie\MediaLibrary\ImageGenerators\BaseGenerator; |
8
|
|
|
use FFMpeg\Coordinate\TimeCode; |
9
|
|
|
use \FFMpeg\FFMpeg; |
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('laravel-medialibrary.ffmpeg_binaries'), |
19
|
|
|
'ffprobe.binaries' => config('laravel-medialibrary.ffprobe_binaries'), |
20
|
|
|
]); |
21
|
|
|
$video = $ffmpeg->open($file); |
22
|
|
|
|
23
|
|
|
$seconds = $conversion ? $conversion->getExtractVideoFrameAtSecond() : 0; |
24
|
|
|
|
25
|
|
|
$frame = $video->frame(TimeCode::fromSeconds($seconds)); |
26
|
|
|
$frame->save($imageFile); |
27
|
|
|
|
28
|
|
|
return $imageFile; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function requirementsAreInstalled() : bool |
32
|
|
|
{ |
33
|
|
|
return class_exists('\\FFMpeg\\FFMpeg'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function supportedExtensions() : Collection |
37
|
|
|
{ |
38
|
|
|
return collect(['webm', 'mov', 'mp4']); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function supportedMimeTypes() : Collection |
42
|
|
|
{ |
43
|
|
|
return collect(['video/webm', 'video/mpeg', 'video/mp4', 'video/quicktime']); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function supportedTypes() : Collection |
47
|
|
|
{ |
48
|
|
|
return collect('video'); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|