Pimcore\Model\Asset\Video\Thumbnail\Processor::execute PHP Method

execute() public static method

public static execute ( $processId )
$processId
    public static function execute($processId)
    {
        $instance = new self();
        $instance->setProcessId($processId);
        $instanceItem = TmpStore::get($instance->getJobStoreId($processId));
        $instance = $instanceItem->getData();
        $formats = [];
        $conversionStatus = "finished";
        // check if there is already a transcoding process running, wait if so ...
        Model\Tool\Lock::acquire("video-transcoding", 7200, 10);
        // expires after 2 hrs, refreshes every 10 secs
        $asset = Model\Asset::getById($instance->getAssetId());
        // start converting
        foreach ($instance->queue as $converter) {
            try {
                Logger::info("start video " . $converter->getFormat() . " to " . $converter->getDestinationFile());
                $success = $converter->save();
                Logger::info("finished video " . $converter->getFormat() . " to " . $converter->getDestinationFile());
                File::rename($converter->getDestinationFile(), $converter->getStorageFile());
                // set proper permissions
                @chmod($converter->getStorageFile(), File::getDefaultMode());
                if ($success) {
                    $formats[$converter->getFormat()] = str_replace($asset->getVideoThumbnailSavePath(), "", $converter->getStorageFile());
                } else {
                    $conversionStatus = "error";
                }
                $converter->destroy();
            } catch (\Exception $e) {
                Logger::error($e);
            }
        }
        Model\Tool\Lock::release("video-transcoding");
        if ($asset) {
            $customSetting = $asset->getCustomSetting("thumbnails");
            $customSetting = is_array($customSetting) ? $customSetting : [];
            if (array_key_exists($instance->getConfig()->getName(), $customSetting) && array_key_exists("formats", $customSetting[$instance->getConfig()->getName()]) && is_array($customSetting[$instance->getConfig()->getName()]["formats"])) {
                $formats = array_merge($customSetting[$instance->getConfig()->getName()]["formats"], $formats);
            }
            $customSetting[$instance->getConfig()->getName()] = ["status" => $conversionStatus, "formats" => $formats];
            $asset->setCustomSetting("thumbnails", $customSetting);
            $asset->save();
        }
        TmpStore::delete($instance->getJobStoreId());
    }

Usage Example

Exemplo n.º 1
0
<?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]);
All Usage Examples Of Pimcore\Model\Asset\Video\Thumbnail\Processor::execute