|
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 Psr\Container\ContainerInterface; |
|
15
|
|
|
use Soluble\MediaTools\Common\Config\ContainerConfigLocator; |
|
16
|
|
|
use Soluble\MediaTools\Common\Config\SafeConfigReader; |
|
17
|
|
|
use Soluble\MediaTools\Common\Exception\InvalidConfigException; |
|
18
|
|
|
|
|
19
|
|
|
final class FFMpegConfigFactory |
|
20
|
|
|
{ |
|
21
|
|
|
public const DEFAULT_ENTRY_NAME = 'config'; |
|
22
|
|
|
public const DEFAULT_CONFIG_KEY = 'soluble-mediatools'; |
|
23
|
|
|
|
|
24
|
|
|
/** @var string */ |
|
25
|
|
|
private $entryName; |
|
26
|
|
|
|
|
27
|
|
|
/** @var null|string */ |
|
28
|
|
|
private $configKey; |
|
29
|
|
|
|
|
30
|
47 |
|
public function __construct( |
|
31
|
|
|
string $entryName = self::DEFAULT_ENTRY_NAME, |
|
32
|
|
|
?string $configKey = self::DEFAULT_CONFIG_KEY |
|
33
|
|
|
) { |
|
34
|
47 |
|
$this->entryName = $entryName; |
|
35
|
47 |
|
$this->configKey = $configKey; |
|
36
|
47 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @throws InvalidConfigException |
|
40
|
|
|
*/ |
|
41
|
47 |
|
public function __invoke(ContainerInterface $container): FFMpegConfigInterface |
|
42
|
|
|
{ |
|
43
|
47 |
|
$config = (new ContainerConfigLocator($container, $this->entryName))->getConfig($this->configKey); |
|
44
|
|
|
|
|
45
|
45 |
|
$scr = new SafeConfigReader($config, $this->configKey ?? ''); |
|
46
|
|
|
|
|
47
|
45 |
|
return new FFMpegConfig( |
|
48
|
45 |
|
$scr->getNullableString('ffmpeg.binary', null), |
|
49
|
44 |
|
$scr->getNullableInt('ffmpeg.threads', FFMpegConfig::DEFAULT_THREADS), |
|
50
|
44 |
|
$scr->getNullableFloat('ffmpeg.timeout', FFMpegConfig::DEFAULT_TIMEOUT), |
|
51
|
44 |
|
$scr->getNullableFloat('ffmpeg.idle_timeout', FFMpegConfig::DEFAULT_IDLE_TIMEOUT), |
|
52
|
44 |
|
$scr->getArray('ffmpeg.env', FFMpegConfig::DEFAULT_ENV) |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|