GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Nip_File_Video::saveRandomFrame()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 16
nc 4
nop 3
dl 0
loc 22
ccs 0
cts 17
cp 0
crap 12
rs 9.2
c 0
b 0
f 0
1
<?php
2
class Nip_File_Video extends Nip_File_Handler {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
3
4
    static public $extensions = array('avi', 'mp4', 'mpg', 'mpeg', 'mkv', 'm4v');
5
    protected $_ffmpeg_video;
6
7
    public function convert($params = array(), $removeOriginal = true) {
8
        if (!$params['f'] || $params['f'] == $this->extension) {
9
            return;
10
        }
11
12
        $command = [];
13
        $command[] = '/usr/bin/ffmpeg';
14
        $command[] = "-i ".escapeshellarg($this->path);
15
        foreach ($params as $key => $value) {
16
            $command[] = "-$key ".escapeshellarg($value);
17
        }
18
19
        $path = dirname($this->path) .DIRECTORY_SEPARATOR. pathinfo($this->path, PATHINFO_FILENAME) . '.' . strtolower($params['f']);
20
        $command[] = $path;
21
22
        $command = implode(" ", $command) . " && chmod 777 $path".($removeOriginal ? " && rm $this->path" : "");
23
24
        $process = new Process($command);
25
        $process->start();
26
    }
27
28
    public function saveRandomFrame($dir, $width = false, $height = false) {
29
        /* @var $frame ffmpeg_frame */
30
        $frame = $this->getRandomFrame();
31
        $image = new Image_VideoFrame();
32
        $image->setFFmpegFrame($frame);
33
34
        if (!$width) {
35
            $width = $frame->getWidth();
36
        }
37
        if (!$height) {
38
            $height = $frame->getHeight();
39
        }
40
        $image->cropToCenter($width, $height);
41
        $image->unsharpMask();
42
43
        $filename = explode(".", basename($this->path));
44
        array_pop($filename);
45
        $filename[] = "jpg";
46
        $filename = implode(".", $filename);
47
        $image->path = $dir . '/' . $filename;
48
        $image->save();
49
   }
50
51
    public function getRandomFrame()
52
    {
53
        return $this->getFFmpegVideo()->getFrame(rand(1, $this->getFrameCount()));
54
    }
55
56
    protected function getFFmpegVideo()
57
    {
58
        if (!$this->_ffmpeg_video) {
59
            $this->_ffmpeg_video = new ffmpeg_movie($this->path);
60
        }
61
62
        return $this->_ffmpeg_video;
63
    }
64
65
    public function getFrameCount()
66
    {
67
        return $this->getFFmpegVideo()->getFrameCount();
68
    }
69
}