Exemplo n.º 1
1
 /**
  * Gets a default format for the related path.
  * If a default format is not found then the fallback_format_class is used.
  *
  * @access public
  * @author Oliver Lillie
  * @package default
  * @param $path
  * @param $config Config
  * @param $fallback_format_class
  * @param $type
  * @return Format
  */
 public static function getFormatFor($path, $config, $fallback_format_class = 'Format', $type = 'output')
 {
     if (in_array($type, array('input', 'output')) === false) {
         throw new Exception('Unrecognised format type "' . $type . '".');
     }
     $format = null;
     $ext = pathinfo($path, PATHINFO_EXTENSION);
     if (empty($ext) === false) {
         $format = Extensions::toBestGuessFormat($ext);
     }
     //			check the requested class exists
     $class_name = '\\PHPVideoToolkit\\' . $fallback_format_class . (empty($format) === false ? '_' . ucfirst(strtolower($format)) : '');
     if (class_exists($class_name) === false) {
         $requested_class_name = $class_name;
         $class_name = '\\PHPVideoToolkit\\' . $fallback_format_class;
         if (class_exists($class_name) === false) {
             throw new Exception('Requested default format class does not exist, "' . ($requested_class_name === $class_name ? $class_name : $requested_class_name . '" and "' . $class_name . '"') . '".');
         }
     }
     //			check that it extends from the base Format class.
     if ($class_name !== '\\PHPVideoToolkit\\Format' && is_subclass_of($class_name, '\\PHPVideoToolkit\\Format') === false) {
         throw new Exception('The class "' . $class_name . '" is not a subclass of \\PHPVideoToolkit\\Format.');
     }
     return new $class_name($type, $config);
 }
Exemplo n.º 2
0
 /**
  * Returns the best guess output format object based on the given path.
  *
  * @access protected
  * @author Oliver Lillie
  * @param  string $path The output path of the resulting output.
  * @return object Returns an instance of a Format object or child class.
  */
 protected function _bestGuessOutputFormat($path)
 {
     $format = null;
     $ext = pathinfo($path, PATHINFO_EXTENSION);
     if (empty($ext) === false) {
         $format = Extensions::toBestGuessFormat($ext);
     }
     return $this->_getDefaultFormat('output', $this->_default_output_format, $format);
 }
Exemplo n.º 3
0
 /**
  * Process the output format just before the it is compiled into commands.
  *
  * @access protected
  * @author Oliver Lillie
  * @param Format &$output_format 
  * @return void
  */
 protected function _processOutputFormat(Format &$output_format = null, &$save_path, $overwrite)
 {
     //          check to see if we have been set and output format, if not generate an empty one.
     if ($output_format === null) {
         $format = null;
         $ext = pathinfo($save_path, PATHINFO_EXTENSION);
         if (empty($ext) === false) {
             $format = Extensions::toBestGuessFormat($ext);
         }
         $output_format = $this->getDefaultFormat(Format::OUTPUT, $format);
     }
     //          set the media into the format object so that we can update the format options that
     //          require a media object to process.
     $output_format->setMedia($this)->updateFormatOptions($save_path, $overwrite);
 }
Exemplo n.º 4
0
 /**
  * Gets a default format for the related path.
  * If a default format is not found then the fallback_format_class is used.
  *
  * @access public
  * @static
  * @author Oliver Lillie
  * @param string $path The file path to get the format for.
  * @param  PHPVideoToolkit\Config $config The config object.
  * @param string $fallback_format_class The fallback class to use of the format for the given path cannot be automatically determined.
  *  If null is given then a RuntimeException is thrown.
  * @param  constant $input_output_type Either Format::INPUT or Format::OUTPUT. Defaults to OUTPUT. It determines the format
  *  mode used to set various commands in the final ffmpeg exec call.
  * @return PHPVideToolkit\Format Returns an object extended from the PHPVideToolkit\Format class.
  * @throws \InvalidArgumentException If the $input_output_type is not valid.
  * @throws \InvalidArgumentException If the specified fallback class is attempted to be used but is not found.
  * @throws \LogicException If the generated class does not extend from PHPVideToolkit\Format.
  */
 public static function getFormatFor($path, $config, $fallback_format_class = 'Format', $type = Format::OUTPUT)
 {
     if (in_array($type, array(Format::OUTPUT, Format::INPUT)) === false) {
         throw new \InvalidArgumentException('Unrecognised format type "' . $type . '".');
     }
     $format = null;
     $ext = pathinfo($path, PATHINFO_EXTENSION);
     if (empty($ext) === false) {
         $format = Extensions::toBestGuessFormat($ext);
     }
     //          check the requested class exists
     $class_name = '\\PHPVideoToolkit\\' . $fallback_format_class . (empty($format) === false ? '_' . ucfirst(strtolower($format)) : '');
     if (class_exists($class_name) === false) {
         if ($fallback_format_class === null) {
             throw new \RuntimeException('It was not possible to generate the format class for `' . $path . '` and a fallback class was not given.');
         }
         $requested_class_name = $class_name;
         $class_name = '\\PHPVideoToolkit\\' . $fallback_format_class;
         if (class_exists($class_name) === false) {
             throw new \InvalidArgumentException('Requested default format class does not exist, "' . ($requested_class_name === $class_name ? $class_name : $requested_class_name . '" and "' . $class_name . '"') . '".');
         }
     }
     //          check that it extends from the base Format class.
     if ($class_name !== '\\PHPVideoToolkit\\Format' && is_subclass_of($class_name, '\\PHPVideoToolkit\\Format') === false) {
         throw new \LogicException('The class "' . $class_name . '" is not a subclass of \\PHPVideoToolkit\\Format.');
     }
     return new $class_name($type, $config);
 }