<commit_before><?php

include_once("KDLCommon.php");
include_once("KDLMediaDataSet.php");
include_once("KDLFlavor.php");
include_once("KDLOperatorBase.php");

	/* ===========================
	 * KDLOperatorWrapper
	 */
class KDLOperatorWrapper extends KDLOperatorBase {
    public function __construct($id, $name=null, $sourceBlacklist=null, $targetBlacklist=null) {
    	$srcBlacklist = $sourceBlacklist;
		if(is_null($sourceBlacklist) && array_key_exists($id, KDLConstants::$TranscodersSourceBlackList)) {
			$srcBlacklist = KDLConstants::$TranscodersSourceBlackList[$id];
		}
		$trgBlacklist = $targetBlacklist;
		if(is_null($targetBlacklist) && array_key_exists($id, KDLConstants::$TranscodersTargetBlackList)) {
			$trgBlacklist = KDLConstants::$TranscodersTargetBlackList[$id];
		}
    	parent::__construct($id,$name,$srcBlacklist,$trgBlacklist);
    }

	public function GenerateCommandLine(KDLFlavor $predesign, KDLFlavor $target, $extra=null)
	{
		$cmdLineGenerator = $target->SetTranscoderCmdLineGenerator();

		if($target->_video)
			$cmdLineGenerator->_vidBr = $target->_video->_bitRate;
		$params = new KDLOperationParams($this->_id, $extra);
		return $cmdLineGenerator->Generate($params, $predesign->_video->_bitRate);
	}
	
    /* ---------------------------
	 * CheckConstraints
	 */
	public function CheckConstraints(KDLMediaDataSet $source, KDLFlavor $target, array &$errors=null, array &$warnings=null)
	{
//		if(array_key_exists($this->_id, KDLConstants::$TranscodersSourceBlackList)) {
//			$this->_sourceBlacklist = KDLConstants::$TranscodersSourceBlackList[$this->_id];
//		}
//		if(array_key_exists($this->_id, KDLConstants::$TranscodersTargetBlackList)) {
//			$this->_targetBlacklist = KDLConstants::$TranscodersTargetBlackList[$this->_id];
//		}
		if(parent::CheckConstraints($source, $target, $errors, $warnings)==true)
			return true;
			
		/*
		 * Remove encoding.com for DAR<>PAR
		 */
		if($this->_id==KDLTranscoders::ENCODING_COM
		&& $source->_video && $source->_video->_dar
		&& abs($source->_video->GetPAR()-$source->_video->_dar)>0.01) {
			$warnings[KDLConstants::VideoIndex][] = //"The transcoder (".$key.") can not process the (".$sourcePart->_id."/".$sourcePart->_format. ").";
				KDLWarnings::ToString(KDLWarnings::TranscoderFormat, $this->_id, "non square pixels");
			return true;
		}
			
		/*
		 * Remove mencoder, encoding.com and cli_encode
		 * for audio only flavors
		 */
		if(($this->_id==KDLTranscoders::MENCODER || $this->_id==KDLTranscoders::ENCODING_COM || $this->_id==KDLTranscoders::ON2)
		&& $target->_video==null) {
			$warnings[KDLConstants::AudioIndex][] = //"The transcoder (".$key.") does not handle properly DAR<>PAR.";
				KDLWarnings::ToString(KDLWarnings::TranscoderLimitation, $this->_id);
			return true;
		}

		/*
		 * Remove encoding.com and ffmpegs
		 * for rotated videos
		 */
		if(($this->_id==KDLTranscoders::ENCODING_COM || $this->_id==KDLTranscoders::FFMPEG || $this->_id==KDLTranscoders::FFMPEG_AUX)
		&& $target->_video && $target->_video->_rotation) {
			$warnings[KDLConstants::VideoIndex][] = //"The transcoder (".$key.") does not handle properly DAR<>PAR.";
				KDLWarnings::ToString(KDLWarnings::TranscoderLimitation, $this->_id);
			return true;
		}
		
		/*
		 * Non Mac transcoders should not mess up with QT/WMV/WMA
		 * 
		 */
		$qt_wmv_list = array("wmv1","wmv2","wmv3","wvc1","wmva","wma1","wma2","wmapro");
		if(($this->_id==KDLTranscoders::ENCODING_COM || $this->_id==KDLTranscoders::FFMPEG || $this->_id==KDLTranscoders::FFMPEG_AUX
		|| $this->_id==KDLTranscoders::MENCODER || $this->_id==KDLTranscoders::ON2)
		&& $source->_container && ($source->_container->_id=="qt" || $source->_container->_format=="qt")
		&& (
			($source->_video && (in_array($source->_video->_format,$qt_wmv_list)||in_array($source->_video->_id,$qt_wmv_list)))
			||($source->_audio && (in_array($source->_audio->_format,$qt_wmv_list)||in_array($source->_audio->_id,$qt_wmv_list)))
			)
		){
			$warnings[KDLConstants::VideoIndex][] = //"The transcoder (".$key.") can not process the (".$sourcePart->_id."/".$sourcePart->_format. ").";
				KDLWarnings::ToString(KDLWarnings::TranscoderFormat, $this->_id, "qt/wmv/wma");
			return true;
		}
		
		return false;	
	}
}


	/* ===========================
	 * KDLTranscoderCommand
	 */
