public function __construct($callback = null, Config $config = null)
 {
     //			check that the "-progress" function is available.
     $parser = new FfmpegParser($config);
     $available_commands = $parser->getCommands();
     if (isset($available_commands['progress']) === false) {
         throw new Exception('Your version of FFmpeg cannot support the Native progress handler. Please use ProgressHandlerOutput instead.');
     }
     parent::__construct($callback, $config);
     $this->_progress_file = null;
 }
 /**
  * Sets a command on ffmpeg that sets a timelimit
  *
  * @access public
  * @author Oliver Lillie
  * @param string $timelimit_in_seconds 
  * @return self
  */
 public function setProcessTimelimit($timelimit_in_seconds)
 {
     $parser = new FfmpegParser($this->_config);
     $commands = $parser->getCommands();
     if (isset($commands['timelimit']) === false) {
         throw new Exception('The -timelimit command is not supported by your version of FFmpeg.');
     }
     if ($timelimit_in_seconds <= 0) {
         throw new Exception('The timelimit must be greater than 0 seconds.');
     }
     $this->addCommand('-timelimit', $timelimit_in_seconds);
     return $this;
 }
 /**
  * Sets a command on ffmpeg that sets a timelimit for the process. If this timelimit is exceeded then ffmpeg bails.
  *
  * @access public
  * @author Oliver Lillie
  * @param integer $timelimit_in_seconds The timelimit to impose in seconds.
  * @return PHPVideoToolkit\FfmpegProcess Returns the current object.
  * @throws PHPVideoToolkit\FfmpegProcessCommandUnavailableException If the timelimit command is not available on the configured ffmpeg.
  * @throws \InvalidArgumentException If the timelimit is not an integer.
  * @throws \InvalidArgumentException If the timelimit is less than or equal to 0.
  */
 public function setProcessTimelimit($timelimit_in_seconds)
 {
     $parser = new FfmpegParser($this->_config);
     $commands = $parser->getCommands();
     if (isset($commands['timelimit']) === false) {
         throw new FfmpegProcessCommandUnavailableException('The -timelimit command is not supported by your version of FFmpeg.');
     }
     if (is_int($timelimit_in_seconds) === false) {
         throw new \InvalidArgumentException('The timelimit in seconds argument must be an integer.');
     } else {
         if ($timelimit_in_seconds <= 0) {
             throw new \InvalidArgumentException('The timelimit must be greater than 0 seconds.');
         }
     }
     $this->addCommand('-timelimit', $timelimit_in_seconds);
     return $this;
 }
예제 #4
0
 public function __construct($input_output_type, Config $config = null)
 {
     parent::__construct($config);
     $this->setType($input_output_type);
     $this->_additional_commands = array();
     $this->_removed_commands = array();
     $this->_media_object = null;
     $this->_format = array('quality' => null, 'format' => null, 'strictness' => null, 'preset_options_file' => null, 'threads' => null);
     $this->_format_to_command = array('quality' => '-q <setting>', 'format' => '-f <setting>', 'strictness' => '-strict <setting>', 'preset_options_file' => '-fpre <setting>', 'threads' => '-threads <setting>');
     //			add default input/output commands
     if ($input_output_type === 'output') {
         $this->setThreads(1)->setStrictness('experimental')->setQualityVsStreamabilityBalanceRatio(4);
     } else {
         if ($input_output_type === 'input') {
         } else {
             throw new Exception('Unrecognised input/output type "' . $input_output_type . '" set in \\PHPVideoToolkit\\Format::__construct');
         }
     }
 }
<?php

namespace PHPVideoToolkit;

