Ejemplo n.º 1
0
 public function getFrame($frame_number = false, $frame_rate = false)
 {
     try {
         $toolkit = new PHPVideoToolkit(PHPVIDEOTOOLKIT_TEMP_DIRECTORY);
         $tmp_name = $toolkit->unique() . '-%index.jpg';
         // 		extract the frame
         $toolkit->extractFrame($frame_number, $frame_rate, '%ft');
         $toolkit->setOutput(PHPVIDEOTOOLKIT_TEMP_DIRECTORY, $tmp_name, PHPVideoToolkit::OVERWRITE_EXISTING);
         $result = $this->_toolkit->execute(false, true);
         // 		check the image has been outputted
         if ($result !== PHPVideoToolkit::RESULT_OK) {
             return false;
         }
         $temp_output = array_shift(array_flip($toolkit->getLastOutput()));
         print_r($temp_output);
         $gd_img = imagecreatefromjpeg($temp_output);
         $ffmpeg_frame_time = $toolkit->formatTimecode($frame_number, '%ft', '%hh:%mm:%ss.%ms', $frame_rate);
     } catch (Exception $e) {
         echo $e;
     }
     return new ffmpeg_frame($gd_img, $ffmpeg_frame_time);
 }
Ejemplo n.º 2
0
 // 		get the filename parts
 $filename = basename($file);
 $filename_minus_ext = substr($filename, 0, strrpos($filename, '.'));
 // 		set the input file
 $ok = $toolkit->setInputFile($file);
 // 		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;
 }
 // 		set the output dimensions
 $toolkit->setVideoOutputDimensions(PHPVideoToolkit::SIZE_SQCIF);
 // 		extract a thumbnail from the fifth frame two seconds into the video
 $toolkit->extractFrame('00:00:02.5');
 // 		set the output details
 $ok = $toolkit->setOutput($thumbnail_output_dir, $filename_minus_ext . '.jpg', PHPVideoToolkit::OVERWRITE_EXISTING);
 // 		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
Ejemplo n.º 3
0
 /**
  * extract frame
  *
  * @param string $file 
  * @param string $time_frame 
  * @return void
  * @author Andy Bennett
  */
 public static function extract_frame($file = null, $time_frame = '00:00:00.1')
 {
     if (is_null($file)) {
         return null;
     }
     if (!defined('PHPVIDEOTOOLKIT_FFMPEG_BINARY')) {
         define('PHPVIDEOTOOLKIT_FFMPEG_BINARY', Kohana::config('ffmpeg.binaries_path'));
     }
     try {
         // require the library
         require_once 'phpvideotoolkit/phpvideotoolkit.php5.php';
         // start the timer collection
         $total_process_time = 0;
         $tmp_dir = Kohana::config('ffmpeg.tmp_path');
         // start PHPVideoToolkit class
         $toolkit = new PHPVideoToolkit($tmp_dir);
         // set PHPVideoToolkit class to run silently
         $toolkit->on_error_die = FALSE;
         // check the return value in-case of error
         if (!$toolkit->setInputFile($file)) {
             throw new Exception($toolkit->getLastError());
         }
         // set the output dimensions
         $toolkit->setVideoOutputDimensions(PHPVideoToolkit::SIZE_SAS);
         // same as source
         // extract a thumbnail
         $toolkit->extractFrame($time_frame);
         // get the filename parts
         $path = dirname($file) . '/';
         $filename = basename($file);
         $filename_minus_ext = substr($filename, 0, strrpos($filename, '.'));
         // set the output details
         $ok = $toolkit->setOutput($path, $filename_minus_ext . '.jpg', PHPVideoToolkit::OVERWRITE_EXISTING);
         // check the return value in-case of error
         if (!$ok) {
             throw new Exception($toolkit->getLastError());
         }
         // execute the ffmpeg command
         $result = $toolkit->execute(false, true);
         // check the return value in-case of error
         if ($result !== PHPVideoToolkit::RESULT_OK) {
             throw new Exception($toolkit->getLastError());
         }
         // reset
         $toolkit->reset();
         return true;
     } catch (Exception $e) {
         // echo $toolkit->getLastCommand().'<br />';
         echo $e->getMessage();
         $toolkit->reset();
     }
 }