class KDLTranscoderCommand {
	
			public $_vidId;
			public $_vidBr;
			public $_vidWid;
			public $_vidHgt;
			public $_vidFr;
			public $_vidGop;
			public $_vid2pass;
			public $_vidRotation;
			public $_vidScanType;
			
			public $_audId;
			public $_audBr; 
			public $_audCh;
			public $_audSr;
			
			public $_conId;
			
			public $_inFileName=KDLCmdlinePlaceholders::InFileName;
			public $_outFileName=KDLCmdlinePlaceholders::OutFileName;
			public $_clipStart=null;
			public $_clipDur=null;
			
	public function KDLTranscoderCommand($inFileName=KDLCmdlinePlaceholders::InFileName, $outFileName=KDLCmdlinePlaceholders::OutFileName, $clipStart=null, $clipDur=null)
	{
		$this->_inFileName=$inFileName;
		$this->_outFileName=$outFileName;
		$this->_clipStart=$clipStart;
		$this->_clipDur=$clipDur;
	}
	
	/* ---------------------------
	 * Generate
	 */
	public function Generate(KDLOperationParams $transParams, $maxVidRate)
	{
		$cmd=null;
		switch($transParams->_id){
			case KDLTranscoders::KALTURA:
				$cmd=$transParams->_id;
				break;
			case KDLTranscoders::ON2:
				$cmd=$this->CLI_Encode($transParams->_extra);;
				break;
			case KDLTranscoders::FFMPEG:
				$this->fixVP6BitRate($maxVidRate);
				$cmd=$this->FFMpeg($transParams->_extra);
				break;
			case KDLTranscoders::MENCODER:
				$this->fixVP6BitRate($maxVidRate);
				$cmd=$this->Mencoder($transParams->_extra);
				break;
			case KDLTranscoders::ENCODING_COM:
				$cmd=$transParams->_id;
				break;
			case KDLTranscoders::FFMPEG_AUX:
			case KDLTranscoders::FFMPEG_VP8:
				$this->fixVP6BitRate($maxVidRate);
				$cmd=$this->FFMpeg_aux($transParams->_extra);
				break;
			case KDLTranscoders::EE3:
				$cmd=$this->EE3($transParams->_extra);
				break;
		}
		return $cmd;
	}
	