include_once './includes/bootstrap.php';
$ffmpeg = new FfmpegParser();
$is_available = $ffmpeg->isAvailable();
Trace::vars('$ffmpeg->isAvailable()', $is_available);
$ffmpeg_version = $ffmpeg->getVersion();
Trace::vars('$ffmpeg->getVersion()', $ffmpeg_version);
$has_ffmpeg_php_support = $ffmpeg->hasFfmpegPhpSupport();
Trace::vars('$ffmpeg->hasFfmpegPhpSupport()', $has_ffmpeg_php_support);
$basic_ffmpeg_information = $ffmpeg->getFfmpegData();
Trace::vars('$ffmpeg->getFfmpegData()', $basic_ffmpeg_information);
$basic_ffmpeg_information = $ffmpeg->getCommands();
Trace::vars('$ffmpeg->getCommands()', $basic_ffmpeg_information);
$ffmpeg_formats = $ffmpeg->getFormats();
Trace::vars('$ffmpeg->getFormats()', $ffmpeg_formats);
$ffmpeg_audio_codecs = $ffmpeg->getCodecs('audio');
Trace::vars('$ffmpeg->getCodecs(\'audio\')', $ffmpeg_audio_codecs);
$ffmpeg_video_codecs = $ffmpeg->getCodecs('video');
Trace::vars('$ffmpeg->getCodecs(\'video\')', $ffmpeg_video_codecs);
$ffmpeg_subtitle_codecs = $ffmpeg->getCodecs('subtitle');
Trace::vars('$ffmpeg->getCodecs(\'subtitle\')', $ffmpeg_subtitle_codecs);
$ffmpeg_bitstream_filters = $ffmpeg->getBitstreamFilters();
Trace::vars('$ffmpeg->getBitstreamFilters()', $ffmpeg_bitstream_filters);
$ffmpeg_filters = $ffmpeg->getFilters();
Trace::vars('$ffmpeg->getFilters()', $ffmpeg_filters);
$ffmpeg_protocols = $ffmpeg->getProtocols();
Trace::vars('$ffmpeg->getProtocols()', $ffmpeg_protocols);
$ffmpeg_pixel_formats = $ffmpeg->getPixelFormats();
예제 #6
0
 /**
  * Splits (aka ffmpeg segment) the output into multiple files.
  *
  * @access public
  * @author Oliver Lillie
  * @return self
  */
 public function split($split_by, $time_delta = 0, $output_list_path = null)
 {
     //          check that segment is available to ffmpeg
     $ffmpeg = new FfmpegParser($this->_config);
     $formats = $ffmpeg->getFormats();
     if (isset($formats['segment']) === false) {
         throw new Exception('Unable to split media as the ffmpeg option "-segment" is not supported by your version of ffmpeg.');
     }
     //          check to see if split options are already set
     if (empty($this->_split_options) === false) {
         throw new \LogicException('Split options have already been set. You cannot call split more than once on a ' . get_class($this) . ' object.');
     }
     $this->_split_options = array();
     $duration = $this->readDuration();
     //          check the split by
     if (empty($split_by) === true) {
         throw new \InvalidArgumentException('The split by value is empty, in \\PHPVideoToolkit\\' . get_class($this) . '::split');
     } else {
         if (is_array($split_by) === true) {
             //              we check to see if we have a timecode object, if we do then we are spliting at exact points
             if (is_object($split_by[0]) === true) {
                 $times = array();
                 foreach ($split_by as $key => $timecode) {
                     if (get_class($timecode) !== 'PHPVideoToolkit\\Timecode') {
                         throw new \InvalidArgumentException('The split by timecode specified in index ' . $key . ' is not a \\PHPVideoToolkit\\Timecode object.');
                     }
                     //                      check the timecode against the total number of seconds in the media duration.
                     $seconds = $timecode->total_seconds;
                     if ($seconds > $duration->total_seconds) {
                         throw new \InvalidArgumentException('The split by timecode specified in index ' . $key . ' is greater than the duration of the media (' . $duration->total_seconds . ' seconds).');
                     }
                     array_push($times, $seconds);
                 }
                 $this->_split_options['segment_times'] = implode(',', $times);
             } else {
                 $times = array();
                 foreach ($split_by as $key => $integer) {
                     if (is_int($integer) === false) {
                         throw new \InvalidArgumentException('The split by frame number specified in index ' . $key . ' is not an integer.');
                     }
                     //                      check the frame number against the total number of frames in the media duration.
                     // TODO total frame rate comparison
                     // $seconds = ceil($timecode->total_seconds);
                     // if($seconds > $duration->total_seconds)
                     // {
                     //  throw new Exception('The split by timecode specified in index '.$key.' is greater than the duration of the media ('.$duration->total_seconds.' seconds).');
                     // }
                     //
                     array_push($times, $integer);
                 }
                 $this->_split_options['segment_frames'] = implode(',', $times);
             }
         } else {
             if ($split_by < 1) {
                 throw new \InvalidArgumentException('The split by value must be >= 1, in \\PHPVideoToolkit\\' . get_class($this) . '::split');
             }
             //              check the split time against the total number of seconds in the media duration.
             if ($split_by > $duration->total_seconds) {
                 throw new \InvalidArgumentException('The split by value is greater than the duration of the media (' . $duration->total_seconds . ' seconds).');
             }
             $this->_split_options['segment_time'] = (int) $split_by;
         }
     }
     //          check time delta
     if ($time_delta < 0) {
         throw new \InvalidArgumentException('The time delta specified "' . $time_delta . '", in \\PHPVideoToolkit\\' . get_class($this) . '::split must be >= 0');
     } else {
         if ($time_delta > 0) {
             $this->_split_options['segment_time_delta'] = (double) $time_delta;
         }
     }
     //          check the directory that contains the output list is writeable
     if (empty($output_list_path) === false) {
         $output_list = realpath($output_list_path);
         $output_list_dir = dirname($output_list);
         if (is_dir($output_list_dir) === false) {
             throw new \InvalidArgumentException('The directory for the output list file "' . $output_list_path . '" does not exist, in \\PHPVideoToolkit\\' . get_class($this) . '::split');
         } else {
             if (is_writeable($output_list_dir) === false) {
                 throw new \InvalidArgumentException('The directory for the output list file "' . $output_list_path . '" is not writeable, in \\PHPVideoToolkit\\' . get_class($this) . '::split');
             }
         }
         $this->_split_options['segment_list'] = $output_list_path;
     }
     //          mark that we require a %d (or in phpvideotoolkits case %index or %timecode) in the file name output as multiple files will be outputed.
     $this->_require_d_in_output = true;
     return $this;
 }
