public function evaluateTargetVideo(KDLVideoData $source)
 {
     $targetVid = clone $this->_video;
     $flavorVid = $this->_video;
     $sourceVid = $source;
     if ($this->_video->_id == "") {
         switch ($this->_container->_id) {
             case KDLContainerTarget::FLV:
                 $targetVid->_id = KDLVideoTarget::FLV;
                 break;
             case KDLContainerTarget::AVI:
                 $targetVid->_id = KDLVideoTarget::H264;
                 break;
             case KDLContainerTarget::MP4:
                 $targetVid->_id = KDLVideoTarget::H264;
                 break;
             case KDLContainerTarget::MOV:
                 $targetVid->_id = KDLVideoTarget::H264;
                 break;
             case KDLContainerTarget::_3GP:
                 $targetVid->_id = KDLVideoTarget::H264;
                 break;
             case KDLContainerTarget::OGG:
                 $targetVid->_id = KDLVideoTarget::THEORA;
                 break;
             case KDLContainerTarget::WMV:
                 $targetVid->_id = KDLVideoTarget::WMV2;
                 break;
             case KDLContainerTarget::ISMV:
                 $targetVid->_id = KDLVideoTarget::WVC1A;
                 break;
             case KDLContainerTarget::WEBM:
                 $targetVid->_id = KDLVideoTarget::VP8;
                 break;
             case KDLContainerTarget::MPEG:
             case KDLContainerTarget::MPEGTS:
             case KDLContainerTarget::APPLEHTTP:
                 $targetVid->_id = KDLVideoTarget::H264;
                 break;
         }
     }
     /*
      * Evaluate flavor frame-size
      */
     $this->evaluateTargetVideoFramesize($sourceVid, $targetVid);
     /*
      * Following code is a hack to overcome ffmpeg/x264 AR disorder 
      * that happens with several hdv source formats
      */
     $srcVcodec = $source->GetIdOrFormat();
     if (isset($srcVcodec) && in_array($srcVcodec, array("dvh3", "dvhp", "hdv1", "hdv2", "hdv3", "hdv6")) && !($targetVid->_width == 0 || $targetVid->_height == 0)) {
         $targetVid->_dar = round($targetVid->_width / $targetVid->_height, 4);
     }
     /*
      * Evaluate flavor bitrate
      */
     $this->evaluateTargetVideoBitrate($sourceVid, $targetVid);
     /*
      * Frame Rate - If the flavor fps is zero, evaluate it from the source and
      * the constants theshold.
      */
     $this->evaluateTargetVideoFramerate($sourceVid, $targetVid);
     /*
      * GOP - if gop not set, set it to 2sec according to the required frame rate,
      * otherwise if gop param is in sec (_isGopInSec) ==> calculate form framerate,
      * If framerate not set - DefaultGOP(60)
      */
     if ($flavorVid->_gop === null || $flavorVid->_gop == 0) {
         if (isset($targetVid->_frameRate)) {
             $targetVid->_gop = round(KDLConstants::DefaultGOPinSec * $targetVid->_frameRate);
         } else {
             $targetVid->_gop = KDLConstants::DefaultGOP;
         }
     } else {
         if (isset($flavorVid->_isGopInSec) && $flavorVid->_isGopInSec > 0) {
             if (isset($targetVid->_frameRate)) {
                 $targetVid->_gop = round($targetVid->_gop * $targetVid->_frameRate);
             } else {
                 $targetVid->_gop = KDLConstants::DefaultGOP;
             }
         }
     }
     $targetVid->_rotation = $sourceVid->_rotation;
     $targetVid->_scanType = $sourceVid->_scanType;
     return $targetVid;
 }
