コード例 #1
0
ファイル: KDLFlavor.php プロジェクト: GElkayam/server
 public function ValidateProduct(KDLMediaDataSet $source, KDLFlavor $product)
 {
     KalturaLog::log(".SRC-->" . $source->ToString());
     KalturaLog::log(".TRG-->" . $this->ToString());
     KalturaLog::log(".PRD-->" . $product->ToString());
     $rv = $product->ValidateFlavor();
     if ($source) {
         $srcVid = $source->_video;
         $srcAud = $source->_audio;
         $srcCont = $source->_container;
     } else {
         $srcVid = null;
         $srcAud = null;
         $srcCont = null;
     }
     /*
      * ARF (webex) sources don't have proper mediaInfo - thus can not validate the product, skip it
      * 
      * - The second portion of the 'if condition' is a workaround to handle invalidly passed inter-src 
      * asset both as a source and as a product. 
      * It is 'strstr' rather than 'strcmp', because call to 'product->ValidateFlavor' might add warnings to the ToString
      */
     //		if(isset($srcCont) && $srcCont->GetIdOrFormat()=='arf') {
     if (isset($srcCont) && $srcCont->GetIdOrFormat() == 'arf' || strstr($product->ToString(), $source->ToString()) != false) {
         KalturaLog::log("ARF (webex) sources don't have proper mediaInfo - thus can not validate the product");
         return true;
     }
     /*
      * WVM (DRM Widevine) sources don't have proper mediaInfo - thus can not validate the product, skip it
      */
     if (isset($this->_container) && $this->_container->GetIdOrFormat() == 'wvm') {
         KalturaLog::log("WVM (DRM Widevine) sources don't have proper mediaInfo - thus can not validate the product");
         return true;
     }
     /*
      * Evaluate source duration, to be used to check the product duration validity 
      */
     $plannedDur = 0;
     if ($this->_clipDur && $this->_clipDur > 0) {
         $plannedDur = $this->_clipDur;
         $vDur = $plannedDur;
         $aDur = $plannedDur;
         $cDur = $plannedDur;
     } else {
         $vDur = isset($srcVid) ? $srcVid->_duration : 0;
         $aDur = isset($srcAud) ? $srcAud->_duration : 0;
         $cDur = isset($srcCont) ? $srcCont->_duration : 0;
         $plannedDur = max(max($aDur, $vDur), $cDur);
     }
     /*
      * Allow conversion and fixing of invalidly muxed WEB-CAM recordecd files - 
      * - FLV/Sorenson/Nellimossr
      * - very HUGE duration
      * - very LOW bitrate - about several bits-per-sec.
      * In such cases the 'duration validation' is un-applicable
      *
     if(isset($srcVid) && $srcVid->IsFormatOf(array("h.263","h263","sorenson spark","vp6")) 
     && isset($srcAud) && $srcAud->IsFormatOf(array('nellymoser')) && $cDur>0 && isset($srcCont->_fileSize)){
     	if($srcCont->_fileSize*8000/$cDur<KDLSanityLimits::MinBitrate) {
     		KalturaLog::log("Invalid WEB-CAM source file. Duration validation is un-applicable");
     		return true;
     	}
     }
     */
     if ($this->_video !== null) {
         if ($product->_video === null) {
             $product->_errors[KDLConstants::VideoIndex][] = KDLErrors::ToString(KDLErrors::MissingMediaStream);
             $rv = false;
         } else {
             $prdVid = $product->_video;
             $trgVid = $this->_video;
             /*
              *  On short durations, the 'granulariity' of a single frame dur might cause invalidation. 
              *  Don't check for <2sec
              */
             if ($plannedDur > 2000) {
                 if ($prdVid->_duration < $plannedDur * KDLSanityLimits::MinDurationFactor || $prdVid->_duration > $plannedDur * KDLSanityLimits::MaxDurationFactor) {
                     //This check was added to filter out files that have no duration set on their metadata and are of type ogg or ogv to avoid failure on product validation (SUP 546)
                     if ($aDur == 0 && in_array(strtolower($this->_container->GetIdOrFormat()), array("ogg", "ogv"))) {
                         //Do Nothing
                     } else {
                         $product->_errors[KDLConstants::VideoIndex][] = KDLErrors::ToString(KDLErrors::InvalidDuration, $prdVid->_duration / 1000, $plannedDur / 1000);
                         $rv = false;
                     }
                 } else {
                     if ($prdVid->_duration < $plannedDur * KDLConstants::ProductDurationFactor) {
                         $product->_warnings[KDLConstants::VideoIndex][] = KDLWarnings::ToString(KDLWarnings::ProductShortDuration, $prdVid->_duration, $plannedDur);
                     }
                 }
             }
             if (isset($srcVid) && $prdVid->_bitRate < $trgVid->_bitRate * KDLConstants::ProductBitrateFactor) {
                 $product->_warnings[KDLConstants::VideoIndex][] = KDLWarnings::ToString(KDLWarnings::ProductLowBitrate, $prdVid->_bitRate, $srcVid->_bitRate);
             }
         }
     }
     if ($this->_audio !== null) {
         if ($product->_audio === null) {
             $product->_errors[KDLConstants::AudioIndex][] = KDLErrors::ToString(KDLErrors::MissingMediaStream);
             $rv = false;
         } else {
             $prdAud = $product->_audio;
             $trgAud = $this->_audio;
             /*
              * On short durations, the 'granulariity' of a single frame dur might cause invalidation.
              * Don't check for <2sec
              */
             if ($plannedDur > 2000) {
                 if ($prdAud->_duration < $plannedDur * KDLSanityLimits::MinDurationFactor || $prdAud->_duration > $plannedDur * KDLSanityLimits::MaxDurationFactor) {
                     $product->_errors[KDLConstants::AudioIndex][] = KDLErrors::ToString(KDLErrors::InvalidDuration, $prdAud->_duration / 1000, $plannedDur / 1000);
                     $rv = false;
                 } else {
                     if ($prdAud->_duration < $plannedDur * KDLConstants::ProductDurationFactor) {
                         $product->_warnings[KDLConstants::AudioIndex][] = KDLWarnings::ToString(KDLWarnings::ProductShortDuration, $prdAud->_duration, $plannedDur);
                     }
                 }
             }
             if (isset($srcAud) && $prdAud->_bitRate < $trgAud->_bitRate * KDLConstants::ProductBitrateFactor) {
                 $product->_warnings[KDLConstants::AudioIndex][] = KDLWarnings::ToString(KDLWarnings::ProductLowBitrate, $prdAud->_bitRate, $srcAud->_bitRate);
             }
         }
     }
     if ($product->_video === null && $product->_audio === null) {
         // "Invalid File - No media content.";
         $product->_errors[KDLConstants::ContainerIndex][] = KDLErrors::ToString(KDLErrors::NoValidMediaStream);
     }
     KalturaLog::log(".PRD-->" . $product->ToString());
     return $rv;
 }
