Ejemplo n.º 1
0
		public static function gif($file, $options=array(), $target_extension='gif')
		{
// 			merge the options with the defaults
			$options = array_merge(array(
				'temp_dir'					=> '/tmp', 
				'width'						=> 320, 
				'height'					=> 240,
				'ratio'						=> false, //PHPVideoToolkit::RATIO_STANDARD, 
				'frame_rate'				=> 1, 
				'loop_output'				=> 0,	// 0 will loop endlessly
				'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_GIF);
			
			$toolkit->disableAudio();
			
			if($options['ratio'] !== false)
			{
				$toolkit->setVideoAspectRatio($options['ratio']);
			}
			$toolkit->setVideoOutputDimensions($options['width'], $options['height']);
			$toolkit->setVideoFrameRate($options['frame_rate']);
			$toolkit->addCommand('-loop_output', $options['loop_output']);
			
// 			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;
		}
Ejemplo n.º 2
0
 $toolkit->setVideoOutputDimensions(320, 240);
 // 		set the video to be converted to flv
 $toolkit->setFormatToFLV($samprate, $bitrate);
 // 		set the output details and overwrite if nessecary
 $ok = $toolkit->setOutput($video_output_dir, $filename_minus_ext . '.flv', PHPVideoToolkit::OVERWRITE_EXISTING);
 // 		check the return value in-case of error
 if (!$ok) {
     // 			if there was an error then get it
     echo $toolkit->getLastError() . "<br /><br />\r\n";
     $toolkit->reset();
     continue;
 }
 // 		execute the ffmpeg command using multiple passes and log the calls and ffmpeg results
 $result = $toolkit->execute(true, true);
 // 		get the last command given
 $command = $toolkit->getLastCommand();
 // 		echo $command[0]."<br />\r\n";
 // 		echo $command[1]."<br />\r\n";
 // 		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
     $toolkit->moveLog($log_dir . $filename_minus_ext . '.log');
     // 			if there was an error then get it
     echo $toolkit->getLastError() . "<br /><br />\r\n";
     $toolkit->reset();
     continue;
 }
 // 		get the process time of the file
 $process_time = $toolkit->getLastProcessTime();
 $total_process_time += $process_time;
 $file = array_shift($toolkit->getLastOutput());