diff --git a/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php b/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php index 1a782400ad..a3db77e635 100644 --- a/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php +++ b/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php @@ -67,6 +67,20 @@ class FilesystemService return $pathdest . $this->generateSubdefFilename($record, $subdef); } + public function generateTemporarySubdefPathname(\record_adapter $record, \databox_subdef $subdef, $tmpDir) + { + $tmpDir = \p4string::addEndSlash($tmpDir); + $ffmpegDir = $tmpDir."ffmpeg/"; + + if(!is_dir($ffmpegDir)){ + $this->filesystem->mkdir($ffmpegDir); + } + + $filenameSufix = $this->generateSubdefFilename($record, $subdef); + + return $ffmpegDir . hash('sha256', $filenameSufix) . $filenameSufix; + } + /** * @param RecordInterface $record * @param string|\SplFileInfo $source diff --git a/lib/Alchemy/Phrasea/Media/SubdefGenerator.php b/lib/Alchemy/Phrasea/Media/SubdefGenerator.php index c60c4d3b7b..037b3d8f51 100644 --- a/lib/Alchemy/Phrasea/Media/SubdefGenerator.php +++ b/lib/Alchemy/Phrasea/Media/SubdefGenerator.php @@ -22,6 +22,7 @@ use Alchemy\Phrasea\Filesystem\FilesystemService; use Alchemy\Phrasea\Media\Subdef\Specification\PdfSpecification; use MediaAlchemyst\Alchemyst; use MediaAlchemyst\Specification\Image; +use MediaAlchemyst\Specification\Video; use MediaVorus\MediaVorus; use MediaAlchemyst\Exception\ExceptionInterface as MediaAlchemystException; use Neutron\TemporaryFilesystem\Manager; @@ -173,6 +174,14 @@ class SubdefGenerator return; } + $tmpDir = $this->app['conf']->get(['main', 'storage', 'tmp_files']); + $destFile = null; + + if($subdef_class->getSpecs() instanceof Video && !empty($tmpDir)){ + $destFile = $pathdest; + $pathdest = $this->filesystem->generateTemporarySubdefPathname($record, $subdef_class, $tmpDir); + } + if (isset($this->tmpFilePath) && $subdef_class->getSpecs() instanceof Image) { $this->alchemyst->turnInto($this->tmpFilePath, $pathdest, $subdef_class->getSpecs()); @@ -187,6 +196,11 @@ class SubdefGenerator } + if($destFile){ + $this->filesystem->copy($pathdest, $destFile); + $this->app['filesystem']->remove($pathdest); + } + } catch (MediaAlchemystException $e) { $this->logger->error(sprintf('Subdef generation failed for record %d with message %s', $record->getRecordId(), $e->getMessage())); }