|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @see https://github.com/soluble-io/soluble-mediatools for the canonical repository |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright Copyright (c) 2018-2020 Sébastien Vanvelthem. (https://github.com/belgattitude) |
|
9
|
|
|
* @license https://github.com/soluble-io/soluble-mediatools/blob/master/LICENSE.md MIT |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Soluble\MediaTools\Video\Config; |
|
13
|
|
|
|
|
14
|
|
|
use Soluble\MediaTools\Common\Process\ProcessParamsInterface; |
|
15
|
|
|
use Soluble\MediaTools\Video\Adapter\ConverterAdapterInterface; |
|
16
|
|
|
use Soluble\MediaTools\Video\Adapter\FFMpegAdapter; |
|
17
|
|
|
use Soluble\MediaTools\Video\Process\ProcessParams; |
|
18
|
|
|
|
|
19
|
|
|
final class FFMpegConfig implements FFMpegConfigInterface |
|
20
|
|
|
{ |
|
21
|
|
|
public const DEFAULT_THREADS = null; |
|
22
|
|
|
public const DEFAULT_TIMEOUT = null; |
|
23
|
|
|
public const DEFAULT_IDLE_TIMEOUT = null; |
|
24
|
|
|
public const DEFAULT_ENV = []; |
|
25
|
|
|
|
|
26
|
|
|
/** @var string */ |
|
27
|
|
|
private $binary; |
|
28
|
|
|
|
|
29
|
|
|
/** @var int|null */ |
|
30
|
|
|
private $threads; |
|
31
|
|
|
|
|
32
|
|
|
/** @var FFMpegAdapter|null */ |
|
33
|
|
|
private $ffmpegAdapter; |
|
34
|
|
|
|
|
35
|
|
|
/** @var ProcessParams */ |
|
36
|
|
|
private $processParams; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param string|null $ffmpegBinary if null will return 'ffmpeg' on linux, 'ffmpeg.exe' on windows |
|
40
|
|
|
* @param int|null $threads number fo threads used for conversion, null means single threads, 0 all cores, .... |
|
41
|
|
|
* @param float|null $timeout max allowed time (in seconds) for conversion, null for no timeout |
|
42
|
|
|
* @param float|null $idleTimeout max allowed idle time (in seconds) for conversion, null for no timeout |
|
43
|
|
|
* @param array<string, string|int> $env An array of additional env vars to set when running the ffmpeg conversion process |
|
44
|
|
|
*/ |
|
45
|
55 |
|
public function __construct( |
|
46
|
|
|
?string $ffmpegBinary = null, |
|
47
|
|
|
?int $threads = self::DEFAULT_THREADS, |
|
48
|
|
|
?float $timeout = self::DEFAULT_TIMEOUT, |
|
49
|
|
|
?float $idleTimeout = self::DEFAULT_IDLE_TIMEOUT, |
|
50
|
|
|
array $env = self::DEFAULT_ENV |
|
51
|
|
|
) { |
|
52
|
55 |
|
$this->binary = $ffmpegBinary ?? self::getPlatformDefaultBinary(); |
|
53
|
|
|
|
|
54
|
55 |
|
$this->threads = $threads; |
|
55
|
|
|
|
|
56
|
55 |
|
$this->processParams = new ProcessParams( |
|
57
|
55 |
|
$timeout, |
|
58
|
|
|
$idleTimeout, |
|
59
|
|
|
$env |
|
60
|
|
|
); |
|
61
|
55 |
|
} |
|
62
|
|
|
|
|
63
|
3 |
|
public static function getPlatformDefaultBinary(): string |
|
64
|
|
|
{ |
|
65
|
3 |
|
return (DIRECTORY_SEPARATOR === '\\') ? 'ffmpeg.exe' : 'ffmpeg'; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
38 |
|
public function getBinary(): string |
|
69
|
|
|
{ |
|
70
|
38 |
|
return $this->binary; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
29 |
|
public function getThreads(): ?int |
|
74
|
|
|
{ |
|
75
|
29 |
|
return $this->threads; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
31 |
|
public function getProcessParams(): ProcessParamsInterface |
|
79
|
|
|
{ |
|
80
|
31 |
|
return $this->processParams; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @return FFMpegAdapter |
|
85
|
|
|
*/ |
|
86
|
36 |
|
public function getAdapter(): ConverterAdapterInterface |
|
87
|
|
|
{ |
|
88
|
36 |
|
if ($this->ffmpegAdapter === null) { |
|
89
|
36 |
|
$this->ffmpegAdapter = new FFMpegAdapter($this); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
36 |
|
return $this->ffmpegAdapter; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|