/** * @param BatchJob $dbBatchJob * @param kPostConvertJobData $data */ protected static function createThumbnail(BatchJob $dbBatchJob, kPostConvertJobData $data) { KalturaLog::debug("Post Convert finished with thumnail: " . $data->getThumbPath()); $ignoreThumbnail = false; // this logic decide when this thumbnail should be used $rootBatchJob = $dbBatchJob->getRootJob(); if ($rootBatchJob->getJobType() == BatchJobType::CONVERT_PROFILE) { $thisFlavorHeight = $data->getThumbHeight(); $thisFlavorBitrate = $data->getThumbBitrate(); $rootBatchJobData = $rootBatchJob->getData(); if (!$rootBatchJobData->getCreateThumb() || $rootBatchJobData->getThumbBitrate() > $thisFlavorBitrate) { $ignoreThumbnail = true; } elseif ($rootBatchJobData->getThumbBitrate() == $thisFlavorBitrate && $rootBatchJobData->getThumbHeight() > $thisFlavorHeight) { $ignoreThumbnail = true; } else { $rootBatchJobData->setThumbHeight($thisFlavorHeight); $rootBatchJobData->setThumbBitrate($thisFlavorBitrate); $rootBatchJob->setData($rootBatchJobData); $rootBatchJob->save(); } } if (!$ignoreThumbnail) { KalturaLog::debug("Saving thumbnail from: " . $data->getThumbPath()); // creats thumbnail the file sync $entry = $dbBatchJob->getEntry(false, false); if (!$entry) { KalturaLog::err("Entry not found [" . $dbBatchJob->getEntryId() . "]"); return; } KalturaLog::debug("Entry duration: " . $entry->getLengthInMsecs()); if (!$entry->getLengthInMsecs()) { KalturaLog::debug("Copy duration from flvor asset: " . $data->getFlavorAssetId()); $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($data->getFlavorAssetId()); if ($mediaInfo) { KalturaLog::debug("Set duration to: " . $mediaInfo->getContainerDuration()); $entry->setDimensions($mediaInfo->getVideoWidth(), $mediaInfo->getVideoHeight()); $entry->setLengthInMsecs($mediaInfo->getContainerDuration()); } } $entry->reload(); // make sure that the thumbnail version is the latest $entry->setThumbnail(".jpg"); $entry->save(); $syncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); kFileSyncUtils::moveFromFile($data->getThumbPath(), $syncKey); } }
/** * @param BatchJob $dbBatchJob * @param kPostConvertJobData $data */ protected static function createThumbnail(BatchJob $dbBatchJob, kPostConvertJobData $data) { $ignoreThumbnail = false; // this logic decide when this thumbnail should be used $entry = $dbBatchJob->getEntry(); if (!$entry) { return $dbBatchJob; } /* * Retrieve data describing the new thumb */ $thisFlavorHeight = $data->getThumbHeight(); $thisFlavorBitrate = $data->getThumbBitrate(); $thisFlavorId = $data->getFlavorAssetId(); /* * If there is already a thumb assigned to that entry, get the asset id that was used to grab the thumb. * For older entries (w/out grabbedFromAssetId), the original logic would be used. * For newer entries - retrieve mediaInfo's for th new and grabbed assest. * Use KDL logic to normalize the 'grabbed' and 'new' video bitrates. * Set ignoreThumbnail if the new br is lower than the normalized. */ if ($entry->getCreateThumb()) { $grabbedFromAssetId = $entry->getThumbGrabbedFromAssetId(); if (isset($grabbedFromAssetId)) { $thisMediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($thisFlavorId); $grabMediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($grabbedFromAssetId); if (isset($thisMediaInfo) && isset($grabMediaInfo)) { $normalizedBr = KDLVideoBitrateNormalize::NormalizeSourceToTarget($grabMediaInfo->getVideoFormat(), $grabMediaInfo->getVideoBitrate(), $thisMediaInfo->getVideoFormat()); $ignoreThumbnail = $normalizedBr >= $thisMediaInfo->getVideoBitrate() ? true : false; } else { $grabbedFromAssetId = null; } } /* * Nulled 'grabbedFromAssetId' notifies - there is no grabbed asset data available, * ==> use the older logic - w/out br normalizing */ if (!isset($grabbedFromAssetId)) { if ($entry->getThumbBitrate() > $thisFlavorBitrate) { $ignoreThumbnail = true; } elseif ($entry->getThumbBitrate() == $thisFlavorBitrate && $entry->getThumbHeight() > $thisFlavorHeight) { $ignoreThumbnail = true; } } } else { $ignoreThumbnail = true; } if (!$ignoreThumbnail) { $entry->setThumbHeight($thisFlavorHeight); $entry->setThumbBitrate($thisFlavorBitrate); $entry->setThumbGrabbedFromAssetId($thisFlavorId); $entry->save(); // creats thumbnail the file sync $entry = $dbBatchJob->getEntry(false, false); if (!$entry) { KalturaLog::err("Entry not found [" . $dbBatchJob->getEntryId() . "]"); return; } KalturaLog::info("Entry duration: " . $entry->getLengthInMsecs()); if (!$entry->getLengthInMsecs()) { KalturaLog::info("Copy duration from flvor asset: " . $data->getFlavorAssetId()); $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($data->getFlavorAssetId()); if ($mediaInfo) { KalturaLog::info("Set duration to: " . $mediaInfo->getContainerDuration()); $entry->setDimensionsIfBigger($mediaInfo->getVideoWidth(), $mediaInfo->getVideoHeight()); if ($entry->getCalculateDuration()) { $entry->setLengthInMsecs($mediaInfo->getContainerDuration()); } } } $entry->reload(); // make sure that the thumbnail version is the latest $entry->setThumbnail(".jpg"); $entry->save(); $syncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); kFileSyncUtils::moveFromFile($data->getThumbPath(), $syncKey); } }