Example #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;
		}
Example #2
0
    // 		check the return value in-case of error
    if (!$ok) {
        // 			if there was an error then get it
        echo '<b>' . $toolkit->getLastError() . "</b><br />\r\n";
        $toolkit->reset();
        continue;
    }
    // 		execute the ffmpeg command
    $result = $toolkit->execute(false, true);
    // 		get the last command given
    // 		$command = $toolkit->getLastCommand();
    // 		echo $command."<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 '<b>' . $toolkit->getLastError() . "</b><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());
    echo 'Frame grabbed in ' . $process_time . ' seconds... <b>' . $thumbnail_output_dir . $file . '</b><br />' . "\r\n";
    echo '<img src="processed/thumbnails/' . $file . '" alt="" border="0" /><br /><br />';
    // 		reset
    $toolkit->reset();
}
echo '<br />' . "\r\n" . 'The total time taken to process all ' . ($key + 1) . ' file(s) is : <b>' . $total_process_time . '</b>';
Example #3
0
}
// 	set a different output size (this will shrink the images to a video that is smaller, the images are 320x240)
$toolkit->setVideoOutputDimensions(160, 120);
// 	set endless looping
$toolkit->setGifLoops(0);
// 	$toolkit->addAudio($sound);
// 	set the output parameters
$ok = $toolkit->setOutput($video_output_dir, $output_filename, PHPVideoToolkit::OVERWRITE_EXISTING);
if (!$ok) {
    // 		if there was an error then get it
    echo $toolkit->getLastError() . "<br />\r\n";
    exit;
}
// 	execute the ffmpeg command
$result = $toolkit->execute(false, true);
// 	get the last command given
// 	$command = $toolkit->getLastCommand();
// 	echo $command."<br />\r\n<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 . 'example03.log');
    // 		if there was an error then get it
    echo $toolkit->getLastError() . "<br />\r\n";
    exit;
}
$toolkit->moveLog($log_dir . 'example03.log');
$img = array_shift($toolkit->getLastOutput());
echo "Video created from images... <b>" . basename($img) . "</b><br />";
echo '<img src="processed/videos/' . basename($img) . '" border="0" /><br /><br />';
echo '</body></html>';