Exemple #1
0
 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"] . "'");
         }
     }
 }
 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;
 }
Exemple #3
0
 /**
  *
  */
 public function generate()
 {
     $errorImage = PIMCORE_PATH . '/static6/img/filetype-not-supported.png';
     $deferred = false;
     $generated = false;
     if (!$this->asset) {
         $this->filesystemPath = $errorImage;
     } elseif (!$this->filesystemPath) {
         $cs = $this->asset->getCustomSetting("image_thumbnail_time");
         $im = $this->asset->getCustomSetting("image_thumbnail_asset");
         if ($im || $this->imageAsset) {
             if ($this->imageAsset) {
                 $im = $this->imageAsset;
             } else {
                 $im = Model\Asset::getById($im);
             }
             if ($im instanceof Image) {
                 $imageThumbnail = $im->getThumbnail($this->getConfig());
                 $this->filesystemPath = $imageThumbnail->getFileSystemPath();
             }
         }
         if (!$this->filesystemPath) {
             $timeOffset = $this->timeOffset;
             if (!$this->timeOffset && $cs) {
                 $timeOffset = $cs;
             }
             // fallback
             if (!$timeOffset) {
                 $timeOffset = ceil($this->asset->getDuration() / 3);
             }
             $converter = \Pimcore\Video::getInstance();
             $converter->load($this->asset->getFileSystemPath());
             $path = PIMCORE_TEMPORARY_DIRECTORY . "/video-image-cache/video_" . $this->asset->getId() . "__thumbnail_" . $timeOffset . ".png";
             if (!is_dir(dirname($path))) {
                 File::mkdir(dirname($path));
             }
             if (!is_file($path)) {
                 $lockKey = "video_image_thumbnail_" . $this->asset->getId() . "_" . $timeOffset;
                 Model\Tool\Lock::acquire($lockKey);
                 // after we got the lock, check again if the image exists in the meantime - if not - generate it
                 if (!is_file($path)) {
                     $converter->saveImage($path, $timeOffset);
                     $generated = true;
                 }
                 Model\Tool\Lock::release($lockKey);
             }
             if ($this->getConfig()) {
                 $this->getConfig()->setFilenameSuffix("time-" . $timeOffset);
                 try {
                     $path = Image\Thumbnail\Processor::process($this->asset, $this->getConfig(), $path, $deferred, true, $generated);
                 } catch (\Exception $e) {
                     Logger::error("Couldn't create image-thumbnail of video " . $this->asset->getRealFullPath());
                     Logger::error($e);
                     $path = $errorImage;
                 }
             }
             $this->filesystemPath = $path;
         }
         \Pimcore::getEventManager()->trigger("asset.video.image-thumbnail", $this, ["deferred" => $deferred, "generated" => $generated]);
     }
 }
                    <?php 
    echo $this->translate("please_wait");
    ?>

                    <div class="pimcore_tag_video_progress_status"></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 />
Exemple #5
0
",
        showCloseConfirmation: true,
        debug_admin_translations: <?php 
echo \Zend_Json::encode((bool) $this->config->general->debug_admin_translations);
?>
,
        document_generatepreviews: <?php 
echo \Zend_Json::encode((bool) $this->config->documents->generatepreview);
?>
,
        htmltoimage: <?php 
echo \Zend_Json::encode(\Pimcore\Image\HtmlToImage::isSupported());
?>
,
        videoconverter: <?php 
echo \Zend_Json::encode(\Pimcore\Video::isAvailable());
?>
,
        asset_hide_edit: <?php 
echo $this->config->assets->hide_edit_image ? "true" : "false";
?>
    };
</script>


<?php 
// 3rd party libraries
?>
<script type="text/javascript">
    <?php 
