| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-13 14:34:53 +02:00
										 |  |  | /* | 
					
						
							|  |  |  |  * This file is part of PHP-FFmpeg. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * (c) Alchemy <info@alchemy.fr> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * For the full copyright and license information, please view the LICENSE | 
					
						
							|  |  |  |  * file that was distributed with this source code. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  | namespace FFMpeg; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-13 15:12:43 +02:00
										 |  |  | use \Symfony\Component\Process\Process; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * FFProbe driver | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @author Romain Neutron imprec@gmail.com | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  | class FFProbe extends Binary | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-13 15:12:43 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Probe the format of a given file | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param string $pathfile | 
					
						
							|  |  |  |      * @return string | 
					
						
							|  |  |  |      * @throws Exception\InvalidFileArgumentException | 
					
						
							| 
									
										
										
										
											2012-04-13 15:21:52 +02:00
										 |  |  |      * @throws Exception\RuntimeException | 
					
						
							| 
									
										
										
										
											2012-04-13 15:12:43 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |     public function probeFormat($pathfile) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2012-05-11 00:30:02 +02:00
										 |  |  |         if ( ! is_file($pathfile)) { | 
					
						
							| 
									
										
										
										
											2012-04-13 15:12:43 +02:00
										 |  |  |             throw new Exception\InvalidFileArgumentException($pathfile); | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $cmd = $this->binary . ' ' . $pathfile . ' -show_format'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this->executeProbe($cmd); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-13 15:12:43 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Probe the streams contained in a given file | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param string $pathfile | 
					
						
							|  |  |  |      * @return string | 
					
						
							|  |  |  |      * @throws Exception\InvalidFileArgumentException | 
					
						
							| 
									
										
										
										
											2012-04-13 15:21:52 +02:00
										 |  |  |      * @throws Exception\RuntimeException | 
					
						
							| 
									
										
										
										
											2012-04-13 15:12:43 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |     public function probeStreams($pathfile) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2012-05-11 00:30:02 +02:00
										 |  |  |         if ( ! is_file($pathfile)) { | 
					
						
							| 
									
										
										
										
											2012-04-13 15:12:43 +02:00
										 |  |  |             throw new Exception\InvalidFileArgumentException($pathfile); | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $cmd = $this->binary . ' ' . $pathfile . ' -show_streams'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-13 15:21:52 +02:00
										 |  |  |         return $this->executeProbe($cmd); | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-13 15:12:43 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param string $command | 
					
						
							|  |  |  |      * @return string | 
					
						
							|  |  |  |      * @throws Exception\RuntimeException | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |     protected function executeProbe($command) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2012-05-11 00:30:02 +02:00
										 |  |  |         try { | 
					
						
							| 
									
										
										
										
											2012-04-13 15:12:43 +02:00
										 |  |  |             $process = new Process($command); | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-13 15:12:43 +02:00
										 |  |  |             $process->run(); | 
					
						
							| 
									
										
										
										
											2012-05-11 00:30:02 +02:00
										 |  |  |         } catch (\RuntimeException $e) { | 
					
						
							| 
									
										
										
										
											2012-04-13 15:12:43 +02:00
										 |  |  |             throw new Exception\RuntimeException(sprintf('Failed to run the given command %s', $command)); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-11 00:30:02 +02:00
										 |  |  |         if ( ! $process->isSuccessful()) { | 
					
						
							| 
									
										
										
										
											2012-04-13 15:12:43 +02:00
										 |  |  |             throw new Exception\RuntimeException(sprintf('Failed to probe %s', $command)); | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $process->getOutput(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-13 15:12:43 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Return the binary name | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |     protected static function getBinaryName() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2012-05-11 00:30:02 +02:00
										 |  |  |         return array('avprobe', 'ffprobe'); | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } |