-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PS-670-rendition-video_enhance3 (#494)
* more "twigable" options * almost every "time" options supports float (2.5) or timecode ("00.00.02.50") * video-summary module can generate "phraseanet" animated gif - period sets the gap between frames from the _input video_, e.g. `"{{ input.duration/10 }}"` -> 10 frames extracted. - duration sets the duration in seconds of each frame into the _output animated gif_, e.g. `0.1` -> 10 frames / seconds. * video-summary module supports `start` * ffmpeg module can extract audio: set `format: "audio-wav"` or `audio-mp3`, `audio-aac` ; todo: audio options * ffmpeg module / filter "watermark" supports `path: <url>` * bypass ffmpeg bugs (timecode / seconds) * fix attributes access in twig : use `"{{ attr.myfield }}"` where `myfield` is the *slugified* attribute name * new cli `app:documentation:dump` to generate doc * documentation & config validator as services, used by databox. * allow empty definition * move video output "formats" documentation to each related transformer module.
- Loading branch information
Showing
44 changed files
with
1,662 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Command; | ||
|
||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Alchemy\RenditionFactory\RenditionBuilderConfigurationDocumentation; | ||
|
||
|
||
#[AsCommand('app:documentation:dump')] | ||
class DocumentationDumperCommand extends Command | ||
{ | ||
public function __construct( | ||
private readonly RenditionBuilderConfigurationDocumentation $renditionBuilderConfigurationDocumentation, | ||
) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$output->writeln('# ' . $this->renditionBuilderConfigurationDocumentation::getName()); | ||
$output->writeln($this->renditionBuilderConfigurationDocumentation->generate()); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
databox/api/src/Validator/ValidRenditionDefinitionConstraint.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Validator; | ||
|
||
use Symfony\Component\Validator\Constraint; | ||
|
||
/** @uses ValidRenditionDefinitionConstraintValidator */ | ||
#[\Attribute] | ||
class ValidRenditionDefinitionConstraint extends Constraint | ||
{ | ||
public function getTargets(): string|array | ||
{ | ||
return self::PROPERTY_CONSTRAINT; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
databox/api/src/Validator/ValidRenditionDefinitionConstraintValidator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Validator; | ||
|
||
use Alchemy\RenditionFactory\Config\BuildConfigValidator; | ||
use Alchemy\RenditionFactory\Config\YamlLoader; | ||
use Symfony\Component\Validator\Constraint; | ||
use Symfony\Component\Validator\ConstraintValidator; | ||
|
||
class ValidRenditionDefinitionConstraintValidator extends ConstraintValidator | ||
{ | ||
/** @uses BuildConfigValidator */ | ||
public function __construct(private readonly YamlLoader $yamlLoader, private readonly BuildConfigValidator $validator) | ||
{ | ||
} | ||
|
||
/** | ||
* @param string $value | ||
* @param ValidRenditionDefinitionConstraint $constraint | ||
*/ | ||
public function validate($value, Constraint $constraint): void | ||
{ | ||
if(!$value) { | ||
return; | ||
} | ||
try { | ||
$config = $this->yamlLoader->parse($value); | ||
$this->validator->validate($config); | ||
} catch (\Exception $e) { | ||
$this->context | ||
->buildViolation($e->getMessage()) | ||
->addViolation(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
lib/php/rendition-factory/src/Command/ConfigurationValidateCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Alchemy\RenditionFactory\Command; | ||
|
||
use Alchemy\RenditionFactory\Config\BuildConfigValidator; | ||
use Alchemy\RenditionFactory\Config\YamlLoader; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
#[AsCommand('alchemy:rendition-factory:conf:validate')] | ||
class ConfigurationValidateCommand extends Command | ||
{ | ||
public function __construct( | ||
private readonly YamlLoader $yamlLoader, | ||
private readonly BuildConfigValidator $validator, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
parent::configure(); | ||
|
||
$this->addArgument('config', InputArgument::REQUIRED, 'A build config YAML file to validate') | ||
->setHelp('Validate a config file.') | ||
; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$config = $this->yamlLoader->load($input->getArgument('config')); | ||
$this->validator->validate($config); | ||
|
||
$output->writeln('Configuration is valid.'); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
lib/php/rendition-factory/src/Config/BuildConfigValidator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Alchemy\RenditionFactory\Config; | ||
|
||
use Alchemy\RenditionFactory\DTO\BuildConfig\BuildConfig; | ||
use Alchemy\RenditionFactory\DTO\FamilyEnum; | ||
use Alchemy\RenditionFactory\Transformer\TransformerModuleInterface; | ||
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; | ||
use Symfony\Component\Config\Definition\Processor; | ||
use Symfony\Component\DependencyInjection\Attribute\TaggedLocator; | ||
use Symfony\Component\DependencyInjection\ServiceLocator; | ||
|
||
readonly class BuildConfigValidator | ||
{ | ||
public function __construct( | ||
#[TaggedLocator(TransformerModuleInterface::TAG, defaultIndexMethod: 'getName')] | ||
private ServiceLocator $transformers, | ||
) { | ||
} | ||
|
||
public function getTransformers(): ServiceLocator | ||
{ | ||
return $this->transformers; | ||
} | ||
|
||
public function validate(BuildConfig $config): void | ||
{ | ||
foreach (FamilyEnum::cases() as $family) { | ||
$familyConfig = $config->getFamily($family); | ||
if (null === $familyConfig) { | ||
continue; | ||
} | ||
foreach ($familyConfig->getTransformations() as $transformation) { | ||
$transformerName = $transformation->getModule(); | ||
|
||
/** @var TransformerModuleInterface $transformer */ | ||
$transformer = $this->transformers->get($transformerName); | ||
|
||
try { | ||
$this->checkTransformerConfiguration($transformer, $transformation->toArray()); | ||
} catch (\Throwable $e) { | ||
$msg = sprintf("Error in module \"%s\"\n%s", $transformerName, $e->getMessage()); | ||
throw new InvalidConfigurationException($msg); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private function checkTransformerConfiguration(TransformerModuleInterface $transformer, array $options): void | ||
{ | ||
$documentation = $transformer->getDocumentation(); | ||
$treeBuilder = $documentation->getTreeBuilder(); | ||
|
||
$processor = new Processor(); | ||
$processor->process($treeBuilder->buildTree(), ['root' => $options]); | ||
} | ||
} |
Oops, something went wrong.