private static function generateThumbnail(asset $srcAsset, thumbParamsOutput $destThumbParamsOutput, &$errDescription, $rotate = null)
 {
     $srcSyncKey = $srcAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($srcSyncKey, true, false);
     if (!$fileSync || $fileSync->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL) {
         $errDescription = 'Source asset could has no valid file sync';
         return false;
     }
     $srcPath = $fileSync->getFullPath();
     $srcWamsAssetId = $fileSync->getWamsAssetId();
     $uniqid = uniqid('thumb_');
     $destPath = kConf::get('temp_folder') . "/thumb/{$uniqid}.jpg";
     $logPath = $destPath . '.log';
     if (is_null($srcWamsAssetId)) {
         if (!file_exists($srcPath)) {
             $errDescription = "Source file [{$srcPath}] does not exist";
             return false;
         }
         if (!is_file($srcPath)) {
             $errDescription = "Source file [{$srcPath}] is not a file";
             return false;
         }
     }
     try {
         if ($srcAsset->getType() == assetType::FLAVOR) {
             /* @var $srcAsset flavorAsset */
             $dar = null;
             $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($srcAsset->getId());
             if ($mediaInfo) {
                 $dar = $mediaInfo->getVideoDar();
             }
             // generates the thumbnail
             if (!is_null($srcWamsAssetId)) {
                 $thumbMaker = new KWAMSThumbnailMaker($srcWamsAssetId, $destPath);
                 $created = $thumbMaker->createThumbnail($destThumbParamsOutput->getVideoOffset(), $srcAsset->getWidth(), $srcAsset->getHeight(), $dar);
             } else {
                 $thumbMaker = new KFFMpegThumbnailMaker($srcPath, $destPath, kConf::get('bin_path_ffmpeg'));
                 $created = $thumbMaker->createThumnail($destThumbParamsOutput->getVideoOffset(), $srcAsset->getWidth(), $srcAsset->getHeight(), null, null, $dar);
             }
             if (!$created || !file_exists($destPath)) {
                 $errDescription = "Thumbnail not captured";
                 return false;
             }
             $srcPath = $destPath;
             $uniqid = uniqid('thumb_');
             $destPath = kConf::get('temp_folder') . "/thumb/{$uniqid}.jpg";
         }
         $quality = $destThumbParamsOutput->getQuality();
         $cropType = $destThumbParamsOutput->getCropType();
         $cropX = $destThumbParamsOutput->getCropX();
         $cropY = $destThumbParamsOutput->getCropY();
         $cropWidth = $destThumbParamsOutput->getCropWidth();
         $cropHeight = $destThumbParamsOutput->getCropHeight();
         $bgcolor = $destThumbParamsOutput->getBackgroundColor();
         $width = $destThumbParamsOutput->getWidth();
         $height = $destThumbParamsOutput->getHeight();
         $scaleWidth = $destThumbParamsOutput->getScaleWidth();
         $scaleHeight = $destThumbParamsOutput->getScaleHeight();
         $density = $destThumbParamsOutput->getDensity();
         $stripProfiles = $destThumbParamsOutput->getStripProfiles();
         $cropper = new KImageMagickCropper($srcPath, $destPath, kConf::get('bin_path_imagemagick'), true);
         $cropped = $cropper->crop($quality, $cropType, $width, $height, $cropX, $cropY, $cropWidth, $cropHeight, $scaleWidth, $scaleHeight, $bgcolor, $density, $rotate, $stripProfiles);
         if (!$cropped || !file_exists($destPath)) {
             $errDescription = "Crop failed";
             return false;
         }
         return $destPath;
     } catch (Exception $ex) {
         $errDescription = $ex->getMessage();
         return false;
     }
 }
 /**
  * @param KalturaBatchJob $job
  * @param KalturaPostConvertJobData $data
  * @return KalturaBatchJob
  */
 private function postConvert(KalturaBatchJob $job, KalturaPostConvertJobData $data)
 {
     DbManager::setConfig(kConf::getDB());
     DbManager::initialize();
     $flavorAsset = assetPeer::retrieveByPK($data->flavorAssetId);
     if (!empty($flavorAsset) && $this->checkMediaInfoExists($data->flavorAssetId) && $flavorAsset->getIsOriginal() && $flavorAsset->getSize() !== 0) {
         $data->createThumb = false;
         return $this->closeJob($job, null, null, 'Media info already exists', KalturaBatchJobStatus::FINISHED, $data);
     }
     if ($data->flavorParamsOutputId) {
         $data->flavorParamsOutput = $this->kClient->flavorParamsOutput->get($data->flavorParamsOutputId);
     }
     try {
         $mediaFile = trim($data->srcFileSyncLocalPath);
         $mediaFileExt = pathinfo($mediaFile, PATHINFO_EXTENSION);
         if (!is_null($data->srcFileSyncWamsAssetId)) {
             $tempFile = kWAMS::getInstance($job->partnerId)->createTempFileForAssetId($data->srcFileSyncWamsAssetId, $mediaFileExt);
             if (file_exists($tempFile)) {
                 $mediaFile = $tempFile;
             }
         }
         if (!$data->flavorParamsOutput || !$data->flavorParamsOutput->sourceRemoteStorageProfileId) {
             if (!$this->pollingFileExists($mediaFile)) {
                 return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::NFS_FILE_DOESNT_EXIST, "Source file {$mediaFile} does not exist", KalturaBatchJobStatus::RETRY);
             }
             if (!is_file($mediaFile)) {
                 return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::NFS_FILE_DOESNT_EXIST, "Source file {$mediaFile} is not a file", KalturaBatchJobStatus::FAILED);
             }
         }
         KalturaLog::debug("mediaFile [{$mediaFile}]");
         $this->updateJob($job, "Extracting file media info on {$mediaFile}", KalturaBatchJobStatus::QUEUED, 1);
     } catch (Exception $ex) {
         return $this->closeJob($job, KalturaBatchJobErrorTypes::RUNTIME, $ex->getCode(), "Error: " . $ex->getMessage(), KalturaBatchJobStatus::FAILED);
     }
     $mediaInfo = null;
     try {
         $engine = KBaseMediaParser::getParser($job->jobSubType, realpath($mediaFile), $this->taskConfig, $job, $data->srcFileSyncWamsAssetId);
         if ($engine) {
             KalturaLog::info("Media info engine [" . get_class($engine) . "]");
             $mediaInfo = $engine->getMediaInfo();
             if (!empty($data->srcFileSyncWamsAssetId)) {
                 kWAMS::getInstance($job->partnerId)->deleteTempFileForAssetId($data->srcFileSyncWamsAssetId, $mediaFileExt);
             }
         } else {
             $err = "Media info engine not found for job subtype [" . $job->jobSubType . "]";
             KalturaLog::info($err);
             return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::ENGINE_NOT_FOUND, $err, KalturaBatchJobStatus::FAILED);
         }
     } catch (Exception $ex) {
         KalturaLog::err("Error: " . $ex->getMessage());
         $mediaInfo = null;
     }
     /* @var $mediaInfo KalturaMediaInfo */
     if (is_null($mediaInfo)) {
         return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::EXTRACT_MEDIA_FAILED, "Failed to extract media info: {$mediaFile}", KalturaBatchJobStatus::FAILED);
     }
     try {
         $mediaInfo->flavorAssetId = $data->flavorAssetId;
         $createdMediaInfo = $this->getClient()->batch->addMediaInfo($mediaInfo);
         if ($createdMediaInfo instanceof KalturaMediaInfo) {
             $mediaInfo = $createdMediaInfo;
         }
         // must save the mediaInfoId before reporting that the task is finished
         $this->updateJob($job, "Saving media info id {$createdMediaInfo->id}", KalturaBatchJobStatus::PROCESSED, 50, $data);
         $data->thumbPath = null;
         if (!$data->createThumb) {
             return $this->closeJob($job, null, null, "Media info id {$createdMediaInfo->id} saved", KalturaBatchJobStatus::FINISHED, $data);
         }
         // creates a temp file path
         $rootPath = $this->taskConfig->params->localTempPath;
         $this->createDir($rootPath);
         // creates the path
         $uniqid = uniqid('thumb_');
         $thumbPath = realpath($rootPath) . "/{$uniqid}";
         $videoDurationSec = floor($mediaInfo->videoDuration / 1000);
         $data->thumbOffset = max(0, min($data->thumbOffset, $videoDurationSec));
         if ($mediaInfo->videoHeight) {
             $data->thumbHeight = $mediaInfo->videoHeight;
         }
         if ($mediaInfo->videoBitRate) {
             $data->thumbBitrate = $mediaInfo->videoBitRate;
         }
         // generates the thumbnail
         if (!is_null($data->srcFileSyncWamsAssetId)) {
             $thumbMaker = new KWAMSThumbnailMaker($data->srcFileSyncWamsAssetId, $thumbPath);
             $created = $thumbMaker->createThumbnail($data->thumbOffset, $mediaInfo->videoWidth, $mediaInfo->videoHeight, $mediaInfo->videoDar);
         } else {
             $thumbMaker = new KFFMpegThumbnailMaker($mediaFile, $thumbPath, $this->taskConfig->params->FFMpegCmd);
             $created = $thumbMaker->createThumnail($data->thumbOffset, $mediaInfo->videoWidth, $mediaInfo->videoHeight, null, null, $mediaInfo->videoDar);
         }
         if (!$created || !file_exists($thumbPath)) {
             $data->createThumb = false;
             return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::THUMBNAIL_NOT_CREATED, 'Thumbnail not created', KalturaBatchJobStatus::FINISHED, $data);
         }
         $data->thumbPath = $thumbPath;
         $job = $this->moveFile($job, $data);
         if ($this->checkFileExists($job->data->thumbPath)) {
             return $this->closeJob($job, null, null, null, KalturaBatchJobStatus::FINISHED, $data);
         }
         $data->createThumb = false;
         return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::NFS_FILE_DOESNT_EXIST, 'File not moved correctly', KalturaBatchJobStatus::FINISHED, $data);
     } catch (Exception $ex) {
         return $this->closeJob($job, KalturaBatchJobErrorTypes::RUNTIME, $ex->getCode(), "Error: " . $ex->getMessage(), KalturaBatchJobStatus::FAILED);
     }
 }
 private function captureThumb(KalturaBatchJob $job, KalturaCaptureThumbJobData $data)
 {
     KalturaLog::debug("captureThumb({$job->id})");
     $thumbParamsOutput = $this->kClient->thumbParamsOutput->get($data->thumbParamsOutputId);
     try {
         $mediaFile = trim($data->srcFileSyncLocalPath);
         if (is_null($data->srcWamsAssetId)) {
             if (!file_exists($mediaFile)) {
                 return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::NFS_FILE_DOESNT_EXIST, "Source file {$mediaFile} does not exist", KalturaBatchJobStatus::RETRY);
             }
             if (!is_file($mediaFile)) {
                 return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::NFS_FILE_DOESNT_EXIST, "Source file {$mediaFile} is not a file", KalturaBatchJobStatus::FAILED);
             }
         }
         KalturaLog::debug("mediaFile [{$mediaFile}]");
         $this->updateJob($job, "Capturing thumbnail on {$mediaFile}", KalturaBatchJobStatus::QUEUED, 1);
     } catch (Exception $ex) {
         return $this->closeJob($job, KalturaBatchJobErrorTypes::RUNTIME, $ex->getCode(), "Error: " . $ex->getMessage(), KalturaBatchJobStatus::FAILED);
     }
     try {
         $data->thumbPath = null;
         // creates a temp file path
         $rootPath = $this->taskConfig->params->localTempPath;
         if (!is_dir($rootPath)) {
             if (!file_exists($rootPath)) {
                 KalturaLog::info("Creating temp thumbnail directory [{$rootPath}]");
                 mkdir($rootPath);
             } else {
                 // already exists but not a directory
                 KalturaLog::err("Cannot create temp thumbnail directory [{$rootPath}] due to an error. Please fix and restart");
                 die;
             }
         }
         $capturePath = $mediaFile;
         if ($data->srcAssetType == KalturaAssetType::FLAVOR) {
             // creates the path
             $uniqid = uniqid('thumb_');
             $capturePath = realpath($rootPath) . "/{$uniqid}";
             $mediaInfoWidth = null;
             $mediaInfoHeight = null;
             $mediaInfoDar = null;
             $mediaInfoFilter = new KalturaMediaInfoFilter();
             $mediaInfoFilter->flavorAssetIdEqual = $data->srcAssetId;
             $this->impersonate($job->partnerId);
             $mediaInfoList = $this->kClient->mediaInfo->listAction($mediaInfoFilter);
             $this->unimpersonate();
             if (count($mediaInfoList->objects)) {
                 $mediaInfo = reset($mediaInfoList->objects);
                 /* @var $mediaInfo KalturaMediaInfo */
                 $mediaInfoWidth = $mediaInfo->videoWidth;
                 $mediaInfoHeight = $mediaInfo->videoHeight;
                 $mediaInfoDar = $mediaInfo->videoDar;
             }
             // generates the thumbnail
             if (!is_null($data->srcWamsAssetId)) {
                 $thumbMaker = new KWAMSThumbnailMaker($data->srcWamsAssetId, $capturePath);
                 $created = $thumbMaker->createThumbnail($thumbParamsOutput->videoOffset, $mediaInfoWidth, $mediaInfoHeight, $mediaInfoDar);
             } else {
                 $thumbMaker = new KFFMpegThumbnailMaker($mediaFile, $capturePath, $this->taskConfig->params->FFMpegCmd);
                 $created = $thumbMaker->createThumnail($thumbParamsOutput->videoOffset, $mediaInfoWidth, $mediaInfoHeight, null, null, $mediaInfoDar);
             }
             if (!$created || !file_exists($capturePath)) {
                 return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::THUMBNAIL_NOT_CREATED, "Thumbnail not created", KalturaBatchJobStatus::FAILED);
             }
             $this->updateJob($job, "Thumbnail captured [{$capturePath}]", KalturaBatchJobStatus::PROCESSING, 40);
         } else {
             KalturaLog::info("Source file is already an image");
         }
         $uniqid = uniqid('thumb_');
         $thumbPath = realpath($rootPath) . "/{$uniqid}";
         $quality = $thumbParamsOutput->quality;
         $cropType = $thumbParamsOutput->cropType;
         $cropX = $thumbParamsOutput->cropX;
         $cropY = $thumbParamsOutput->cropY;
         $cropWidth = $thumbParamsOutput->cropWidth;
         $cropHeight = $thumbParamsOutput->cropHeight;
         $bgcolor = $thumbParamsOutput->backgroundColor;
         $width = $thumbParamsOutput->width;
         $height = $thumbParamsOutput->height;
         $scaleWidth = $thumbParamsOutput->scaleWidth;
         $scaleHeight = $thumbParamsOutput->scaleHeight;
         $density = $thumbParamsOutput->density;
         $rotate = $thumbParamsOutput->rotate;
         $cropper = new KImageMagickCropper($capturePath, $thumbPath, $this->taskConfig->params->ImageMagickCmd, true);
         $cropped = $cropper->crop($quality, $cropType, $width, $height, $cropX, $cropY, $cropWidth, $cropHeight, $scaleWidth, $scaleHeight, $bgcolor, $density, $rotate);
         if (!$cropped || !file_exists($thumbPath)) {
             return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::THUMBNAIL_NOT_CREATED, "Thumbnail not cropped", KalturaBatchJobStatus::FAILED);
         }
         $data->thumbPath = $thumbPath;
         $job = $this->moveFile($job, $data);
         if ($this->checkFileExists($job->data->thumbPath)) {
             $updateData = new KalturaCaptureThumbJobData();
             $updateData->thumbPath = $data->thumbPath;
             return $this->closeJob($job, null, null, null, KalturaBatchJobStatus::FINISHED, $updateData);
         }
         return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::NFS_FILE_DOESNT_EXIST, 'File not moved correctly', KalturaBatchJobStatus::FAILED, $data);
     } catch (Exception $ex) {
         return $this->closeJob($job, KalturaBatchJobErrorTypes::RUNTIME, $ex->getCode(), "Error: " . $ex->getMessage(), KalturaBatchJobStatus::FAILED);
     }
 }
 public static function resizeEntryImage(entry $entry, $version, $width, $height, $type, $bgcolor = "ffffff", $crop_provider = null, $quality = 0, $src_x = 0, $src_y = 0, $src_w = 0, $src_h = 0, $vid_sec = -1, $vid_slice = 0, $vid_slices = -1, $orig_image_path = null, $density = 0, $stripProfiles = false, $thumbParams = null)
 {
     if (is_null($thumbParams) || !$thumbParams instanceof kThumbnailParameters) {
         $thumbParams = new kThumbnailParameters();
     }
     $contentPath = myContentStorage::getFSContentRootPath();
     $entry_status = $entry->getStatus();
     $tempThumbName = $entry->getId() . "_{$width}_{$height}_{$type}_{$crop_provider}_{$bgcolor}_{$quality}_{$src_x}_{$src_y}_{$src_w}_{$src_h}_{$vid_sec}_{$vid_slice}_{$vid_slices}_{$entry_status}";
     if ($orig_image_path) {
         $tempThumbName .= '_oip_' . basename($orig_image_path);
     }
     if ($density) {
         $tempThumbName .= "_dns_{$density}";
     }
     if ($stripProfiles) {
         $tempThumbName .= "_stp_{$stripProfiles}";
     }
     $entryThumbFilename = $entry->getThumbnail() ? $entry->getThumbnail() : "0.jpg";
     if ($entry->getStatus() != entryStatus::READY || @$entryThumbFilename[0] == '&') {
         $tempThumbName .= "_NOCACHE_";
     }
     // we remove the & from the template thumb otherwise getGeneralEntityPath will drop $tempThumbName from the final path
     $entryThumbFilename = str_replace("&", "", $entryThumbFilename);
     $basePath = myContentStorage::getGeneralEntityPath("entry/tempthumb", $entry->getIntId(), $tempThumbName, $entryThumbFilename, $version);
     $tempThumbPath = $contentPath . $basePath;
     if (file_exists($tempThumbPath) && @filesize($tempThumbPath)) {
         header("X-Kaltura:cached-thumb-exists," . md5($tempThumbPath));
         return $tempThumbPath;
     }
     if ($orig_image_path === null || !file_exists($orig_image_path)) {
         $sub_type = $entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE ? entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA : entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB;
         $orig_image_key = $entry->getSyncKey($sub_type, $version);
         $orig_image_path = kFileSyncUtils::getReadyLocalFilePathForKey($orig_image_key);
     }
     // remark added so ffmpeg will try to load the thumbnail from the original source
     if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE && !file_exists($orig_image_path)) {
         throw new kFileSyncException('no ready filesync on current DC', kFileSyncException::FILE_DOES_NOT_EXIST_ON_CURRENT_DC);
     }
     // check a request for animated thumbs without a concrete vid_slice
     // in which case we'll create all the frames as one wide image
     $multi = $vid_slice == -1 && $vid_slices != -1;
     $count = $multi ? $vid_slices : 1;
     $im = null;
     if ($multi) {
         $vid_slice = 0;
     }
     while ($count--) {
         if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_VIDEO && ($vid_sec != -1 || $vid_slices != -1) || !file_exists($orig_image_path)) {
             if ($vid_sec != -1) {
                 $calc_vid_sec = min($vid_sec, floor($entry->getLengthInMsecs() / 1000));
             } else {
                 if ($vid_slices != -1) {
                     $calc_vid_sec = floor($entry->getLengthInMsecs() / $vid_slices * min($vid_slice, $vid_slices) / 1000);
                 } else {
                     if ($entry->getStatus() != entryStatus::READY && $entry->getLengthInMsecs() == 0) {
                         $calc_vid_sec = $entry->getPartner() && $entry->getPartner()->getDefThumbOffset() ? $entry->getPartner()->getDefThumbOffset() : 3;
                     } else {
                         $calc_vid_sec = $entry->getBestThumbOffset();
                     }
                 }
             }
             $capturedThumbName = $entry->getId() . "_sec_{$calc_vid_sec}";
             $capturedThumbPath = $contentPath . myContentStorage::getGeneralEntityPath("entry/tempthumb", $entry->getIntId(), $capturedThumbName, $entry->getThumbnail(), $version);
             $orig_image_path = $capturedThumbPath . "temp_1.jpg";
             // if we already captured the frame at that second, dont recapture, just use the existing file
             if (!file_exists($orig_image_path)) {
                 // creating the thumbnail is a very heavy operation
                 // prevent calling it in parallel for the same thubmnail for 5 minutes
                 $cache = new myCache("thumb-processing", 5 * 60);
                 // 5 minutes
                 $processing = $cache->get($orig_image_path);
                 if ($processing) {
                     KExternalErrors::dieError(KExternalErrors::PROCESSING_CAPTURE_THUMBNAIL);
                 }
                 $cache->put($orig_image_path, true);
                 $flavorAsset = assetPeer::retrieveHighestBitrateByEntryId($entry->getId(), flavorParams::TAG_THUMBSOURCE);
                 if (is_null($flavorAsset)) {
                     $flavorAsset = assetPeer::retrieveOriginalReadyByEntryId($entry->getId());
                     if (is_null($flavorAsset) || !($flavorAsset->hasTag(flavorParams::TAG_MBR) || $flavorAsset->hasTag(flavorParams::TAG_WEB))) {
                         // try the best playable
                         $flavorAsset = assetPeer::retrieveHighestBitrateByEntryId($entry->getId());
                     }
                     if (is_null($flavorAsset)) {
                         // if no READY ORIGINAL entry is available, try to retrieve a non-READY ORIGINAL entry
                         $flavorAsset = assetPeer::retrieveOriginalByEntryId($entry->getId());
                     }
                 }
                 if (is_null($flavorAsset)) {
                     // if no READY ORIGINAL entry is available, try to retrieve a non-READY ORIGINAL entry
                     $flavorAsset = assetPeer::retrieveOriginalByEntryId($entry->getId());
                 }
                 if (is_null($flavorAsset)) {
                     KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
                 }
                 $flavorSyncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                 $entry_data_path = kFileSyncUtils::getReadyLocalFilePathForKey($flavorSyncKey);
                 $entry_data_wams_asset_id = kFileSyncUtils::getWamsAssetIdForKey($flavorSyncKey);
                 if (!$entry_data_path) {
                     // since this is not really being processed on this server, and will probably cause redirect in thumbnailAction
                     // remove from cache so later requests will still get redirected and will not fail on PROCESSING_CAPTURE_THUMBNAIL
                     $cache->remove($orig_image_path);
                     throw new kFileSyncException('no ready filesync on current DC', kFileSyncException::FILE_DOES_NOT_EXIST_ON_CURRENT_DC);
                 }
                 if (!empty($entry_data_wams_asset_id)) {
                     $thumbMaker = new KWAMSThumbnailMaker($entry_data_wams_asset_id, $orig_image_path);
                     if (!$thumbMaker->createThumbnail($calc_vid_sec, -1, -1)) {
                         if (!$thumbMaker->createThumbnail(0, -1, -1)) {
                             $kalturaPath = realpath(dirname(__FILE__) . '/../../../../');
                             copy($kalturaPath . '/res/broken_thumb.jpg', $orig_image_path);
                         }
                     }
                 } else {
                     myFileConverter::autoCaptureFrame($entry_data_path, $capturedThumbPath . "temp_", $calc_vid_sec, -1, -1);
                 }
                 $cache->remove($orig_image_path);
             }
         }
         // resizing (and editing)) an image file that failes results in a long server waiting time
         // prevent this waiting time (of future requests) in case the resizeing failes
         $cache = new myCache("thumb-processing-resize", 5 * 60);
         // 5 minutes
         $processing = $cache->get($orig_image_path);
         if ($processing) {
             KExternalErrors::dieError(KExternalErrors::PROCESSING_CAPTURE_THUMBNAIL);
         }
         kFile::fullMkdir($tempThumbPath);
         if ($crop_provider) {
             $convertedImagePath = myFileConverter::convertImageUsingCropProvider($orig_image_path, $tempThumbPath, $width, $height, $type, $crop_provider, $bgcolor, true, $quality, $src_x, $src_y, $src_w, $src_h, $density, $stripProfiles);
         } else {
             if (!file_exists($orig_image_path)) {
                 KExternalErrors::dieError(KExternalErrors::IMAGE_RESIZE_FAILED);
             }
             $imageSizeArray = getimagesize($orig_image_path);
             if ($thumbParams->getSupportAnimatedThumbnail() && is_array($imageSizeArray) && $imageSizeArray[2] === IMAGETYPE_GIF) {
                 $tempThumbPath = kFile::replaceExt($tempThumbPath, "gif");
             }
             $convertedImagePath = myFileConverter::convertImage($orig_image_path, $tempThumbPath, $width, $height, $type, $bgcolor, true, $quality, $src_x, $src_y, $src_w, $src_h, $density, $stripProfiles, $thumbParams);
         }
         // die if resize operation failed and add failed resizing to cache
         if ($convertedImagePath === null || !@filesize($convertedImagePath)) {
             $cache->put($orig_image_path, true);
             KExternalErrors::dieError(KExternalErrors::IMAGE_RESIZE_FAILED);
         }
         // if resizing secceded remove from cache of failed resizing
         if ($cache->get($orig_image_path)) {
             $cache->remove($orig_image_path, true);
         }
         if ($multi) {
             list($w, $h, $type, $attr, $srcIm) = myFileConverter::createImageByFile($tempThumbPath);
             if (!$im) {
                 $im = imagecreatetruecolor($w * $vid_slices, $h);
             }
             imagecopy($im, $srcIm, $w * $vid_slice, 0, 0, 0, $w, $h);
             imagedestroy($srcIm);
             ++$vid_slice;
         }
     }
     if ($multi) {
         imagejpeg($im, $tempThumbPath);
         imagedestroy($im);
     }
     return $tempThumbPath;
 }