if (isset($googleMapsApiKey) && strlen($googleMapsApiKey) > 0) {
 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");
     }
     $condition = "path LIKE '" . ($folder->getFullPath() == "/" ? "/%'" : $folder->getFullPath() . "/%'") . " AND type != 'folder'";
     $list = Asset::getList(array("condition" => $condition, "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";
             } else {
                 if ($asset instanceof Asset\Document && \Pimcore\Document::isAvailable()) {
                     $thumbnailMethod = "getImageThumbnail";
                 }
             }
         }
         if (!empty($thumbnailMethod)) {
             $assets[] = array("id" => $asset->getId(), "type" => $asset->getType(), "filename" => $asset->getFilename(), "url" => "/admin/asset/get-" . $asset->getType() . "-thumbnail/id/" . $asset->getId() . "/treepreview/true", "idPath" => $data["idPath"] = Element\Service::getIdPath($asset));
         }
     }
     $this->_helper->json(array("assets" => $assets, "success" => true, "total" => $list->getTotalCount()));
 }
Exemple #7
0
 /**
  * @param Model\Asset\Video $asset
  * @param $config
  * @param array $onlyFormats
  * @return Processor
  * @throws \Exception
  */
 public static function process(Model\Asset\Video $asset, $config, $onlyFormats = [])
 {
     if (!\Pimcore\Video::isAvailable()) {
         throw new \Exception("No ffmpeg executable found, please configure the correct path in the system settings");
     }
     $instance = new self();
     $formats = empty($onlyFormats) ? ["mp4"] : $onlyFormats;
     $instance->setProcessId(uniqid());
     $instance->setAssetId($asset->getId());
     $instance->setConfig($config);
     // check for running or already created thumbnails
     $customSetting = $asset->getCustomSetting("thumbnails");
     $existingFormats = [];
     if (is_array($customSetting) && array_key_exists($config->getName(), $customSetting)) {
         if ($customSetting[$config->getName()]["status"] == "inprogress") {
             if (TmpStore::get($instance->getJobStoreId($customSetting[$config->getName()]["processId"]))) {
                 return;
             }
         } elseif ($customSetting[$config->getName()]["status"] == "finished") {
             // check if the files are there
             $formatsToConvert = [];
             foreach ($formats as $f) {
                 if (!is_file($asset->getVideoThumbnailSavePath() . $customSetting[$config->getName()]["formats"][$f])) {
                     $formatsToConvert[] = $f;
                 } else {
                     $existingFormats[$f] = $customSetting[$config->getName()]["formats"][$f];
                     $existingFormats[$f] = $customSetting[$config->getName()]["formats"][$f];
                 }
             }
             if (!empty($formatsToConvert)) {
                 $formats = $formatsToConvert;
             } else {
                 return;
             }
         } elseif ($customSetting[$config->getName()]["status"] == "error") {
             throw new \Exception("Unable to convert video, see logs for details.");
         }
     }
     foreach ($formats as $format) {
         $thumbDir = $asset->getVideoThumbnailSavePath() . "/thumb__" . $config->getName();
         $filename = preg_replace("/\\." . preg_quote(File::getFileExtension($asset->getFilename())) . "/", "", $asset->getFilename()) . "." . $format;
         $fsPath = $thumbDir . "/" . $filename;
         $tmpPath = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/" . $filename;
         if (!is_dir(dirname($fsPath))) {
             File::mkdir(dirname($fsPath));
         }
         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($tmpPath);
         $converter->setStorageFile($fsPath);
         $transformations = $config->getItems();
         if (is_array($transformations) && count($transformations) > 0) {
             foreach ($transformations as $transformation) {
                 if (!empty($transformation)) {
                     $arguments = [];
                     $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([$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 : [];
     $customSetting[$config->getName()] = ["status" => "inprogress", "formats" => $existingFormats, "processId" => $instance->getProcessId()];
     $asset->setCustomSetting("thumbnails", $customSetting);
     $asset->save();
     $instance->convert();
     return $instance;
 }
Exemple #8
0
 /**
  * @return null
  * @throws \Exception
  */
 protected function getDurationFromBackend()
 {
     if (\Pimcore\Video::isAvailable()) {
         $converter = \Pimcore\Video::getInstance();
         $converter->load($this->getFileSystemPath());
         return $converter->getDuration();
     }
     return null;
 }