function waitTillFinished($videoId, $thumbnail) { $finished = false; // initial delay $video = Asset::getById($videoId); $thumb = $video->getThumbnail($thumbnail); if ($thumb["status"] != "finished") { sleep(20); } while (!$finished) { \Pimcore::collectGarbage(); $video = Asset::getById($videoId); $thumb = $video->getThumbnail($thumbnail); if ($thumb["status"] == "finished") { $finished = true; \Logger::debug("video [" . $video->getId() . "] FINISHED"); } else { if ($thumb["status"] == "inprogress") { $progress = Asset\Video\Thumbnail\Processor::getProgress($thumb["processId"]); \Logger::debug("video [" . $video->getId() . "] in progress: " . number_format($progress, 0) . "%"); sleep(5); } else { // error \Logger::debug("video [" . $video->getId() . "] has status: '" . $thumb["status"] . "' -> skipping"); break; } } } }
public function getAssetCode($inAdmin = false) { $asset = Asset::getById($this->id); $options = $this->getOptions(); // compatibility mode when FFMPEG is not present or no thumbnail config is given if (!\Pimcore\Video::isAvailable() || !$options["thumbnail"]) { if ($asset instanceof Asset && preg_match("/\\.(f4v|flv|mp4)/", $asset->getFullPath())) { return $this->getHtml5Code(array("mp4" => (string) $asset)); } return $this->getErrorCode("Asset is not a video, or missing thumbnail configuration"); } if ($asset instanceof Asset\Video && $options["thumbnail"]) { $thumbnail = $asset->getThumbnail($options["thumbnail"]); if ($thumbnail) { if (!array_key_exists("imagethumbnail", $options) || empty($options["imagethumbnail"])) { // try to get the dimensions out ouf the video thumbnail $imageThumbnailConf = $asset->getThumbnailConfig($options["thumbnail"])->getEstimatedDimensions(); $imageThumbnailConf["format"] = "JPEG"; } else { $imageThumbnailConf = $options["imagethumbnail"]; } if (empty($imageThumbnailConf)) { $imageThumbnailConf["width"] = 800; $imageThumbnailConf["format"] = "JPEG"; } if ($this->poster && ($poster = Asset::getById($this->poster))) { $image = $poster->getThumbnail($imageThumbnailConf); } else { if ($asset->getCustomSetting("image_thumbnail_asset")) { $image = $asset->getImageThumbnail($imageThumbnailConf); } else { if ($thumbnail["status"] == "finished" && (array_key_exists("animatedGifPreview", $options) && $options["animatedGifPreview"] !== false)) { $image = $asset->getPreviewAnimatedGif(null, null, $imageThumbnailConf); } else { $image = $asset->getImageThumbnail($imageThumbnailConf); } } } if ($inAdmin && isset($options["editmodeImagePreview"]) && $options["editmodeImagePreview"]) { $code = '<div id="pimcore_video_' . $this->getName() . '" class="pimcore_tag_video">'; $code .= '<img width="' . $this->getWidth() . '" src="' . $image . '" />'; $code .= '</div'; return $code; } if ($thumbnail["status"] == "finished") { return $this->getHtml5Code($thumbnail["formats"], $image); } else { if ($thumbnail["status"] == "inprogress") { // disable the output-cache if enabled $front = \Zend_Controller_Front::getInstance(); $front->unregisterPlugin("Pimcore\\Controller\\Plugin\\Cache"); $progress = Asset\Video\Thumbnail\Processor::getProgress($thumbnail["processId"]); return $this->getProgressCode($progress, $image); } else { return $this->getErrorCode("The video conversion failed, please see the debug.log for more details."); } } } else { return $this->getErrorCode("The given thumbnail doesn't exist: '" . $options["thumbnail"] . "'"); } } }
<?php /** * Pimcore * * LICENSE * * This source file is subject to the new BSD license that is bundled * with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://www.pimcore.org/license * * @copyright Copyright (c) 2009-2014 pimcore GmbH (http://www.pimcore.org) * @license http://www.pimcore.org/license New BSD License */ chdir(__DIR__); include_once "startup.php"; use Pimcore\Model\Asset; Asset\Video\Thumbnail\Processor::execute($argv[1]);
} </style> </head> <body> <table id="wrapper" width="100%" height="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td class="error" align="center" valign="center"> <?php if ($this->thumbnail && $this->thumbnail["status"] == "inprogress") { ?> <?php $progress = \Pimcore\Model\Asset\Video\Thumbnail\Processor::getProgress($this->thumbnail["processId"]); ?> <style type="text/css"> .pimcore_tag_video_progress { position:relative; background:#555 url(<?php echo $this->asset->getImageThumbnail(array("width" => 640)); ?> ) no-repeat center center; font-family:Arial,Verdana,sans-serif; color:#fff; text-shadow: 0 0 3px #000, 0 0 5px #000, 0 0 1px #000; } .pimcore_tag_video_progress_status { font-size:16px;
protected function execute(InputInterface $input, OutputInterface $output) { Asset\Video\Thumbnail\Processor::execute($input->getArgument("processId")); }
/** * Returns a path to a given thumbnail or an thumbnail configuration * * @param mixed * @return string */ public function getThumbnail($thumbnailName, $onlyFormats = array()) { $thumbnail = $this->getThumbnailConfig($thumbnailName); if ($thumbnail) { try { Video\Thumbnail\Processor::process($this, $thumbnail, $onlyFormats); // check for existing videos $customSetting = $this->getCustomSetting("thumbnails"); if (is_array($customSetting) && array_key_exists($thumbnail->getName(), $customSetting)) { return $customSetting[$thumbnail->getName()]; } } catch (\Exception $e) { \Logger::error("Couldn't create thumbnail of video " . $this->getFullPath()); \Logger::error($e); } } return null; }
/** * Returns a path to a given thumbnail or an thumbnail configuration * * @param mixed * @return string */ public function getThumbnail($thumbnailName, $onlyFormats = []) { $thumbnail = $this->getThumbnailConfig($thumbnailName); if ($thumbnail) { try { Video\Thumbnail\Processor::process($this, $thumbnail, $onlyFormats); // check for existing videos $customSetting = $this->getCustomSetting("thumbnails"); if (is_array($customSetting) && array_key_exists($thumbnail->getName(), $customSetting)) { foreach ($customSetting[$thumbnail->getName()]["formats"] as &$path) { $fullPath = $this->getVideoThumbnailSavePath() . $path; $path = str_replace(PIMCORE_DOCUMENT_ROOT, "", $fullPath); $path = urlencode_ignore_slash($path); $results = \Pimcore::getEventManager()->trigger("frontend.path.asset.video.thumbnail", $this, ["filesystemPath" => $fullPath, "frontendPath" => $path]); if ($results->count()) { $path = $results->last(); } } return $customSetting[$thumbnail->getName()]; } } catch (\Exception $e) { Logger::error("Couldn't create thumbnail of video " . $this->getRealFullPath()); Logger::error($e); } } return null; }