Esempio n. 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;
 }
    /**
     * 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;
    }
 /**
  * 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;
 }