Пример #1
0
 /**
  * Returns the raw data returned from ffmpeg about the available supported formats.
  *
  * @access public
  * @author Oliver Lillie
  * @param boolean $read_from_cache 
  * @return string
  */
 public function getRawFormatData($read_from_cache = true)
 {
     $cache_key = 'ffmpeg_raw_formats_data';
     if ($read_from_cache === true && ($data = $this->_cacheGet($cache_key, -1)) !== -1) {
         return $data;
     }
     $exec = new FfmpegProcess('ffmpeg', $this->_config);
     $data = $exec->addCommand('-formats')->execute()->getBuffer();
     //			check the process for any errors.
     if ($exec->hasError() === true) {
         throw new FfmpegProcessException('An error was encountered with FFmpeg when attempting to read the formats that FFmpeg supports. FFmpeg reported: ' . $exec->getLastLine(), null, $exec);
     }
     $this->_cacheSet($cache_key, $data);
     return $data;
 }
 /**
  * Constructor
  *
  * @access public
  * @author: Oliver Lillie
  * @param string $program The programme to call. Note this is not the path. If you wish to call ffmpeg/aconv you should jsut
  *  supply 'ffmpeg' and then set the aconv path as the ffmpeg configuration option in Config.   
  * @param PHPVideoToolkit\Config $config The config object.
  */
 public function __construct($programme, Config $config = null)
 {
     parent::__construct($programme, $config);
     $this->_progress_callbacks = array();
     $this->_output_renamed = null;
     $this->_final_output = null;
 }
