Skip to content

Commit

Permalink
Merge pull request kaltura#6467 from kaltura/Mercury-13.9.0-SUP-11979…
Browse files Browse the repository at this point in the history
…-Thumbs-deinterlace

Mercury 13.9.0 sup 11979 thumbs deinterlace
  • Loading branch information
anatolkaltura authored Dec 4, 2017
2 parents 778f70e + d6e1ae9 commit 6dbdb17
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 22 deletions.
11 changes: 6 additions & 5 deletions alpha/apps/kaltura/lib/batch2/bcdl/kBusinessPreConvertDL.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,15 @@ private static function generateThumbnail(asset $srcAsset, thumbParamsOutput $de
if($srcAsset->getType() == assetType::FLAVOR)
{
/* @var $srcAsset flavorAsset */
$dar = null;
$params = array();
$mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($srcAsset->getId());
if($mediaInfo)
$dar = $mediaInfo->getVideoDar();

if($mediaInfo){
$params['dar'] = $mediaInfo->getVideoDar();
$params['scanType'] = $mediaInfo->getScanType();
}
// generates the thumbnail
$thumbMaker = new KFFMpegThumbnailMaker($srcPath, $destPath, kConf::get('bin_path_ffmpeg'));
$created = $thumbMaker->createThumnail($destThumbParamsOutput->getVideoOffset(), $srcAsset->getWidth(), $srcAsset->getHeight(), null, null, $dar);
$created = $thumbMaker->createThumnail($destThumbParamsOutput->getVideoOffset(), $srcAsset->getWidth(), $srcAsset->getHeight(), $params);
if(!$created || !file_exists($destPath))
{
$errDescription = "Thumbnail not captured";
Expand Down
5 changes: 4 additions & 1 deletion batch/batches/CaptureThumb/KAsyncCaptureThumb.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ private function captureThumb(KalturaBatchJob $job, KalturaCaptureThumbJobData $
// generates the thumbnail
$thumbMaker = new KFFMpegThumbnailMaker($mediaFile, $capturePath, self::$taskConfig->params->FFMpegCmd);
$videoOffset = max(0 ,min($thumbParamsOutput->videoOffset, $mediaInfoVidDur-1));
$created = $thumbMaker->createThumnail($videoOffset, $mediaInfoWidth, $mediaInfoHeight, null ,null, $mediaInfoDar, $mediaInfoVidDur);
$params['dar'] = $mediaInfoDar;
$params['vidDur'] = $mediaInfoVidDur;
$params['scanType'] = $mediaInfoScanType;
$created = $thumbMaker->createThumnail($videoOffset, $mediaInfoWidth, $mediaInfoHeight, $params);
if(!$created || !file_exists($capturePath))
return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::THUMBNAIL_NOT_CREATED, "Thumbnail not created", KalturaBatchJobStatus::FAILED);

Expand Down
4 changes: 3 additions & 1 deletion batch/batches/PostConvert/KAsyncPostConvert.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ private function postConvert(KalturaBatchJob $job, KalturaPostConvertJobData $da

// generates the thumbnail
$thumbMaker = new KFFMpegThumbnailMaker($mediaFile, $thumbPath, KBatchBase::$taskConfig->params->FFMpegCmd);
$created = $thumbMaker->createThumnail($data->thumbOffset, $mediaInfo->videoWidth, $mediaInfo->videoHeight, null, null, $mediaInfo->videoDar);
$params['dar'] = $mediaInfo->videoDar;
$params['scanType'] = $mediaInfo->scanType;
$created = $thumbMaker->createThumnail($data->thumbOffset, $mediaInfo->videoWidth, $mediaInfo->videoHeight, $params);

if(!$created || !file_exists($thumbPath))
{
Expand Down
28 changes: 24 additions & 4 deletions infra/media/thumbnailMaker/KBaseThumbnailMaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,30 @@ public function __construct($srcPath, $targetPath)
$this->targetPath = $targetPath;
}

public function createThumnail($position = null, $width = null, $height = null, $frameCount = 1, $targetType = "image2", $dar = null)
public function createThumnail($position = null, $width = null, $height = null, $params = array())
{
KalturaLog::debug("position[$position], width[$width], height[$height], frameCount[$frameCount], frameCount[$frameCount], dar[$dar]");
$cmd = $this->getCommand($position, $width, $height, $frameCount, $targetType);
if(!array_key_exists('frameCount', $params)){
$params['frameCount'] = 1;
}

if(!array_key_exists ('targetType', $params)){
$params['targetType'] = "image2";
}

if(!array_key_exists ('dar', $params)){
$params['dar'] = null;
}

if(!array_key_exists ('vidDur', $params)){
$params['vidDur'] = null;
}

if(!array_key_exists ('scanType', $params)){
$params['scanType'] = null;
}

KalturaLog::debug("position[$position], width[$width], height[$height], params[".serialize($params)."]");
$cmd = $this->getCommand($position, $width, $height, $params);
KalturaLog::info("Executing: $cmd");

$returnValue = null;
Expand All @@ -52,4 +72,4 @@ protected abstract function getCommand();
* @return int
*/
protected abstract function parseOutput($output);
}
}
47 changes: 36 additions & 11 deletions infra/media/thumbnailMaker/KFFMpegThumbnailMaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,35 @@ public function __construct($srcPath, $targetPath, $cmdPath = 'ffmpeg')
parent::__construct($srcPath, $targetPath);
}

public function createThumnail($position = null, $width = null, $height = null, $frameCount = 1, $targetType = "image2", $dar = null, $vidDur = null)
public function createThumnail($position = null, $width = null, $height = null, $params = array())
{
if(!isset($frameCount))
$frameCount = 1;
if(!isset($targetType))
$targetType = "image2";
KalturaLog::debug("position[$position], width[$width], height[$height], frameCount[$frameCount], frameCount[$frameCount], dar[$dar], vidDur[$vidDur]");
if(!array_key_exists('frameCount', $params)){
$params['frameCount'] = 1;
}

if(!array_key_exists ('targetType', $params)){
$params['targetType'] = "image2";
}

if(!array_key_exists ('dar', $params)){
$params['dar'] = null;
}

if(!array_key_exists ('vidDur', $params)){
$params['vidDur'] = null;
}

if(!array_key_exists ('scanType', $params)){
$params['scanType'] = null;
}

KalturaLog::debug("position[$position], width[$width], height[$height], params[".serialize($params)."]");
$dar = $params['dar'];
if(isset($dar) && $dar>0 && isset($height)){
$width = floor(round($height*$dar) /2) * 2;
$width = floor(round($height*$dar) /2) * 2;
}
// TODO - calculate the width and height according to dar
$cmdArr = $this->getCommand($position, $width, $height, $frameCount, $targetType, $vidDur);
$cmdArr = $this->getCommand($position, $width, $height, $params);

$cmd= $cmdArr[0];
$rv = null;
Expand Down Expand Up @@ -66,8 +83,16 @@ public function createThumnail($position = null, $width = null, $height = null,
return $rv? false: true;
}

protected function getCommand($position = null, $width = null, $height = null, $frameCount = 1, $targetType = "image2", $vidDur = null)
protected function getCommand($position = null, $width = null, $height = null, $params = array())
{
$frameCount = $params['frameCount'];
$targetType = $params['targetType'];
$vidDur = $params['vidDur'];
$scanType = $params['scanType'];
if(isset($scanType) && $scanType==1)
$scanType = " -deinterlace";
else $scanType = null;

$dimensions = (is_null($width) || is_null($height)) ? '' : ("-s ". $width ."x" . $height);

//In case the video length is less than 30 sec to the seek in the decoding phase and not in the muxing phase (related to SUP-2172)
Expand All @@ -84,9 +109,9 @@ protected function getCommand($position = null, $width = null, $height = null, $

$cmdArr = array();
// '-noautorotate' to adjust to ffm2.7.2 that automatically normalizes rotated sources
$cmdArr[] = "$this->cmdPath $position_str -noautorotate -i $this->srcPath -an -y -r 1 $dimensions -vframes $frameCount -f $targetType $position_str_suffix" .
$cmdArr[] = "$this->cmdPath $position_str -noautorotate -i $this->srcPath -an$scanType -y -r 1 $dimensions -vframes $frameCount -f $targetType $position_str_suffix" .
" $this->targetPath >> $this->targetPath.log 2>&1";
$cmdArr[] = "$this->cmdPath -noautorotate -i $this->srcPath $position_str -an -y -r 1 $dimensions -vframes $frameCount -f $targetType" .
$cmdArr[] = "$this->cmdPath -noautorotate -i $this->srcPath $position_str -an$scanType -y -r 1 $dimensions -vframes $frameCount -f $targetType" .
" $this->targetPath >> $this->targetPath.log 2>&1";
return $cmdArr;

Expand Down

0 comments on commit 6dbdb17

Please sign in to comment.