Exemplo n.º 1
0
		public static function iPod($file, $options=array(), $target_extension='mp4')
		{
// 			merge the options with the defaults
			$options = array_merge(array(
				'temp_dir'					=> '/tmp', 
				'width'						=> 320, 
				'height'					=> 240,
				'frequency'					=> 44100, 
				'audio_bitrate'				=> 128, 
				'video_bitrate'				=> 1200, 
				'ratio'						=> false, //PHPVideoToolkit::RATIO_STANDARD, 
				'frame_rate'				=> 29.7, 
				'output_dir'				=> null,	// this doesn't have to be set it can be automatically retreived from 'output_file'
				'output_file'				=> '#filename.#ext', 	// you can use #filename to automagically hold the filename and #ext to automagically hold the target format extension
				'output_title'				=> '#filename', 	// you can use #filename to automagically hold the filename and #ext to automagically hold the target format extension
				'use_multipass'				=> false, 
				'generate_log'				=> true,
				'log_directory'				=> null,
				'die_on_error'				=> false,
				'overwrite_mode'			=> PHPVideoToolkit::OVERWRITE_FAIL
			), $options);
			
// 			start PHPVideoToolkit class
			require_once dirname(dirname(__FILE__)).DS.'phpvideotoolkit.php5.php';
			$toolkit = new PHPVideoToolkit($options['temp_dir']);
			$toolkit->on_error_die = $options['die_on_error'];
// 			get the output directory
			if($options['output_dir'])
			{
				$output_dir 	= $options['output_dir'];
			}
			else
			{
				$output_dir		= dirname($options['output_file']);
				$output_dir		= $output_dir == '.' ? dirname($file) : $output_dir;
			}
// 			get the filename parts
			$filename 			= basename($file);
			$filename_minus_ext = substr($filename, 0, strrpos($filename, '.'));
// 			get the output filename
			$output_filename	= str_replace(array('#filename', '#ext'), array($filename_minus_ext, $target_extension), basename($options['output_file']));
		
// 			set the input file
			$ok = $toolkit->setInputFile($file);
// 			check the return value in-case of error
			if(!$ok)
			{
				$toolkit->reset();
				array_push(self::$_error_messages, $toolkit->getLastError());
				return false;
			}
			$toolkit->setFormat(PHPVideoToolkit::FORMAT_MP4);
			
			$toolkit->setAudioSampleFrequency($options['frequency']);
			$toolkit->setAudioBitRate($options['audio_bitrate']);
// 			$toolkit->addCommand('-acodec', 'libfaac');
// 			$toolkit->addCommand('-acodec', 'mp3');
			
			$toolkit->setVideoFormat(PHPVideoToolkit::FORMAT_MPEG4);
			if($options['ratio'] !== false)
			{
				$toolkit->setVideoAspectRatio($options['ratio']);
			}
			$toolkit->setVideoOutputDimensions($options['width'], $options['height']);
			$toolkit->setVideoFrameRate($options['frame_rate']);
			$toolkit->addCommand('-mbd', '2');
			$toolkit->addCommand('-flags', '+4mv+trell');
			$toolkit->addCommand('-aic', '2');
			$toolkit->addCommand('-cmp', '2');
			$toolkit->addCommand('-subcmp', '2');
			
			$toolkit->addCommand('-title', str_replace(array('#filename', '#ext'), array($filename_minus_ext, $target_extension), basename($options['output_title'])));
		
// 			set the output details and overwrite if nessecary
			$ok = $toolkit->setOutput($output_dir, $output_filename, $options['overwrite_mode']);
// 			check the return value in-case of error
			if(!$ok)
			{
				$toolkit->reset();
				array_push(self::$_error_messages, $toolkit->getLastError());
				return false;
			}
			
// 			execute the ffmpeg command using multiple passes and log the calls and PHPVideoToolkit results
			$result = $toolkit->execute($options['use_multipass'], $options['generate_log']);
			array_push(self::$_commands, $toolkit->getLastCommand());
		
// 			check the return value in-case of error
			if($result !== PHPVideoToolkit::RESULT_OK)
			{
// 				move the log file to the log directory as something has gone wrong
				if($options['generate_log'])
				{
					$log_dir = $options['log_directory'] ? $options['log_directory'] : $output_dir;
					$toolkit->moveLog($log_dir.$filename_minus_ext.'.log');
					array_push(self::$_log_files, $log_dir.$filename_minus_ext.'.log');
				}
				$toolkit->reset();
				array_push(self::$_error_messages, $toolkit->getLastError());
				return $result;
			}
			
			array_push(self::$_outputs, $toolkit->getLastOutput());
			
// 			reset 
			$toolkit->reset();
			
			return $result;
		}