1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Nip_File_Video extends Nip_File_Handler |
4
|
|
|
{ |
5
|
|
|
public static $extensions = ['avi', 'mp4', 'mpg', 'mpeg', 'mkv', 'm4v']; |
6
|
|
|
protected $_ffmpeg_video; |
7
|
|
|
|
8
|
|
|
public function convert($params = [], $removeOriginal = true) |
9
|
|
|
{ |
10
|
|
|
if (!$params['f'] || $params['f'] == $this->extension) { |
11
|
|
|
return; |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
$command = []; |
15
|
|
|
$command[] = '/usr/bin/ffmpeg'; |
16
|
|
|
$command[] = '-i '.escapeshellarg($this->path); |
17
|
|
|
foreach ($params as $key => $value) { |
18
|
|
|
$command[] = "-$key ".escapeshellarg($value); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
$path = dirname($this->path).DIRECTORY_SEPARATOR.pathinfo($this->path, PATHINFO_FILENAME).'.'.strtolower($params['f']); |
22
|
|
|
$command[] = $path; |
23
|
|
|
|
24
|
|
|
$command = implode(' ', $command)." && chmod 777 $path".($removeOriginal ? " && rm $this->path" : ''); |
25
|
|
|
|
26
|
|
|
$process = new Process($command); |
|
|
|
|
27
|
|
|
$process->start(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function saveRandomFrame($dir, $width = false, $height = false) |
31
|
|
|
{ |
32
|
|
|
/* @var $frame ffmpeg_frame */ |
33
|
|
|
$frame = $this->getRandomFrame(); |
34
|
|
|
$image = new Image_VideoFrame(); |
|
|
|
|
35
|
|
|
$image->setFFmpegFrame($frame); |
36
|
|
|
|
37
|
|
|
if (!$width) { |
38
|
|
|
$width = $frame->getWidth(); |
39
|
|
|
} |
40
|
|
|
if (!$height) { |
41
|
|
|
$height = $frame->getHeight(); |
42
|
|
|
} |
43
|
|
|
$image->cropToCenter($width, $height); |
44
|
|
|
$image->unsharpMask(); |
45
|
|
|
|
46
|
|
|
$filename = explode('.', basename($this->path)); |
47
|
|
|
array_pop($filename); |
48
|
|
|
$filename[] = 'jpg'; |
49
|
|
|
$filename = implode('.', $filename); |
50
|
|
|
$image->path = $dir.'/'.$filename; |
51
|
|
|
$image->save(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getRandomFrame() |
55
|
|
|
{ |
56
|
|
|
return $this->getFFmpegVideo()->getFrame(rand(1, $this->getFrameCount())); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
protected function getFFmpegVideo() |
60
|
|
|
{ |
61
|
|
|
if (!$this->_ffmpeg_video) { |
62
|
|
|
$this->_ffmpeg_video = new ffmpeg_movie($this->path); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $this->_ffmpeg_video; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function getFrameCount() |
69
|
|
|
{ |
70
|
|
|
return $this->getFFmpegVideo()->getFrameCount(); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths