/** * Returns information about the specified file without having to use ffmpeg-php * as it consults the ffmpeg binary directly. * * @access public * @param string $tmp_directory A full absolute path to you temporary directory. Only needed in a static call. * @return mixed false on error encountered, true otherwise **/ public function getFFmpegInfo($tmp_directory = '/tmp/') { // check to see if the info has already been cached if (PHPVideoToolkit::$ffmpeg_info !== false) { return PHPVideoToolkit::$ffmpeg_info; } // check to see if this is a static call if (PHPVideoToolkit::$_static === true) { $toolkit = new PHPVideoToolkit($tmp_directory); return $toolkit->getFFmpegInfo(); } $format = ''; // $info_file = $this->_tmp_directory.$this->unique('ffinfo').'.info'; // execute the ffmpeg lookup // exec(PHPVIDEOTOOLKIT_FFMPEG_BINARY.' -formats &> '.$info_file); exec(PHPVIDEOTOOLKIT_FFMPEG_BINARY . ' -formats 2>&1', $buffer); $buffer = implode("\r\n", $buffer); // die($buffer); // $data = false; // try to open the file // $handle = fopen($info_file, 'r'); // if($handle) // { $data = array(); // $buffer = ''; // loop through the lines of data and collect the buffer // while (!feof($handle)) // { // $buffer .= fgets($handle, 4096); // } // echo($buffer); $data['compiler'] = array(); $look_ups = array('configuration' => 'configuration: ', 'formats' => 'File formats:', 'codecs' => 'Codecs:', 'filters' => 'Bitstream filters:', 'protocols' => 'Supported file protocols:', 'abbreviations' => 'Frame size, frame rate abbreviations:', 'Note:'); $total_lookups = count($look_ups); $pregs = array(); $indexs = array(); foreach ($look_ups as $key => $reg) { if (strpos($buffer, $reg) !== false) { $index = array_push($pregs, $reg); $indexs[$key] = $index; } } preg_match('/' . implode('(.*)', $pregs) . '/s', $buffer, $matches); $configuration = trim($matches[$indexs['configuration']]); // grab the ffmpeg configuration flags preg_match_all('/--[a-zA-Z0-9\\-]+/', $configuration, $config_flags); $data['compiler']['configuration'] = $config_flags[0]; $data['compiler']['vhook-support'] = in_array('--enable-vhook', $config_flags[0]) && !in_array('--disable-vhook', $config_flags[0]); // grab the versions $data['compiler']['versions'] = array(); preg_match_all('/([a-zA-Z0-9\\-]+) version: ([0-9\\.]+)/', $configuration, $versions); for ($i = 0, $a = count($versions[0]); $i < $a; $i++) { $data['compiler']['versions'][strtolower(trim($versions[1][$i]))] = $versions[2][$i]; } // grab the ffmpeg compile info preg_match('/built on (.*), gcc: (.*)/', $configuration, $conf); if (count($conf) > 0) { $data['compiler']['gcc'] = $conf[2]; $data['compiler']['build_date'] = $conf[1]; $data['compiler']['build_date_timestamp'] = strtotime($conf[1]); } // grab the file formats available to ffmpeg preg_match_all('/ (DE|D|E) (.*) {1,} (.*)/', trim($matches[$indexs['formats']]), $formats); $data['formats'] = array(); // loop and clean for ($i = 0, $a = count($formats[0]); $i < $a; $i++) { $data['formats'][strtolower(trim($formats[2][$i]))] = array('encode' => $formats[1][$i] == 'DE' || $formats[1][$i] == 'E', 'decode' => $formats[1][$i] == 'DE' || $formats[1][$i] == 'D', 'fullname' => $formats[3][$i]); } // grab the bitstream filters available to ffmpeg $data['filters'] = array(); if (isset($indexs['filters']) && isset($matches[$indexs['filters']])) { $filters = trim($matches[$indexs['filters']]); if (empty($filters)) { $data['filters'] = explode(' ', $filters); } } // grab the file prototcols available to ffmpeg $data['filters'] = array(); if (isset($indexs['protocols']) && isset($matches[$indexs['protocols']])) { $protocols = trim($matches[$indexs['protocols']]); if (empty($protocols)) { $data['protocols'] = explode(' ', str_replace(':', '', $protocols)); } } // grab the abbreviations available to ffmpeg $data['abbreviations'] = array(); if (isset($indexs['abbreviations']) && isset($matches[$indexs['abbreviations']])) { $abbreviations = trim($matches[$indexs['abbreviations']]); if (empty($abbreviations)) { $data['abbreviations'] = explode(' ', $abbreviations); } } PHPVideoToolkit::$ffmpeg_info = $data; // } // fclose($handle); // if(is_file($info_file)) // { // if the info file exists remove it // unlink($info_file); // } $data['ffmpeg-php-support'] = $this->hasFFmpegPHPSupport(); return $data; }
/** * Returns information about the specified file without having to use ffmpeg-php * as it consults the ffmpeg binary directly. * * @access public * @param string $file The absolute path of the file that is required to be manipulated. * @return mixed false on error encountered, true otherwise **/ function getFFmpegInfo() { // check to see if this is a static call if(!$this) { $toolkit = new PHPVideoToolkit($tmp_directory); return $toolkit->getFFmpegInfo(); } // check to see if the info has already been cached if($this->ffmpeg_info !== false) { return $this->ffmpeg_info; } // check to see if this is a static call $format = ''; $data = array(); // execute the ffmpeg lookup exec(PHPVIDEOTOOLKIT_FFMPEG_BINARY.' -formats 2>&1', $buffer); $this->ffmpeg_found = $data['ffmpeg-found'] = !(strpos($buffer[0], 'command not found') !== false || strpos($buffer[0], 'No such file or directory') !== false); $data['binary'] = array(); $data['compiler'] = array(); $data['ffmpeg-php-support'] = $this->hasFFmpegPHPSupport(); $data['raw'] = implode("\r\n", $buffer); if(!$this->ffmpeg_found) { $this->ffmpeg_info = $data; return $data; } $buffer = $data['raw']; // start building the info array $look_ups = array('configuration'=>'configuration: ', 'formats'=>'File formats:', 'codecs'=>'Codecs:', 'filters'=>'Bitstream filters:', 'protocols'=>'Supported file protocols:', 'abbreviations'=>'Frame size, frame rate abbreviations:', 'Note:'); $total_lookups = count($look_ups); $pregs = array(); $indexs = array(); foreach($look_ups as $key=>$reg) { if(strpos($buffer, $reg) !== false) { $index = array_push($pregs, $reg); $indexs[$key] = $index; } } preg_match('/'.implode('(.*)', $pregs).'(.*)/s', $buffer, $matches); $configuration = trim($matches[$indexs['configuration']]); // grab the ffmpeg configuration flags preg_match_all('/--[a-zA-Z0-9\-]+/', $configuration, $config_flags); $data['binary']['configuration'] = $config_flags[0]; $data['binary']['vhook-support'] = in_array('--enable-vhook', $config_flags[0]) || !in_array('--disable-vhook', $config_flags[0]); // grab the versions $data['binary']['versions'] = array(); preg_match_all('/([a-zA-Z0-9\-]+) version: ([0-9\.]+)/', $configuration, $versions); for($i=0, $a=count($versions[0]); $i<$a; $i++) { $data['binary']['versions'][strtolower(trim($versions[1][$i]))] = $versions[2][$i]; } // grab the ffmpeg compile info preg_match('/built on (.*), gcc: (.*)/', $configuration, $conf); if(count($conf) > 0) { $data['compiler']['gcc'] = $conf[2]; $data['compiler']['build_date'] = $conf[1]; $data['compiler']['build_date_timestamp'] = strtotime($conf[1]); } // grab the file formats available to ffmpeg preg_match_all('/ (DE|D|E) (.*) {1,} (.*)/', trim($matches[$indexs['formats']]), $formats); $data['formats'] = array(); // loop and clean for($i=0, $a=count($formats[0]); $i<$a; $i++) { $data['formats'][strtolower(trim($formats[2][$i]))] = array( 'encode' => $formats[1][$i] == 'DE' || $formats[1][$i] == 'E', 'decode' => $formats[1][$i] == 'DE' || $formats[1][$i] == 'D', 'fullname' => $formats[3][$i] ); } // grab the bitstream filters available to ffmpeg $data['filters'] = array(); if(isset($indexs['filters']) && isset($matches[$indexs['filters']])) { $filters = trim($matches[$indexs['filters']]); if(empty($filters) === false) { $data['filters'] = explode(' ', $filters); } } // grab the file prototcols available to ffmpeg $data['filters'] = array(); if(isset($indexs['protocols']) && isset($matches[$indexs['protocols']])) { $protocols = trim($matches[$indexs['protocols']]); if(empty($protocols) === false) { $data['protocols'] = explode(' ', str_replace(':', '', $protocols)); } } // grab the abbreviations available to ffmpeg $data['abbreviations'] = array(); if(isset($indexs['abbreviations']) && isset($matches[$indexs['abbreviations']])) { $abbreviations = trim($matches[$indexs['abbreviations']]); if(empty($abbreviations) === false) { $data['abbreviations'] = explode(' ', $abbreviations); } } $this->ffmpeg_info = $data; return $data; }
/** * Returns the available codecs. * @access public * @param mixed $type The type of codec list to return, FALSE (to return all codecs), or either 'audio', 'video', or 'subtitle'. * @return array An array of codecs available to ffmpeg. */ public static function getAvailableCodecs($type = FALSE) { // check to see if this is a static call if (isset($this) === FALSE) { $toolkit = new PHPVideoToolkit(); $info = $toolkit->getFFmpegInfo(true); } else { $info = $this->getFFmpegInfo(true); } // are we checking for particluar method? $return_vals = array(); if ($type === FALSE) { $video_keys = array_keys($info['codecs']['video']); $audio_keys = array_keys($info['codecs']['audio']); $subtitle_keys = array_keys($info['codecs']['subtitle']); return array_merge($video_keys, $audio_keys, $subtitle_keys); } return isset($info['codecs'][$type]) === TRUE ? array_keys($info['codecs'][$type]) : FALSE; }
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ echo '<html><head></head><body>'; echo '<a style="font-size:12px;" href="index.php#examples">← Back to examples list</a><br /><br />'; echo '<strong>This example shows you how to access the information about your ffmpeg installation.</strong><br /><br />'; $ignore_demo_files = true; // load the examples configuration require_once 'example-config.php'; // require the library require_once '../phpvideotoolkit.' . $use_version . '.php'; // temp directory $tmp_dir = PHPVIDEOTOOLKIT_EXAMPLE_ABSOLUTE_BATH . 'tmp/'; // start ffmpeg class $toolkit = new PHPVideoToolkit($tmp_dir); // get the ffmpeg info $info = $toolkit->getFFmpegInfo(); // determine the type of support for ffmpeg-php echo '<strong>FFmpeg-PHP Support</strong><br />'; // determine if ffmpeg-php is supported $has_ffmpeg_php_support = $toolkit->hasFFmpegPHPSupport(); // you can also determine if it has ffmpeg php support with below // $has_ffmpeg_php_support = $info['ffmpeg-php-support']; switch ($has_ffmpeg_php_support) { case 'module': echo 'Congratulations you have the FFmpeg-PHP module installed.'; break; case 'emulated': echo 'You haven\'t got the FFmpeg-PHP module installed, however you can use the PHPVideoToolkit\'s adapter\'s to emulate FFmpeg-PHP.<br /><strong>Note:</strong> It is recommended that if you heavily use FFmpeg-PHP that you install the module.'; break; case false: echo 'You have no support at all for FFmpeg-PHP.';