Skip to content

Commit

Permalink
Merge pull request #8039 from kaltura/Naos-14.13.0-PLAT-9602
Browse files Browse the repository at this point in the history
PLAT-9602: extract thumbnail stripe from segment of the video
  • Loading branch information
inbal-ben-david committed Jan 23, 2019
2 parents e0fdcc3 + 75e1856 commit d87b2c7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
28 changes: 25 additions & 3 deletions alpha/apps/kaltura/lib/myEntryUtils.class.php
Expand Up @@ -696,7 +696,8 @@ public static function createThumbnailFromEntry ( entry $entry , entry $source_e


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, $format = null, $fileSync = null)
$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, $format = null, $fileSync = null,
$start_sec = -1, $end_sec = -1)
{
if (is_null($thumbParams) || !($thumbParams instanceof kThumbnailParameters))
$thumbParams = new kThumbnailParameters();
Expand Down Expand Up @@ -733,6 +734,11 @@ public static function resizeEntryImage( entry $entry, $version , $width , $heig
$thumbName.= "_dns_{$density}";
if($stripProfiles)
$thumbName .= "_stp_{$stripProfiles}";

if($start_sec != -1)
$thumbName .= "_ssec_{$start_sec}";
if($end_sec != -1)
$thumbName .= "_esec_{$end_sec}";

$entryThumbFilename = $entry->getThumbnail();
if(!$entryThumbFilename)
Expand Down Expand Up @@ -816,6 +822,15 @@ public static function resizeEntryImage( entry $entry, $version , $width , $heig
if ($servingVODfromLive)
$orig_image_path = null;

if(($end_sec != -1 && (($end_sec * 1000) > $entryLengthInMsec)) || ($start_sec != -1 && $end_sec == -1))
{
$end_sec = $entryLengthInMsec / 1000;
}
if($start_sec == -1 && $end_sec != -1)
{
$start_sec = 0;
}

while($count--)
{
$thumbCaptureByPackager = false;
Expand All @@ -837,7 +852,14 @@ public static function resizeEntryImage( entry $entry, $version , $width , $heig
}
else if ($vid_slices != -1) // need to create a thumbnail at a specific slice
{
$calc_vid_sec = floor($entryLengthInMsec / $vid_slices * min($vid_slice, $vid_slices) / 1000);
if($start_sec != -1 && $end_sec != -1)
{
$calc_vid_sec = $start_sec + (($end_sec - $start_sec) / $vid_slices) * min($vid_slice, $vid_slices);
}
else
{
$calc_vid_sec = floor($entryLengthInMsec / $vid_slices * min($vid_slice, $vid_slices) / 1000);
}
}
else if ($entry->getStatus() != entryStatus::READY && $entry->getLengthInMsecs() == 0) // when entry is not ready and we don't know its duration
{
Expand All @@ -858,7 +880,7 @@ public static function resizeEntryImage( entry $entry, $version , $width , $heig
{
// creating the thumbnail is a very heavy operation
// prevent calling it in parallel for the same thumbnail for 5 minutes

$cacheLockKeyProcessing = "thumb-processing".$orig_image_path;
if ($cache && !$cache->add($cacheLockKeyProcessing, true, 5 * 60))
KExternalErrors::dieError(KExternalErrors::PROCESSING_CAPTURE_THUMBNAIL);
Expand Down
Expand Up @@ -87,6 +87,8 @@ public function execute()
$flavor_id = $this->getRequestParameter("flavor_id", null);
$file_name = $this->getRequestParameter("file_name", null);
$file_name = basename($file_name);
$start_sec = $this->getFloatRequestParameter("start_sec", -1);
$end_sec = $this->getFloatRequestParameter("end_sec", -1);

// actual width and height of image from which the src_* values were taken.
// these will be used to multiply the src_* parameters to make them relate to the original image size.
Expand Down Expand Up @@ -161,6 +163,21 @@ public function execute()
if($vid_slices > 0 && ($vid_slices * $height) >= 65500)
KExternalErrors::dieError(KExternalErrors::BAD_QUERY, "height($height) * vid_slices($vid_slices) must be between 0 and 65500");

if(!is_numeric($start_sec) || ($start_sec < 0 && $start_sec != -1))
{
KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'start_sec must be positive');
}

if(!is_numeric($end_sec) || ($end_sec < 0 && $end_sec != -1))
{
KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'end_sec must be positive');
}
if($start_sec != -1 && $end_sec != -1 && ($start_sec > $end_sec))
{
KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'start_sec cant be greater then end_sec');
}


if ($upload_token_id)
{
$upload_token = UploadTokenPeer::retrieveByPK($upload_token_id);
Expand Down Expand Up @@ -406,7 +423,7 @@ public function execute()

if ( ! $file_sync )
{
$tempThumbPath = $entry->getLocalThumbFilePath($version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices, $density, $stripProfiles, $flavor_id, $file_name );
$tempThumbPath = $entry->getLocalThumbFilePath($version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices, $density, $stripProfiles, $flavor_id, $file_name, $start_sec, $end_sec );
if (!$tempThumbPath ){
KExternalErrors::dieError ( KExternalErrors::MISSING_THUMBNAIL_FILESYNC );
}
Expand Down Expand Up @@ -436,7 +453,7 @@ public function execute()
try
{
$tempThumbPath = myEntryUtils::resizeEntryImage( $entry, $version , $width , $height , $type , $bgcolor , $crop_provider, $quality,
$src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices, $imageFilePath, $density, $stripProfiles, $thumbParams, $format);
$src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices, $imageFilePath, $density, $stripProfiles, $thumbParams, $format, null, $start_sec, $end_sec);
}
catch(Exception $ex)
{
Expand Down
4 changes: 2 additions & 2 deletions alpha/lib/model/entry.php
Expand Up @@ -3498,7 +3498,7 @@ protected function getTrackEntryString ($namespace, $customDataColumn, $value)
* @return the thumbnail path.
*/
public function getLocalThumbFilePath($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, $density = 0, $stripProfiles = false, $flavorId = null, $fileName = null)
$src_x = 0, $src_y = 0, $src_w = 0, $src_h = 0, $vid_sec = -1, $vid_slice = 0, $vid_slices = -1, $density = 0, $stripProfiles = false, $flavorId = null, $fileName = null, $start_sec = null, $end_sec = null)
{
$contentPath = myContentStorage::getFSContentRootPath ();
// if entry type is audio - serve generic thumb:
Expand Down Expand Up @@ -3545,7 +3545,7 @@ public function getLocalThumbFilePath($version , $width , $height , $type , $bgc
elseif ($this->getType () == entryType::MEDIA_CLIP || $this->getType() == entryType::PLAYLIST) {
try {
$msgPath = $this->getDefaultThumbPath($this->getType());
return myEntryUtils::resizeEntryImage ( $this, $version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices, $msgPath );
return myEntryUtils::resizeEntryImage ( $this, $version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices, $msgPath, 0, false, null, null, null, $start_sec, $end_sec);
} catch ( Exception $ex ) {
if ($ex->getCode () == kFileSyncException::FILE_DOES_NOT_EXIST_ON_CURRENT_DC) {
// get original flavor asset
Expand Down

0 comments on commit d87b2c7

Please sign in to comment.