Пример #3
0
    /**
     * Returns the raw data provided by ffmpeg about a file.
     *
     * @access public
     * @author Oliver Lillie
     * @param string $file_path 
     * @param boolean $read_from_cache 
     * @return mixed Returns false if no data is returned, otherwise returns the raw data as a string.
     */
    public function getFileRawInformation($file_path, $read_from_cache = true)
    {
        //          convert to realpath
        $real_file_path = $this->_checkMediaFilePath($file_path);
        $cache_key = 'media_parser/' . md5($real_file_path) . '_raw_data';
        if ($read_from_cache === true && ($data = $this->_cacheGet($cache_key, -1)) !== -1) {
            return $data;
        }
        $isWindowsPlatform = defined('PHP_WINDOWS_VERSION_BUILD');
        //          execute the ffmpeg lookup
        $exec = new FfmpegProcess('ffmpeg', $this->_config);
        $exec_cmd = $exec->setInputPath($real_file_path)->addCommand('-af', 'volumedetect')->addCommand('-f', 'NULL');
        if ($isWindowsPlatform) {
            $exec_cmd = $exec_cmd->addCommand('NUL');
        } else {
            $exec_cmd = $exec_cmd->addCommand('/dev/null');
        }
        $raw_data = $exec_cmd->execute()->getBuffer();
        //          check the process for any errors.
        if ($exec->hasError() === true && ($last_line = $exec->getLastLine()) !== 'At least one output file must be specified') {
            throw new FfmpegProcessException('FFmpeg encountered an error when attempting to read `' . $file_path . '`. FFmpeg reported: 
' . $raw_data, null, $exec);
        }
        //          check that some data has been obtained
        if (empty($raw_data) === true) {
            // TODO possible error/exception here.
        }
        $this->_cacheSet($cache_key, $raw_data);
        return $raw_data;
    }
    /**
     * Returns the version of ffmpeg if it is found and available.
     *
     * @access public
     * @author Jorrit Schippers
     * @param boolean $read_from_cache If true and the data exists within a cache then that data is used. If false
     *  then the data is re-read from ffmpeg.
     * @return array Returns an array with the following keys; build, version. Note, depending on your version of ffmpeg
     *  either one or both of these keys will container values.
     * @throws PHPVideoToolkit\FfmpegProcessException If a version is not found in the basic information then we call ffmpeg -version
     *  to get the version information. If that call encounters an error this exception is thrown.
     */
    public function getVersion($read_from_cache = true)
    {
        $cache_key = 'ffmpeg_parser/ffmpeg_version';
        if ($read_from_cache === true && ($data = $this->_cacheGet($cache_key))) {
            return $data;
        }
        $version = null;
        $build = null;
        $raw_data = $this->getRawFfmpegData($read_from_cache);
        //          Search for SVN string
        //          FFmpeg version SVN-r20438, Copyright (c) 2000-2009 Fabrice Bellard, et al.
        if ($build === null && preg_match('/(?:ffmpeg|avconv) version SVN-r([0-9.]*)/i', $raw_data, $matches) > 0) {
            $build = $matches[1];
        }
        // //           Some OSX versions are built from a very early CVS
        // //           I do not know what to do with this version- using 1 for now
        //          if(preg_match('/(?:ffmpeg|avconv) version(.*)CVS.*Mac OSX universal/msUi', $raw_data, $matches) > 0)
        //          {
        //              $build = $matches[1];
        //          }
        //          Search for git string
        //          FFmpeg version git-N-29240-gefb5fa7, Copyright (c) 2000-2011 the FFmpeg developers.
        //          ffmpeg version N-31145-g59bd0fe, Copyright (c) 2000-2011 the FFmpeg developers
        if ($build === null && preg_match('/(?:ffmpeg|avconv) version.*N-([0-9.]*)/i', $raw_data, $matches) > 0) {
            //              Versions above this seem to be ok
            if ($matches[1] >= 29240) {
                $build = $matches[1];
            }
        }
        //          Do we have a release?
        //          ffmpeg version 0.4.9-pre1, build 4736, Copyright (c) 2000-2004 Fabrice Bellard
        if ($build === null && preg_match('/(?:ffmpeg|avconv) version ([^,]+) build ([0-9]+),/i', $raw_data, $matches) > 0) {
            $version = $matches[1];
            $build = $matches[2];
        }
        //          Do we have a build version?
        //          ffmpeg version 0.4.9-pre1, build 4736, Copyright (c) 2000-2004 Fabrice Bellard
        if ($build === null && preg_match('/(?:ffmpeg|avconv) version.*, build ([0-9]*)/i', $raw_data, $matches) > 0) {
            $build = $matches[1];
        }
        //          ffmpeg version 1.1.2 Copyright (c) 2000-2013 the FFmpeg developers
        if ($version === null && preg_match('/ffmpeg version ([^\\s]+) Copyright/i', $raw_data, $matches) > 0) {
            $version = $matches[1];
        }
        //          avconv version 0.8.9-4:0.8.9-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav developers built on Nov 9 2013 19:08:00 with gcc 4.6.3
        if ($version === null && preg_match('/avconv version\\s+([^:]+):/msUi', $raw_data, $matches) > 0) {
            $version = $matches[1];
        }
        //          get the version from -version
        if ($version === null) {
            $exec = new FfmpegProcess('ffmpeg', $this->_config);
            $data = $exec->addCommand('-version')->execute()->getBuffer();
            //              check the process for any errors.
            if ($exec->hasError() === true) {
                throw new FfmpegProcessException('An error was encountered when attempting to read FFmpegs\' version. FFmpeg reported: ' . $exec->getLastLine(), null, $exec);
            }
            if (preg_match('/FFmpeg version ([0-9\\.]+)/i', $data, $matches) > 0) {
                $version = $matches[1];
            } else {
                if (preg_match('/FFmpeg ([0-9]+\\.[0-9]+\\.[0-9]+)/i', $data, $matches) > 0) {
                    $version = $matches[1];
                }
            }
        }
        //          if both version and build are not available throw a new exception to get the user to provide their ffmpeg data to github so we can start building up different formats of ffmpeg output.
        if ($version === null && $build === null) {
            throw new FfmpegProcessException('Unable to determine your FFmpeg version or build. Please create an issue at the github repository for PHPVideoToolkit 2; https://github.com/buggedcom/phpvideotoolkit-v2/issues. Please add the following data to the ticket:<br />
<br />              
<code>' . $this->getRawFfmpegData($read_from_cache) . '</code>');
        }
        $data = array('build' => $build, 'version' => $version, 'from-cache' => true, 'read-at' => time());
        $this->_cacheSet($cache_key, $data);
        $data['from-cache'] = false;
        return $data;
    }
Пример #5
0
 /**
  * The callback intentionally public, but should be regarded as protected that is used
  * to post process the output of a save command.
  *
  * @access protected
  * @author Oliver Lillie
  * @return mixed
  */
 public function _postProcessOutput(FfmpegProcess $process)
 {
     $output = $process->completeProcess();
     if (empty($this->_post_process_callbacks) === false) {
         foreach ($this->_post_process_callbacks as $callback) {
             $args = $callback[1];
             array_unshift($args, $output, $this);
             $output = call_user_func_array($callback[0], $args);
         }
     }
     return $output;
 }
Пример #6
0
 /**
  * Returns the raw data provided by ffmpeg about a file.
  *
  * @access public
  * @author Oliver Lillie
  * @param string $file_path 
  * @param boolean $read_from_cache 
  * @return mixed Returns false if no data is returned, otherwise returns the raw data as a string.
  */
 public function getFileRawInformation($file_path, $read_from_cache = true)
 {
     //			convert to realpath
     $real_file_path = $this->_checkMediaFilePath($file_path);
     $cache_key = 'media_parser/' . md5($real_file_path) . '_raw_data';
     if ($read_from_cache === true && ($data = $this->_cacheGet($cache_key, -1)) !== -1) {
         return $data;
     }
     // 			execute the ffmpeg lookup
     $exec = new FfmpegProcess('ffmpeg', $this->_config);
     $raw_data = $exec->setInputPath($real_file_path)->execute()->getBuffer();
     //			check the process for any errors.
     if ($exec->hasError() === true && ($last_line = $exec->getLastLine()) !== 'At least one output file must be specified') {
         throw new FfmpegProcessException('FFmpeg encountered an error when attempting to read `' . $file_path . '`. FFmpeg reported: ' . $last_line, null, $exec);
     }
     // 			check that some data has been obtained
     if (empty($raw_data) === true) {
         // TODO possible error/exception here.
     }
     $this->_cacheSet($cache_key, $raw_data);
     return $raw_data;
 }
 /**
  * Returns the raw data returned from ffmpeg about the available supported protocols.
  *
  * @access public
  * @author Oliver Lillie
  * @param boolean $read_from_cache If true and the data exists within a cache then that data is used. If false
  *  then the data is re-read from ffmpeg.
  * @return string Returns the raw buffer data from ffmpeg.
  * @throws PHPVideoToolkit\FfmpegProcessException If the call to ffmpeg encounters an error.
  */
 public function getRawProtocolsData($read_from_cache = true)
 {
     $cache_key = 'ffmpeg_parser_generic/raw_protocols_data';
     if ($read_from_cache === true && ($data = $this->_cacheGet($cache_key))) {
         return $data;
     }
     $exec = new FfmpegProcess('ffmpeg', $this->_config);
     $data = $exec->addCommand('-protocols')->execute()->getBuffer();
     //          check the process for any errors.
     if ($exec->hasError() === true) {
         throw new FfmpegProcessException('An error was encountered when attempting to read FFmpegs\' available protocols. FFmpeg reported: ' . $exec->getLastLine(), null, $exec);
     }
     $this->_cacheSet($cache_key, $data);
     return $data;
 }
Пример #8
0
 /**
  * Returns the raw data provided by ffmpeg about a file.
  *
  * @access public
  * @author Oliver Lillie
  * @param string $file_path 
  * @param boolean $read_from_cache 
  * @return mixed Returns false if no data is returned, otherwise returns the raw data as a string.
  */
 public function getFileRawInformation($file_path, $read_from_cache = true)
 {
     //			convert to realpath
     $real_file_path = $this->_checkMediaFilePath($file_path);
     $cache_key = 'media_prober/' . md5($real_file_path) . '_raw_data';
     if ($read_from_cache === true && ($data = $this->_cacheGet($cache_key, -1)) !== -1) {
         return $data;
     }
     // 			execute the ffmpeg lookup
     $exec = new FfmpegProcess('ffprobe', $this->_config);
     $raw_data = $exec->setInputPath($real_file_path)->addCommand('-show_streams')->addCommand('-show_format')->execute()->getBuffer();
     //			check the process for any errors.
     if ($exec->hasError() === true) {
         throw new FfmpegProcessException('FFprobe encountered an error when attempting to read `' . $file_path . '`. FFprobe reported: ' . $exec->getLastLine(), null, $exec);
     }
     // 			check that some data has been obtained
     $data = array();
     if (empty($raw_data) === true) {
         // TODO possible error/exception here.
     }
     $this->_cacheSet($cache_key, $data);
     return $data;
 }
 public function __construct($binary_path, $temp_directory)
 {
     parent::__construct($binary_path, $temp_directory);
     $this->_progress_callbacks = array();
 }