private static function evaluateTargetVideoBitrate(KDLVideoData $source, KDLVideoData $target)
 {
     if ($target->_isShrinkBitrateToSource != 1) {
         return $target->_bitRate;
     }
     $brSrcNorm = KDLVideoBitrateNormalize::NormalizeSourceToTarget($source->_id, $source->_bitRate, $target->_id);
     if ($target->_bitRate > $brSrcNorm) {
         $target->_bitRate = $brSrcNorm;
     }
     return $target->_bitRate = round($target->_bitRate, 0);
 }
Example #2
0
 /**
  * @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);
     }
 }