コード例 #2
0
 public function ToString()
 {
     $rvStr = "flag({$this->_flags})";
     if ($this->_clipStart) {
         $rvStr .= ",clpStr({$this->_clipStart})";
     }
     if ($this->_clipDur) {
         $rvStr .= ",clpDur({$this->_clipDur})";
     }
     $rvStr .= "," . parent::ToString();
     if (count($this->_errors)) {
         $rvStr = $rvStr . ",ERRS(" . KDLUtils::arrayToString($this->_errors) . ")";
     }
     if (count($this->_warnings)) {
         $rvStr = $rvStr . ",WRNS(" . KDLUtils::arrayToString($this->_warnings) . ")";
     }
     if (count($this->_transcoders)) {
         $rvStr = $rvStr . ",TRNS(" . KDLUtils::arrayToString($this->_transcoders) . ")";
     }
     return $rvStr;
 }
コード例 #3
0
 public static function runMediasetTest(KDLMediaDataSet $mediaSet, &$dlPrc, $profile = null)
 {
     $inFile = realpath($mediaSet->_container->_fileName);
     //$mediaSet = 100; //new KDLMediaDataSet();
     KalturaLog::log("....S-->" . $mediaSet->ToString());
     //		unset($targetList); // Remarked by Tan-Tan $targetList doesn't exist
     $targetList = array();
     $errors = array();
     $warnings = array();
     $dlPrc = new KDLProcessor();
     $dlPrc->Generate($mediaSet, $profile, $targetList);
     $dlPrc->_targets = $targetList;
     $errors = $errors + $dlPrc->get_errors();
     $warnings = $warnings + $dlPrc->get_warnings();
     if (count($errors) > 0) {
         $rv = false;
     } else {
         $rv = true;
     }
     if ($rv == false) {
         KalturaLog::log("....E==>");
         print_r($errors);
         KalturaLog::log("\n");
     }
     KalturaLog::log("....W==>");
     print_r($warnings);
     KalturaLog::log("\n");
     if ($profile == null) {
         return;
     }
     $xmlStr = KDLProcessor::ProceessFlavorsForCollection($targetList);
     KalturaLog::log(__METHOD__ . "-->XML-->\n" . print_r($xmlStr, true) . "\n<--");
     foreach ($targetList as $target) {
         $output = array();
         $rv = 0;
         KalturaLog::log("...T-->" . $target->ToString());
         $outFile = "aaa1.mp4";
         if (file_exists($outFile)) {
             unlink($outFile);
         }
         $cmdLineGenerator = $target->SetTranscoderCmdLineGenerator($inFile, $outFile);
         $cmdLineGenerator->_clipDur = 10000;
         $exeStr = "FFMpeg " . $cmdLineGenerator->FFMpeg(null);
         //			KalturaLog::log( ".CMD-->".$exeStr);
         $exeStr = "cli_encode " . $cmdLineGenerator->Generate(new KDLOperationParams(KDLTranscoders::ON2), 1000);
         kLog::log(".CMD-->" . $exeStr);
         $exeStr = "mencoder " . $cmdLineGenerator->Generate(new KDLOperationParams(KDLTranscoders::MENCODER), 1000);
         kLog::log(".CMD-->" . $exeStr);
         $exeStr = "ffmpeg " . $cmdLineGenerator->Generate(new KDLOperationParams(KDLTranscoders::FFMPEG), 1000);
         kLog::log(".CMD-->" . $exeStr);
         exec($exeStr, $output, $rv);
         kLog::log("..RV-->In" . $inFile . "==>");
         if (!file_exists($outFile) || kFile::fileSize($outFile) == 0) {
             kLog::log("Failed");
         } else {
             kLog::log("Succeeded, Filesize:" . kFile::fileSize($outFile));
             $mediaInfoStr = shell_exec(MediaInfoProgram . " " . realpath($outFile));
             $medLoader = new KDLMediaInfoLoader($mediaInfoStr);
             $product = new KDLFlavor();
             $medLoader->Load($product);
             $target->ValidateProduct($mediaSet, $product);
             kLog::log("\n" . $mediaInfoStr);
             //				kLog::log( ".PRD-->".$product->ToString());
             //				unlink($outFile);
         }
     }
 }