Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
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
19 changes: 19 additions & 0 deletions lib/Video/Adapter/Ffmpeg.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class Ffmpeg extends Adapter
*/
protected $arguments = [];

/**
* @var array
*/
private $tmpFiles = [];

/**
* @return bool
*/
Expand Down Expand Up @@ -72,6 +77,16 @@ public static function getFfmpegCli()
*/
public function load($file)
{
if (!stream_is_local($file)) {
// Create local copy of remote file
$tmpFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . '/ffmpeg-tmp-' . uniqid() . '.' . File::getFileExtension($file);
recursiveCopy($file, $tmpFile);

$file = $tmpFile;

$this->tmpFiles[] = $tmpFile;
}

$this->file = $file;
$this->setProcessId(uniqid());

Expand Down Expand Up @@ -229,6 +244,10 @@ public function destroy()
Logger::debug("FFMPEG finished, last message was: \n" . file_get_contents($this->getConversionLogFile()));
$this->deleteConversionLogFile();
}

foreach ($this->tmpFiles as $tmpFile) {
@unlink($tmpFile);
}
}

public function deleteConversionLogFile()
Expand Down
4 changes: 2 additions & 2 deletions lib/helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,14 +455,14 @@ function recursiveCopy($source, $destination)
if ($item->isDir()) {
\Pimcore\File::mkdir($destination . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
} else {
copy($item, $destination . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
copy($item, $destination . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), \Pimcore\File::getContext());
}
}
} elseif (is_file($source)) {
if (is_dir(dirname($destination))) {
\Pimcore\File::mkdir(dirname($destination));
}
copy($source, $destination);
copy($source, $destination, \Pimcore\File::getContext());
}

return true;
Expand Down
8 changes: 6 additions & 2 deletions models/Asset/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ protected function getDurationFromBackend(?string $filePath = null)
$converter = \Pimcore\Video::getInstance();
$converter->load($filePath);

return $converter->getDuration();
$duration = $converter->getDuration();
$converter->destroy();
return $duration;
}

return null;
Expand All @@ -210,7 +212,9 @@ protected function getDimensionsFromBackend()
$converter = \Pimcore\Video::getInstance();
$converter->load($this->getFileSystemPath());

return $converter->getDimensions();
$dimensions = $converter->getDimensions();
$converter->destroy();
return $dimensions;
}

return null;
Expand Down
17 changes: 17 additions & 0 deletions models/Asset/Video/ImageThumbnail.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,23 @@ public function generate()
Model\Tool\Lock::release($lockKey);
}

$converter->destroy();

if ($this->getConfig()) {
$this->getConfig()->setFilenameSuffix('time-' . $timeOffset);

try {
// The path can be remote. In that case, the processor will create a local copy of the asset, which is the video itself.
// That is not what is intended, as we are tying to generate a thumbnail based on the already existing video still that
// the converter created earlier. To prevent the processor from doing that, we will create a local copy here if needed
$tmpFile = null;
if (!stream_is_local($path)) {
$tmpFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . '/video-thumbnail-' . uniqid() . '.png';

recursiveCopy($path, $tmpFile);
$path = $tmpFile;
}

$path = Image\Thumbnail\Processor::process(
$this->asset,
$this->getConfig(),
Expand All @@ -188,6 +201,10 @@ public function generate()
true,
$generated
);

if ($tmpFile) {
@unlink($tmpFile);
}
} catch (\Exception $e) {
Logger::error("Couldn't create image-thumbnail of video " . $this->asset->getRealFullPath());
Logger::error($e);
Expand Down