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(); Trace::vars('$ffmpeg->getPixelFormats()', $ffmpeg_pixel_formats);
/** * 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; }