Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PS-670 rendition video enhance1 #468

Merged
merged 16 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion infra/docker/dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ RUN apk add --no-cache \
mysql-dev \
postgresql-dev \
zlib \
libreoffice \
ffmpeg \
libreoffice \
imagemagick \
rabbitmq-c-dev \
bash \
Expand Down
2 changes: 1 addition & 1 deletion lib/php/admin-bundle/Field/YamlField.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Alchemy\AdminBundle\Field;

use Alchemy\AdminBundle\Form\YamlType;
use EasyCorp\Bundle\EasyAdminBundle\Field\FieldTrait;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface;
use EasyCorp\Bundle\EasyAdminBundle\Field\FieldTrait;

final class YamlField implements FieldInterface
{
Expand Down
12 changes: 6 additions & 6 deletions lib/php/admin-bundle/Form/JsonType.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public function transform(mixed $value)

public function reverseTransform(mixed $value)
{
if ($value !== null && json_validate($value) === false) {
return ['input-error' => 'Invalid JSON: ' . json_last_error_msg()];
if (null !== $value && false === json_validate($value)) {
return ['input-error' => 'Invalid JSON: '.json_last_error_msg()];
}

return json_decode($value, true, 512, JSON_THROW_ON_ERROR);
Expand All @@ -36,7 +36,7 @@ public function reverseTransform(mixed $value)
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'attr'=> [
'attr' => [
'rows' => 10,
'style' => 'font-family: "Courier New"',
],
Expand All @@ -48,9 +48,9 @@ function (mixed $data, ExecutionContextInterface $context) {
->buildViolation($data['input-error'])
->addViolation();
}
}
)
]
}
),
],
]);
}

Expand Down
16 changes: 8 additions & 8 deletions lib/php/admin-bundle/Form/YamlType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

namespace Alchemy\AdminBundle\Form;

use Symfony\Component\Yaml\Yaml;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Yaml;

class YamlType extends AbstractType
class YamlType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'attr'=> [
'attr' => [
'rows' => 10,
'style' => 'font-family: "Courier New"',
],
Expand All @@ -31,9 +31,9 @@ function (mixed $data, ExecutionContextInterface $context) {
->buildViolation(sprintf('YAML error: %s', $e->getMessage()))
->addViolation();
}
}
)
]
}
),
],
]);
}

Expand Down
48 changes: 48 additions & 0 deletions lib/php/rendition-factory-bundle/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ services:
tags:
- { name: !php/const Alchemy\RenditionFactory\Transformer\TransformerModuleInterface::TAG }

Alchemy\RenditionFactory\Transformer\Video\VideoToFrameTransformerModule:
tags:
- { name: !php/const Alchemy\RenditionFactory\Transformer\TransformerModuleInterface::TAG }

Alchemy\RenditionFactory\Transformer\Video\VideoToAnimationTransformerModule:
tags:
- { name: !php/const Alchemy\RenditionFactory\Transformer\TransformerModuleInterface::TAG }

Alchemy\RenditionFactory\Transformer\Document\DocumentToPdfTransformerModule:
tags:
- { name: !php/const Alchemy\RenditionFactory\Transformer\TransformerModuleInterface::TAG }
Expand All @@ -36,7 +44,47 @@ services:
tags:
- { name: !php/const Alchemy\RenditionFactory\Transformer\TransformerModuleInterface::TAG }

# FFMpeg "formats"
Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format\JpegFormat:
tags:
- { name: !php/const Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format\FormatInterface::TAG }

Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format\MkvFormat:
tags:
- { name: !php/const Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format\FormatInterface::TAG }

Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format\Mpeg4Format:
tags:
- { name: !php/const Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format\FormatInterface::TAG }

Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format\MpegFormat:
tags:
- { name: !php/const Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format\FormatInterface::TAG }

Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format\QuicktimeFormat:
tags:
- { name: !php/const Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format\FormatInterface::TAG }

Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format\WebmFormat:
tags:
- { name: !php/const Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format\FormatInterface::TAG }

Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format\AnimatedGifFormat:
tags:
- { name: !php/const Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format\FormatInterface::TAG }

Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format\AnimatedPngFormat:
tags:
- { name: !php/const Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format\FormatInterface::TAG }

Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format\AnimatedWebpFormat:
tags:
- { name: !php/const Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format\FormatInterface::TAG }


Imagine\Imagick\Imagine: ~
Imagine\Image\ImagineInterface: '@Imagine\Imagick\Imagine'

