Passed
Push — master ( 1b90b9...7956e0 )
by Gabriel
03:50 queued 11s
created

Nip_File_Video::getFFmpegVideo()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 3
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 7
rs 10
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);
0 ignored issues
show
Bug introduced by
The type Process was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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();
0 ignored issues
show
Bug introduced by
The type Image_VideoFrame was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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);
0 ignored issues
show
Bug introduced by
The call to ffmpeg_movie::__construct() has too few arguments starting with persistent. ( Ignorable by Annotation )

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

62
            $this->_ffmpeg_video = /** @scrutinizer ignore-call */ new ffmpeg_movie($this->path);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
63
        }
64
65
        return $this->_ffmpeg_video;
66
    }
67
68
    public function getFrameCount()
69
    {
70
        return $this->getFFmpegVideo()->getFrameCount();
71
    }
72
}
73