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   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 68
ccs 0
cts 39
cp 0
rs 10
c 0
b 0
f 0
wmc 12
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
B convert() 0 20 5
A saveRandomFrame() 0 22 3
A getRandomFrame() 0 4 1
A getFFmpegVideo() 0 8 2
A getFrameCount() 0 4 1
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
}