Alchemy\RenditionFactory\MimeType\MimeTypeGuesser: ~
Alchemy\RenditionFactory\Format\FormatGuesser: ~
Alchemy\RenditionFactory\Format\FormatFactory: ~
15 changes: 9 additions & 6 deletions lib/php/rendition-factory/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.3/phpunit.xsd" backupGlobals="false" colors="true" cacheDirectory=".phpunit.cache">
<php>
<ini name="error_reporting" value="-1"/>
<server name="SHELL_VERBOSITY" value="-1"/>
Expand All @@ -16,4 +11,12 @@
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<file>tests/AbstractTest.php</file>
</exclude>
</source>
</phpunit>
10 changes: 7 additions & 3 deletions lib/php/rendition-factory/src/Command/CreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function configure(): void

$this->addArgument('src', InputArgument::REQUIRED, 'The source file');
$this->addArgument('build-config', InputArgument::REQUIRED, 'The build config YAML file');
$this->addOption('type', 't', InputOption::VALUE_OPTIONAL, 'Force the MIME type of file');
$this->addOption('type', 't', InputOption::VALUE_REQUIRED, 'Force the MIME type of file');
$this->addOption('working-dir', 'w', InputOption::VALUE_REQUIRED, 'The working directory. Defaults to system temp directory');
$this->addOption('output', 'o', InputOption::VALUE_REQUIRED, 'The output file name WITHOUT extension');
$this->addOption('debug', 'd', InputOption::VALUE_NONE, 'set to debug mode (keep files in working directory)');
Expand Down Expand Up @@ -72,13 +72,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$buildConfig,
$options
);
$output->writeln(sprintf('Rendition created: %s', $outputFile->getPath()));

} catch (\InvalidArgumentException $e) {
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));

return 1;
}

if ($outputPath = $input->getOption('output')) {
if ('/' === substr($outputPath, -1)) {
// a directory is specified, use the filename of the source
$outputPath .= pathinfo($src, PATHINFO_FILENAME);
}
@mkdir(dirname($outputPath), 0755, true);
$outputPath .= '.'.$outputFile->getExtension();
rename($outputFile->getPath(), $outputPath);
Expand All @@ -91,8 +97,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}

$output->writeln(sprintf('Rendition created: %s', $outputFile->getPath()));

if (!$input->getOption('debug')) {
$this->renditionCreator->cleanUp();
}
Expand Down
4 changes: 3 additions & 1 deletion lib/php/rendition-factory/src/Config/YamlLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ private function parseFamilyConfig(array $data): FamilyBuildConfig

$transformations = [];
foreach ($data['transformations'] as $transformation) {
$transformations[] = $this->parseTransformation($transformation);
if ($transformation['enabled'] ?? true) {
$transformations[] = $this->parseTransformation($transformation);
}
}

return new FamilyBuildConfig($transformations, $data['normalization'] ?? []);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format;

use Alchemy\RenditionFactory\DTO\FamilyEnum;

class AnimatedGifFormat implements FormatInterface
{
public static function getAllowedExtensions(): array
{
return ['gif'];
}

public static function getMimeType(): string
{
return 'image/gif';
}

public static function getFormat(): string
{
return 'animated-gif';
}

public static function getFamily(): FamilyEnum
{
return FamilyEnum::Animation;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format;

use Alchemy\RenditionFactory\DTO\FamilyEnum;

class AnimatedPngFormat implements FormatInterface
{
public static function getAllowedExtensions(): array
{
return ['apng', 'png'];
}

public static function getMimeType(): string
{
return 'image/apng';
}

public static function getFormat(): string
{
return 'animated-png';
}

public static function getFamily(): FamilyEnum
{
return FamilyEnum::Animation;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format;

use Alchemy\RenditionFactory\DTO\FamilyEnum;

class AnimatedWebpFormat implements FormatInterface
{
public static function getAllowedExtensions(): array
{
return ['webp'];
}

public static function getMimeType(): string
{
return 'image/webp';
}

public static function getFormat(): string
{
return 'animated-webp';
}

public static function getFamily(): FamilyEnum
{
return FamilyEnum::Animation;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format;

use Alchemy\RenditionFactory\DTO\FamilyEnum;

interface FormatInterface
{
final public const TAG = 'alchemy_rendition_factory.ffmpeg_format';

public static function getAllowedExtensions(): array;

public static function getMimeType(): string;

public static function getFormat(): string;

public static function getFamily(): FamilyEnum;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Alchemy\RenditionFactory\Transformer\Video\FFMpeg\Format;

use Alchemy\RenditionFactory\DTO\FamilyEnum;

class JpegFormat implements FormatInterface
{
public static function getAllowedExtensions(): array
{
return ['jpg', 'jpeg'];
}

public static function getMimeType(): string
{
return 'image/jpeg';
}

public static function getFormat(): string
{
return 'image-jpeg';
4rthem marked this conversation as resolved.
Show resolved Hide resolved
}

public static function getFamily(): FamilyEnum
{
return FamilyEnum::Image;
}
}
Loading
Loading