|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace floor12\files\logic; |
|
5
|
|
|
|
|
6
|
|
|
use ErrorException; |
|
7
|
|
|
use Yii; |
|
8
|
|
|
|
|
9
|
|
|
class VideoFrameExtractor |
|
10
|
|
|
{ |
|
11
|
|
|
/** @var string */ |
|
12
|
|
|
private $ffmpegBin; |
|
13
|
|
|
/** @var string */ |
|
14
|
|
|
private $videoSourceFilename; |
|
15
|
|
|
/** @var string */ |
|
16
|
|
|
private $outputImageFilename; |
|
17
|
|
|
|
|
18
|
|
|
public function __construct(string $videoSourceFilename, string $outputImageFilename) |
|
19
|
|
|
{ |
|
20
|
|
|
$this->ffmpegBin = Yii::$app->getModule('files')->ffmpeg; |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
if (!file_exists($this->ffmpegBin)) |
|
|
|
|
|
|
23
|
|
|
throw new ErrorException("ffmpeg is not found: {$this->ffmpegBin}"); |
|
24
|
|
|
|
|
25
|
|
|
if (!is_executable($this->ffmpegBin)) |
|
|
|
|
|
|
26
|
|
|
throw new ErrorException("ffmpeg is not executable: {$this->ffmpegBin}"); |
|
27
|
|
|
|
|
28
|
|
|
if (!is_file($videoSourceFilename)) |
|
29
|
|
|
throw new ErrorException('File not found on disk.'); |
|
30
|
|
|
|
|
31
|
|
|
$this->videoSourceFilename = $videoSourceFilename; |
|
32
|
|
|
$this->outputImageFilename = $outputImageFilename; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @throws ErrorException |
|
37
|
|
|
*/ |
|
38
|
|
|
public function extract() |
|
39
|
|
|
{ |
|
40
|
|
|
$command = "{$this->ffmpegBin} -i {$this->videoSourceFilename} -ss 00:00:05.000 -vframes 1 {$this->outputImageFilename}"; |
|
41
|
|
|
exec($command, $out, $result); |
|
42
|
|
|
if (is_file($this->outputImageFilename)) { |
|
43
|
|
|
return true; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$command = "{$this->ffmpegBin} -i {$this->videoSourceFilename} -ss 00:00:03.000 -vframes 1 {$this->outputImageFilename}"; |
|
47
|
|
|
exec($command, $out, $result); |
|
48
|
|
|
if (is_file($this->outputImageFilename)) { |
|
49
|
|
|
return true; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
$command = "{$this->ffmpegBin} -i {$this->videoSourceFilename} -ss 00:00:01.000 -vframes 1 {$this->outputImageFilename}"; |
|
54
|
|
|
exec($command, $out, $result); |
|
55
|
|
|
if (is_file($this->outputImageFilename)) { |
|
56
|
|
|
return true; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
throw new ErrorException('FFmpeg frame extracting fail:' . print_r($out, true)); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.