예제 #7
0
 /**
  * Constructor
  *
  * @access public
  * @author: Oliver Lillie
  * @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.
  * @param  PHPVideoToolkit\Config $config The config object.
  * @throws \InvalidArgumentException If the $input_output_type is not valid.
  */
 public function __construct($input_output_type = Format::OUTPUT, Config $config = null)
 {
     parent::__construct($config);
     $this->setType($input_output_type);
     $this->_additional_commands = array();
     $this->_removed_commands = array();
     $this->_media_object = null;
     $this->_format = array('quality' => null, 'format' => null, 'strictness' => null, 'preset_options_file' => null, 'threads' => null, 'threads_indexed' => null);
     $ffmpeg = new FfmpegParser();
     $available_commands = $ffmpeg->getCommands();
     if (isset($available_commands['crf'])) {
         $quality_command = '-crf <setting>';
     } else {
         if (isset($available_commands['q']) === true) {
             $quality_command = '-q <setting>';
         } else {
             $quality_command = '-qscale <setting>';
         }
     }
     $this->_format_to_command = array('quality' => $quality_command, 'format' => '-f <setting>', 'strictness' => '-strict <setting>', 'preset_options_file' => '-fpre <setting>', 'threads' => '-threads <setting>', 'threads_indexed' => '-threads:<index> <setting>');
     //          add default input/output commands
     if ($input_output_type === self::OUTPUT) {
         if ($this->_config->set_default_output_format === true) {
             $this->setThreads(1)->setStrictness('experimental')->setQualityVsStreamabilityBalanceRatio(4);
         }
     } else {
         if ($input_output_type === self::INPUT) {
         } else {
             throw new \InvalidArgumentException('Unrecognised input/output type "' . $input_output_type . '" set in \\PHPVideoToolkit\\Format::__construct');
         }
     }
 }