Exemple #2
0
 public function evaluateTargetVideo(KDLVideoData $source)
 {
     $targetVid = clone $this->_video;
     $flavorVid = $this->_video;
     $sourceVid = $source;
     if ($this->_video->_id == "") {
         switch ($this->_container->_id) {
             case KDLContainerTarget::FLV:
                 $targetVid->_id = KDLVideoTarget::FLV;
                 break;
             case KDLContainerTarget::AVI:
                 $targetVid->_id = KDLVideoTarget::H264;
                 break;
             case KDLContainerTarget::MP4:
             case KDLContainerTarget::M4V:
                 $targetVid->_id = KDLVideoTarget::H264;
                 break;
             case KDLContainerTarget::MOV:
                 $targetVid->_id = KDLVideoTarget::H264;
                 break;
             case KDLContainerTarget::_3GP:
                 $targetVid->_id = KDLVideoTarget::H264;
                 break;
             case KDLContainerTarget::OGG:
             case KDLContainerTarget::OGV:
                 $targetVid->_id = KDLVideoTarget::THEORA;
                 break;
             case KDLContainerTarget::WMV:
                 $targetVid->_id = KDLVideoTarget::WMV2;
                 break;
             case KDLContainerTarget::ISMV:
                 $targetVid->_id = KDLVideoTarget::WVC1A;
                 break;
             case KDLContainerTarget::WEBM:
                 $targetVid->_id = KDLVideoTarget::VP8;
                 break;
             case KDLContainerTarget::MPEG:
             case KDLContainerTarget::MPEGTS:
             case KDLContainerTarget::M2TS:
             case KDLContainerTarget::APPLEHTTP:
                 $targetVid->_id = KDLVideoTarget::H264;
                 break;
         }
     }
     /*
      * Evaluate flavor frame-size
      */
     $this->evaluateTargetVideoFramesize($sourceVid, $targetVid);
     /*
      * Following code is a hack to overcome ffmpeg/x264 AR disorder 
      * that happens with several hdv source formats
      */
     $srcVcodec = $source->GetIdOrFormat();
     if (isset($srcVcodec) && in_array($srcVcodec, array("dvh3", "dvhp", "hdv1", "hdv2", "hdv3", "hdv6")) && !($targetVid->_width == 0 || $targetVid->_height == 0)) {
         $targetVid->_dar = round($targetVid->_width / $targetVid->_height, 4);
     }
     /*
      * Evaluate flavor bitrate
      */
     $this->evaluateTargetVideoBitrate($sourceVid, $targetVid);
     /*
      * Frame Rate - If the flavor fps is zero, evaluate it from the source and
      * the constants theshold.
      */
     $this->evaluateTargetVideoFramerate($sourceVid, $targetVid);
     /*
      * GOP - if gop not set, set it to 2sec according to the required frame rate,
      * otherwise if gop param is in sec (_isGopInSec) ==> calculate form framerate,
      * If framerate not set - DefaultGOP(60)
      */
     if ($flavorVid->_gop === null || $flavorVid->_gop == 0) {
         if (isset($targetVid->_frameRate)) {
             $targetVid->_gop = round(KDLConstants::DefaultGOPinSec * $targetVid->_frameRate);
         } else {
             $targetVid->_gop = KDLConstants::DefaultGOP;
         }
     } else {
         if (isset($flavorVid->_isGopInSec) && $flavorVid->_isGopInSec > 0) {
             if (isset($targetVid->_frameRate)) {
                 $targetVid->_gop = round($targetVid->_gop * $targetVid->_frameRate);
             } else {
                 $targetVid->_gop = KDLConstants::DefaultGOP;
             }
         }
     }
     /*
      * Watermark - evaluate scale value in case of 'percentage-of-the-source'
      * Sample 'scale' value "x30%" stands for - 
      * make the height to be 30% of the source, calculate the width to match the height
      */
     if (isset($targetVid->_watermarkData) && isset($targetVid->_watermarkData->scale)) {
         $scaleArrNew = array();
         $scaleArr = explode("x", $targetVid->_watermarkData->scale);
         foreach ($scaleArr as $i => $val) {
             if (isset($val) && strlen($val) > 0) {
                 $arr = explode('%', $val);
                 if (count($arr) == 2) {
                     if (isset($sourceVid->_width) && isset($sourceVid->_height)) {
                         $val = round(($i == 0 ? $sourceVid->_width : $sourceVid->_height) * $arr[0] / 100);
                     } else {
                         $val = "";
                     }
                 }
             }
             $scaleArrNew[$i] = $val;
         }
         $targetVid->_watermarkData->scale = implode('x', $scaleArrNew);
     }
     $targetVid->_rotation = $sourceVid->_rotation;
     $targetVid->_scanType = $sourceVid->_scanType;
     return $targetVid;
 }