public function getFolderContentPreviewAction() { $folder = Asset::getById($this->_getParam("id")); $start = 0; $limit = 10; if ($this->_getParam("limit")) { $limit = $this->_getParam("limit"); } if ($this->_getParam("start")) { $start = $this->_getParam("start"); } $list = Asset::getList(array("condition" => "path LIKE '" . $folder->getFullPath() . "%' AND type != 'folder'", "limit" => $limit, "offset" => $start, "orderKey" => "filename", "order" => "asc")); $assets = array(); foreach ($list as $asset) { $thumbnailMethod = ""; if ($asset instanceof Asset_Image) { $thumbnailMethod = "getThumbnail"; } else { if ($asset instanceof Asset_Video && Pimcore_Video::isAvailable()) { $thumbnailMethod = "getImageThumbnail"; } } if (!empty($thumbnailMethod)) { $assets[] = array("id" => $asset->getId(), "type" => $asset->getType(), "filename" => $asset->getFilename(), "url" => $asset->{$thumbnailMethod}(array("contain" => true, "width" => 250, "height" => 250, "format" => "JPEG", "interlace" => true, "quality" => 80))); } } $this->_helper->json(array("assets" => $assets, "success" => true, "total" => $list->getTotalCount())); }
public function videoThumbnailAdapterCheckAction() { if (!Pimcore_Video::isAvailable()) { echo '<span style="color: red; font-weight: bold;padding: 10px;margin:0 0 20px 0;border:1px solid red;display:block;">' . $this->view->translate("php_cli_binary_and_or_ffmpeg_binary_setting_is_missing") . '</span>'; } exit; }
public function getFlowplayerCode($urls = array(), $thumbnail = null) { $options = $this->getOptions(); $code = ""; $scriptPath = "/pimcore/static/js/lib/flowplayer/flowplayer.min.js"; $swfPath = "/pimcore/static/js/lib/flowplayer/flowplayer.swf"; $uid = "video_" . uniqid(); $config = array(); // configurations if ($options["swfPath"]) { $swfPath = $options["swfPath"]; } if ($options["scriptPath"]) { $scriptPath = $options["scriptPath"]; } $preConfig = Zend_Json::encode(array("dummy" => true)); if ($options["config"]) { if (is_string($options["config"])) { // configuration is the name of the javascript variable which contains the configuration $preConfig = $options["config"]; } else { if (is_array($options["config"])) { // configuration is directly in php, so wh have to convert it to json $preConfig = Zend_Json::encode($options["config"]); } } } $config["clip"]["url"] = $urls["f4v"]; if (empty($urls)) { return $this->getEmptyCode(); //$config["clip"]["url"] = "/pimcore/static/f4v/pimcore.f4v"; } if (!Document_Tag_Video::$playerJsEmbedded) { $code .= '<script type="text/javascript" src="' . $scriptPath . '"></script>'; $code .= '<script type="text/javascript" src="/pimcore/static/js/lib/array_merge.js"></script>'; $code .= '<script type="text/javascript" src="/pimcore/static/js/lib/array_merge_recursive.js"></script>'; Document_Tag_Video::$playerJsEmbedded = true; $code .= ' <style type="text/css"> a.pimcore_video_flowplayer { display:block; text-align:center; } </style> '; } if (Pimcore_Video::isAvailable()) { $code .= ' <style type="text/css"> #' . $uid . ' .play { margin-top:' . ($this->getHeight() - 83) / 2 . 'px; border:0px; display:inline-block; width:83px; height:83px; background:url(/pimcore/static/js/lib/flowplayer/play_large.png); } </style> '; } $code .= '<div id="pimcore_video_' . $this->getName() . '"> <a id="' . $uid . '" href="' . $urls["mp4"] . '" class="pimcore_video_flowplayer" style="background-image:url(' . $thumbnail . '); width:' . $this->getWidth() . 'px; height:' . $this->getHeight() . 'px;"> ' . (Pimcore_Video::isAvailable() ? '<span class="play">' : "") . '</span> </a> </div>'; Zend_Json::encode($config); $code .= ' <script type="text/javascript"> var player_config_' . $uid . ' = array_merge_recursive(' . $preConfig . ',' . Zend_Json::encode($config) . '); flowplayer("' . $uid . '", { src: "' . $swfPath . '", width: "' . $this->getWidth() . '", height: "' . $this->getHeight() . '", },player_config_' . $uid . '); </script> '; return $code; }
<div class="pimcore_tag_video_progress_status"><?php echo number_format($progress, 0); ?> %</div> </div> <script type="text/javascript"> window.setTimeout(function () { location.reload(); }, 5000); </script> <?php } else { if (!Pimcore_Video::isAvailable()) { ?> <?php echo $this->translate("preview_not_available"); ?> <br /> <?php echo $this->translate("php_cli_binary_and_or_ffmpeg_binary_setting_is_missing"); ?> <?php } else { ?> <?php echo $this->translate("preview_not_available"); ?> <br />
/** * @static * @param Asset_Video $asset * @param Asset_Video_Thumbnail_Config $config */ public static function process(Asset_Video $asset, $config) { if (!Pimcore_Video::isAvailable()) { throw new Exception("No ffmpeg executable found, please configure the correct path in the system settings"); } $instance = new self(); $formats = array("mp4", "webm", "f4v"); $instance->setProcessId(uniqid()); $instance->setAssetId($asset->getId()); $instance->setConfig($config); // check for running or already created thumbnails $customSetting = $asset->getCustomSetting("thumbnails"); $existingFormats = array(); if (is_array($customSetting) && array_key_exists($config->getName(), $customSetting)) { if ($customSetting[$config->getName()]["status"] == "inprogress") { if (is_file($instance->getJobFile($customSetting[$config->getName()]["processId"]))) { return; } } else { if ($customSetting[$config->getName()]["status"] == "finished") { // check if the files are there $formatsToConvert = array(); foreach ($formats as $f) { if (!is_file(PIMCORE_DOCUMENT_ROOT . $customSetting[$config->getName()]["formats"][$f])) { $formatsToConvert[] = $f; } else { $existingFormats[$f] = $customSetting[$config->getName()]["formats"][$f]; } } if (!empty($formatsToConvert)) { $formats = $formatsToConvert; } else { return; } } } } foreach ($formats as $format) { $filename = "video_" . $asset->getId() . "__" . $config->getName() . "." . $format; $fsPath = PIMCORE_TEMPORARY_DIRECTORY . "/" . $filename; if (is_file($fsPath)) { @unlink($fsPath); } $converter = Pimcore_Video::getInstance(); $converter->load($asset->getFileSystemPath()); $converter->setAudioBitrate($config->getAudioBitrate()); $converter->setVideoBitrate($config->getVideoBitrate()); $converter->setFormat($format); $converter->setDestinationFile($fsPath); $transformations = $config->getItems(); if (is_array($transformations) && count($transformations) > 0) { foreach ($transformations as $transformation) { if (!empty($transformation)) { $arguments = array(); $mapping = self::$argumentMapping[$transformation["method"]]; if (is_array($transformation["arguments"])) { foreach ($transformation["arguments"] as $key => $value) { $position = array_search($key, $mapping); if ($position !== false) { $arguments[$position] = $value; } } } ksort($arguments); if (count($mapping) == count($arguments)) { call_user_func_array(array($converter, $transformation["method"]), $arguments); } else { $message = "Video Transform failed: cannot call method `" . $transformation["method"] . "´ with arguments `" . implode(",", $arguments) . "´ because there are too few arguments"; Logger::error($message); } } } } $instance->queue[] = $converter; } $customSetting = $asset->getCustomSetting("thumbnails"); $customSetting = is_array($customSetting) ? $customSetting : array(); $customSetting[$config->getName()] = array("status" => "inprogress", "formats" => $existingFormats, "processId" => $instance->getProcessId()); $asset->setCustomSetting("thumbnails", $customSetting); $asset->save(); $instance->convert(); return $instance; }
/** * @param Asset $asset * @return array|string */ protected function getTreeNodeConfig($asset) { $tmpAsset = array("id" => $asset->getId(), "text" => $asset->getFilename(), "type" => $asset->getType(), "path" => $asset->getFullPath(), "basePath" => $asset->getPath(), "locked" => $asset->isLocked(), "lockOwner" => $asset->getLocked() ? true : false, "elementType" => "asset", "permissions" => array("remove" => $asset->isAllowed("delete"), "settings" => $asset->isAllowed("settings"), "rename" => $asset->isAllowed("rename"), "publish" => $asset->isAllowed("publish"))); // set type specific settings if ($asset->getType() == "folder") { $tmpAsset["leaf"] = false; $tmpAsset["expanded"] = $asset->hasNoChilds(); $tmpAsset["iconCls"] = "pimcore_icon_folder"; $tmpAsset["permissions"]["create"] = $asset->isAllowed("create"); } else { $tmpAsset["leaf"] = true; $tmpAsset["iconCls"] = "pimcore_icon_" . Pimcore_File::getFileExtension($asset->getFilename()); } $tmpAsset["qtipCfg"] = array("title" => "ID: " . $asset->getId()); if ($asset->getType() == "image") { try { $tmpAsset["qtipCfg"] = array("title" => "ID: " . $asset->getId(), "text" => '<img src="/admin/asset/get-image-thumbnail/id/' . $asset->getId() . '/width/130/aspectratio/true" width="130" />', "width" => 140); // this is for backward-compatibilty, to calculate the dimensions if they are not there if (!$asset->getCustomSetting("imageDimensionsCalculated")) { $asset->save(); } if ($asset->getCustomSetting("imageWidth") && $asset->getCustomSetting("imageHeight")) { $tmpAsset["imageWidth"] = $asset->getCustomSetting("imageWidth"); $tmpAsset["imageHeight"] = $asset->getCustomSetting("imageHeight"); } } catch (Exception $e) { Logger::debug("Cannot get dimensions of image, seems to be broken."); } } else { if ($asset->getType() == "video") { try { if (Pimcore_Video::isAvailable()) { $tmpAsset["qtipCfg"] = array("title" => "ID: " . $asset->getId(), "text" => '<img src="/admin/asset/get-video-thumbnail/id/' . $asset->getId() . '/width/130/aspectratio/true" width="130" />', "width" => 140); } } catch (Exception $e) { Logger::debug("Cannot get dimensions of video, seems to be broken."); } } } $tmpAsset["cls"] = ""; if ($asset->isLocked()) { $tmpAsset["cls"] .= "pimcore_treenode_locked "; } if ($asset->getLocked()) { $tmpAsset["cls"] .= "pimcore_treenode_lockOwner "; } return $tmpAsset; }