	/* ---------------------------
	 * FFMpeg
	 */
	public function FFMpeg($extra=null)
	{
	$cmdStr = null;
// rem ffmpeg -i <infilename> -vcodec flv   -r 25 -b 500k  -ar 22050 -ac 2 -acodec libmp3lame -f flv -t 60 -y <outfilename>
$vcodecParams = "fl";
$format = "fl";
$acodec = "libmp3lam";

		if($this->_clipStart!==null && $this->_clipStart>0){
			$cmdStr = $cmdStr." -ss ".$this->_clipStart/1000;
		}
		
		if($this->_clipDur!==null && $this->_clipDur>0){
			$cmdStr = $cmdStr." -t ".$this->_clipDur/1000;
		}
		
if($this->_inFileName){
			$cmdStr .= " -i ".$this->_inFileName;
		}
		if($this->_vidId!="none"){
			switch($this->_vidId){
				case KDLVideoTarget::FLV:
				case KDLVideoTarget::H263:
				case KDLVideoTarget::VP6:
					$vcodecParams = "flv";
					break; 
				case KDLVideoTarget::H264:
				case KDLVideoTarget::H264B:
				case KDLVideoTarget::H264M:
				case KDLVideoTarget::H264H:
					$vcodecParams = $this->generateH264params(KDLTranscoders::FFMPEG);
					break; 				
/*
				case KDLVideoTarget::H264:
					$vcodecParams = "libx264";
					break;
				case KDLVideoTarget::H264B:
					$vcodecParams = "libx264 -coder 0";
					break;
				case KDLVideoTarget::H264M:
					$vcodecParams = "libx264 -bf 8 -coder 1 -refs 2";
					break;
				case KDLVideoTarget::H264H:
					$vcodecParams = "libx264 -bf 16 -coder 1 -refs 6 -flags2 +bpyramid+wpred+mixed_refs+dct8x8+fastpskip";
					break;<commit_msg>minor<commit_after><?php

include_once("KDLCommon.php");
include_once("KDLMediaDataSet.php");
include_once("KDLFlavor.php");
include_once("KDLOperatorBase.php");

	/* ===========================
	 * KDLOperatorWrapper
	 */
class KDLOperatorWrapper extends KDLOperatorBase {
    public function __construct($id, $name=null, $sourceBlacklist=null, $targetBlacklist=null) {
    	$srcBlacklist = $sourceBlacklist;
		if(is_null($sourceBlacklist) && array_key_exists($id, KDLConstants::$TranscodersSourceBlackList)) {
			$srcBlacklist = KDLConstants::$TranscodersSourceBlackList[$id];
		}
		$trgBlacklist = $targetBlacklist;
		if(is_null($targetBlacklist) && array_key_exists($id, KDLConstants::$TranscodersTargetBlackList)) {
			$trgBlacklist = KDLConstants::$TranscodersTargetBlackList[$id];
		}
    	parent::__construct($id,$name,$srcBlacklist,$trgBlacklist);
    }

	public function GenerateCommandLine(KDLFlavor $predesign, KDLFlavor $target, $extra=null)
	{
		$cmdLineGenerator = $target->SetTranscoderCmdLineGenerator();

		if($target->_video)
			$cmdLineGenerator->_vidBr = $target->_video->_bitRate;
		$params = new KDLOperationParams($this->_id, $extra);
		return $cmdLineGenerator->Generate($params, $predesign->_video->_bitRate);
	}
	
    /* ---------------------------
	 * CheckConstraints
	 */
	public function CheckConstraints(KDLMediaDataSet $source, KDLFlavor $target, array &$errors=null, array &$warnings=null)
	{
//		if(array_key_exists($this->_id, KDLConstants::$TranscodersSourceBlackList)) {
//			$this->_sourceBlacklist = KDLConstants::$TranscodersSourceBlackList[$this->_id];
//		}
//		if(array_key_exists($this->_id, KDLConstants::$TranscodersTargetBlackList)) {
//			$this->_targetBlacklist = KDLConstants::$TranscodersTargetBlackList[$this->_id];
//		}
		if(parent::CheckConstraints($source, $target, $errors, $warnings)==true)
			return true;
			
		/*
		 * Remove encoding.com for DAR<>PAR
		 */
		if($this->_id==KDLTranscoders::ENCODING_COM
		&& $source->_video && $source->_video->_dar
		&& abs($source->_video->GetPAR()-$source->_video->_dar)>0.01) {
			$warnings[KDLConstants::VideoIndex][] = //"The transcoder (".$key.") can not process the (".$sourcePart->_id."/".$sourcePart->_format. ").";
				KDLWarnings::ToString(KDLWarnings::TranscoderFormat, $this->_id, "non square pixels");
			return true;
		}
			
		/*
		 * Remove mencoder, encoding.com and cli_encode
		 * for audio only flavors
		 */
		if(($this->_id==KDLTranscoders::MENCODER || $this->_id==KDLTranscoders::ENCODING_COM || $this->_id==KDLTranscoders::ON2)
		&& $target->_video==null) {
			$warnings[KDLConstants::AudioIndex][] = //"The transcoder (".$key.") does not handle properly DAR<>PAR.";
				KDLWarnings::ToString(KDLWarnings::TranscoderLimitation, $this->_id);
			return true;
		}

		/*
		 * Remove encoding.com and ffmpegs
		 * for rotated videos
		 */
		if(($this->_id==KDLTranscoders::ENCODING_COM || $this->_id==KDLTranscoders::FFMPEG || $this->_id==KDLTranscoders::FFMPEG_AUX)
		&& $target->_video && $target->_video->_rotation) {
			$warnings[KDLConstants::VideoIndex][] = //"The transcoder (".$key.") does not handle properly DAR<>PAR.";
				KDLWarnings::ToString(KDLWarnings::TranscoderLimitation, $this->_id);
			return true;
		}
		
		/*
		 * Non Mac transcoders should not mess up with QT/WMV/WMA
		 * 
		 */
		$qt_wmv_list = array("wmv1","wmv2","wmv3","wvc1","wmva","wma1","wma2","wmapro");
		if(($this->_id==KDLTranscoders::ENCODING_COM || $this->_id==KDLTranscoders::FFMPEG || $this->_id==KDLTranscoders::FFMPEG_AUX
		|| $this->_id==KDLTranscoders::MENCODER || $this->_id==KDLTranscoders::ON2)
		&& $source->_container && ($source->_container->_id=="qt" || $source->_container->_format=="qt")
		&& (
			($source->_video && (in_array($source->_video->_format,$qt_wmv_list)||in_array($source->_video->_id,$qt_wmv_list)))
			||($source->_audio && (in_array($source->_audio->_format,$qt_wmv_list)||in_array($source->_audio->_id,$qt_wmv_list)))
			)
		){
			$warnings[KDLConstants::VideoIndex][] = //"The transcoder (".$key.") can not process the (".$sourcePart->_id."/".$sourcePart->_format. ").";
				KDLWarnings::ToString(KDLWarnings::TranscoderFormat, $this->_id, "qt/wmv/wma");
			return true;
		}
		
		return false;	
	}
}


	/* ===========================
	 * KDLTranscoderCommand
	 */
class KDLTranscoderCommand {
	
			public $_vidId;
			public $_vidBr;
			public $_vidWid;
			public $_vidHgt;
			public $_vidFr;
			public $_vidGop;
			public $_vid2pass;
			public $_vidRotation;
			public $_vidScanType;
			
			public $_audId;
			public $_audBr; 
			public $_audCh;
			public $_audSr;
			
			public $_conId;
			
			public $_inFileName=KDLCmdlinePlaceholders::InFileName;
			public $_outFileName=KDLCmdlinePlaceholders::OutFileName;
			public $_clipStart=null;
			public $_clipDur=null;
			
	public function KDLTranscoderCommand($inFileName=KDLCmdlinePlaceholders::InFileName, $outFileName=KDLCmdlinePlaceholders::OutFileName, $clipStart=null, $clipDur=null)
	{
		$this->_inFileName=$inFileName;
		$this->_outFileName=$outFileName;
		$this->_clipStart=$clipStart;
		$this->_clipDur=$clipDur;
	}
	
	/* ---------------------------
	 * Generate
	 */
	public function Generate(KDLOperationParams $transParams, $maxVidRate)
	{
		$cmd=null;
		switch($transParams->_id){
			case KDLTranscoders::KALTURA:
				$cmd=$transParams->_id;
				break;
			case KDLTranscoders::ON2:
				$cmd=$this->CLI_Encode($transParams->_extra);;
				break;
			case KDLTranscoders::FFMPEG:
				$this->fixVP6BitRate($maxVidRate);
				$cmd=$this->FFMpeg($transParams->_extra);
				break;
			case KDLTranscoders::MENCODER:
				$this->fixVP6BitRate($maxVidRate);
				$cmd=$this->Mencoder($transParams->_extra);
				break;
			case KDLTranscoders::ENCODING_COM:
				$cmd=$transParams->_id;
				break;
			case KDLTranscoders::FFMPEG_AUX:
			case KDLTranscoders::FFMPEG_VP8:
				$this->fixVP6BitRate($maxVidRate);
				$cmd=$this->FFMpeg_aux($transParams->_extra);
				break;
			case KDLTranscoders::EE3:
				$cmd=$this->EE3($transParams->_extra);
				break;
		}
		return $cmd;
	}
	
	/* ---------------------------
	 * FFMpeg
	 */
	public function FFMpeg($extra=null)
	{
	$cmdStr = null;
// rem ffmpeg -i <infilename> -vcodec flv   -r 25 -b 500k  -ar 22050 -ac 2 -acodec libmp3lame -f flv -t 60 -y <outfilename>
$vcodecParams = "fl";
$format = "fl";
$acodec = "libmp3lam";

		if($this->_clipStart!==null && $this->_clipStart>0){
			$cmdStr = $cmdStr." -ss ".$this->_clipStart/1000;
		}
		
		if($this->_clipDur!==null && $this->_clipDur>0){
			$cmdStr = $cmdStr." -t ".$this->_clipDur/1000;
		}
		
		if($this->_inFileName){
			$cmdStr .= " -i ".$this->_inFileName;
		}
		if($this->_vidId!="none"){
			switch($this->_vidId){
				case KDLVideoTarget::FLV:
				case KDLVideoTarget::H263:
				case KDLVideoTarget::VP6:
					$vcodecParams = "flv";
					break; 
				case KDLVideoTarget::H264:
				case KDLVideoTarget::H264B:
				case KDLVideoTarget::H264M:
				case KDLVideoTarget::H264H:
					$vcodecParams = $this->generateH264params(KDLTranscoders::FFMPEG);
					break; 				
/*
				case KDLVideoTarget::H264:
					$vcodecParams = "libx264";
					break;
				case KDLVideoTarget::H264B:
					$vcodecParams = "libx264 -coder 0";
					break;
				case KDLVideoTarget::H264M:
					$vcodecParams = "libx264 -bf 8 -coder 1 -refs 2";
					break;
				case KDLVideoTarget::H264H:
					$vcodecParams = "libx264 -bf 16 -coder 1 -refs 6 -flags2 +bpyramid+wpred+mixed_refs+dct8x8+fastpskip";
					break;
{'fraction_non_alphanumeric': 0.18440096488876978, 'fraction_numerical': 0.013133208255159476, 'mean_word_length': 4.401737242128122, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 203, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6329903', 'n_tokens_mistral': 6146, 'n_tokens_neox': 5247, 'n_words': 777}