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;
            }
        }
    }
}
Exemplo n.º 2
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"] . "'");
         }
     }
 }
        }

    </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;