<commit_before><?php
/**
 * @package infra
 * @subpackage Media
 */
class KFFMpegThumbnailMaker extends KBaseThumbnailMaker
{
	protected $cmdPath;
	
	/**
	 * @param string $filePath
	 * @param string $cmdPath
	 */
	public function __construct($srcPath, $targetPath, $cmdPath = 'ffmpeg')
	{
		$this->cmdPath = $cmdPath;
		parent::__construct($srcPath, $targetPath);
	}
	
	public function createThumnail($position = null, $width = null, $height = null, $frameCount = 1, $targetType = "image2", $dar = null)
	{
		KalturaLog::debug("position[$position], width[$width], height[$height], frameCount[$frameCount], frameCount[$frameCount], dar[$dar]");
		
		// TODO - calculate the width and height according to dar
		$cmdArr = $this->getCommand($position, $width, $height, $frameCount, $targetType);

		$cmd= $cmdArr[0];
		{
			$rv = null;
			KalturaLog::info("Executing: $cmd");
			file_put_contents("$this->targetPath.log", $cmd, FILE_APPEND);
			$output = system( $cmd , $rv );
			KalturaLog::debug("Returned value: '$rv'");

			if($rv==0 && $this->parseOutput($output)==true)
				return true;
		}

		KalturaLog::debug("THUMB Capture Failure - First attempt failed due to ffmpeg crash or 'missing-keyframe' issue.\nSecond attempt with 'slow-thumb-capture' mode");
		$cmd= $cmdArr[1];
		if(isset($cmd) ){
			if($position>30) {
				KalturaLog::debug("THUMB Capture - can not run 2nd attempt - 'slow-thumb-capture' is allowed up to 30 sec position");
			}
			else {
				$rv = null;
				KalturaLog::info("Executing: $cmd");<commit_msg>fwr: #14775 - thumbs generated w/wrong aspect ratio  - dar is passed to fix it<commit_after><?php
/**
 * @package infra
 * @subpackage Media
 */
class KFFMpegThumbnailMaker extends KBaseThumbnailMaker
{
	protected $cmdPath;
	/**
	 * @param string $filePath
	 * @param string $cmdPath
	 */
	public function __construct($srcPath, $targetPath, $cmdPath = 'ffmpeg')
	{
		$this->cmdPath = $cmdPath;
		parent::__construct($srcPath, $targetPath);
	}
	
	public function createThumnail($position = null, $width = null, $height = null, $frameCount = 1, $targetType = "image2", $dar = null)
	{
		if(!isset($frameCount))
			$frameCount = 1;
		if(!isset($targetType))
			$targetType = "image2";		
		KalturaLog::debug("position[$position], width[$width], height[$height], frameCount[$frameCount], frameCount[$frameCount], dar[$dar]");
		if(isset($dar) && $dar>0 && isset($height)){
			$width = round($height*$dar);
		}
		// TODO - calculate the width and height according to dar
		$cmdArr = $this->getCommand($position, $width, $height, $frameCount, $targetType);

		$cmd= $cmdArr[0];
		{
			$rv = null;
			KalturaLog::info("Executing: $cmd");
			file_put_contents("$this->targetPath.log", $cmd, FILE_APPEND);
			$output = system( $cmd , $rv );
			KalturaLog::debug("Returned value: '$rv'");

			if($rv==0 && $this->parseOutput($output)==true)
				return true;
		}

		KalturaLog::debug("THUMB Capture Failure - First attempt failed due to ffmpeg crash or 'missing-keyframe' issue.\nSecond attempt with 'slow-thumb-capture' mode");
		$cmd= $cmdArr[1];
		if(isset($cmd) ){
			if($position>30) {
				KalturaLog::debug("THUMB Capture - can not run 2nd attempt - 'slow-thumb-capture' is allowed up to 30 sec position");
			}
			else {
				$rv = null;
				KalturaLog::info("Executing: $cmd");
{'fraction_non_alphanumeric': 0.16883904213398, 'fraction_numerical': 0.008487420430433464, 'mean_word_length': 4.5369127516778525, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6978460', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1116, 'n_words': 268}