1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Soluble\MediaTools\Video\Config; |
6
|
|
|
|
7
|
|
|
use Soluble\MediaTools\Common\Process\ProcessParamsInterface; |
8
|
|
|
use Soluble\MediaTools\Video\Adapter\AdapterInterface; |
9
|
|
|
use Soluble\MediaTools\Video\Adapter\FFMpegAdapter; |
10
|
|
|
use Soluble\MediaTools\Video\ProcessParams; |
11
|
|
|
|
12
|
|
|
class FFMpegConfig implements FFMpegConfigInterface |
13
|
|
|
{ |
14
|
|
|
public const DEFAULT_BINARY = 'ffmpeg'; |
15
|
|
|
public const DEFAULT_THREADS = null; |
16
|
|
|
public const DEFAULT_TIMEOUT = null; |
17
|
|
|
public const DEFAULT_IDLE_TIMEOUT = null; |
18
|
|
|
public const DEFAULT_ENV = []; |
19
|
|
|
|
20
|
|
|
/** @var string */ |
21
|
|
|
protected $binary; |
22
|
|
|
|
23
|
|
|
/** @var int|null */ |
24
|
|
|
protected $threads; |
25
|
|
|
|
26
|
|
|
/** @var FFMpegAdapter */ |
27
|
|
|
protected $ffmpegAdapter; |
28
|
|
|
|
29
|
|
|
/** @var ProcessParams */ |
30
|
|
|
protected $processParams; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param string $ffmpegBinary |
34
|
|
|
* @param int|null $threads number fo threads used for conversion, null means single threads, 0 all cores, .... |
35
|
|
|
* @param float|null $timeout max allowed time (in seconds) for conversion, null for no timeout |
36
|
|
|
* @param float|null $idleTimeout max allowed idle time (in seconds) for conversion, null for no timeout |
37
|
|
|
* @param array<string, string|int> $env An array of additional env vars to set when running the ffmpeg conversion process |
38
|
|
|
*/ |
39
|
|
|
public function __construct( |
40
|
|
|
string $ffmpegBinary = self::DEFAULT_BINARY, |
41
|
|
|
?int $threads = self::DEFAULT_THREADS, |
42
|
|
|
?float $timeout = self::DEFAULT_TIMEOUT, |
43
|
|
|
?float $idleTimeout = self::DEFAULT_IDLE_TIMEOUT, |
44
|
|
|
array $env = self::DEFAULT_ENV |
45
|
|
|
) { |
46
|
|
|
$this->binary = $ffmpegBinary; |
|
|
|
|
47
|
|
|
$this->threads = $threads; |
|
|
|
|
48
|
|
|
|
49
|
|
|
$this->processParams = new ProcessParams( |
50
|
|
|
$timeout, |
51
|
|
|
$idleTimeout, |
52
|
|
|
$env |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getBinary(): string |
57
|
|
|
{ |
58
|
|
|
return $this->binary; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getThreads(): ?int |
62
|
|
|
{ |
63
|
|
|
return $this->threads; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getProcessParams(): ProcessParamsInterface |
67
|
|
|
{ |
68
|
|
|
return $this->processParams; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return FFMpegAdapter |
73
|
|
|
*/ |
74
|
|
|
public function getAdapter(): AdapterInterface |
75
|
|
|
{ |
76
|
|
|
if ($this->ffmpegAdapter === null) { |
77
|
|
|
$this->ffmpegAdapter = new FFMpegAdapter($this); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $this->ffmpegAdapter; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.