FFProbe now returns Json
This commit is contained in:
		
					parent
					
						
							
								2142bf8241
							
						
					
				
			
			
				commit
				
					
						fa39cb09eb
					
				
			
		
					 2 changed files with 55 additions and 11 deletions
				
			
		|  | @ -234,17 +234,17 @@ class FFMpeg extends Binary | ||||||
|                 throw new LogicException('You must set a valid prober if you use RESIZEMODE_INSET'); |                 throw new LogicException('You must set a valid prober if you use RESIZEMODE_INSET'); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             $result = $this->prober->probeStreams($this->pathfile); |             $result = json_decode($this->prober->probeStreams($this->pathfile), true); | ||||||
| 
 | 
 | ||||||
|             $originalWidth = $originalHeight = null; |             $originalWidth = $originalHeight = null; | ||||||
| 
 | 
 | ||||||
|             foreach ($result as $stream) { |             foreach ($result as $stream) { | ||||||
|                 foreach ($stream as $info) { |                 foreach ($stream as $name => $value) { | ||||||
|                     if (strpos($info, 'width=') === 0) { |                     if ($name == 'width') { | ||||||
|                         $originalWidth = substr($info, 6); |                         $originalWidth = substr($info, 6); | ||||||
|                         continue; |                         continue; | ||||||
|                     } |                     } | ||||||
|                     if (strpos($info, 'height=') === 0) { |                     if ($name == 'value') { | ||||||
|                         $originalHeight = substr($info, 7); |                         $originalHeight = substr($info, 7); | ||||||
|                         continue; |                         continue; | ||||||
|                     } |                     } | ||||||
|  |  | ||||||
|  | @ -27,7 +27,8 @@ class FFProbe extends Binary | ||||||
|      * Probe the format of a given file |      * Probe the format of a given file | ||||||
|      * |      * | ||||||
|      * @param  string                   $pathfile |      * @param  string                   $pathfile | ||||||
|      * @return string |      * @return string    A Json object containing the key/values of the probe output | ||||||
|  |      *  | ||||||
|      * @throws InvalidArgumentException |      * @throws InvalidArgumentException | ||||||
|      * @throws RuntimeException |      * @throws RuntimeException | ||||||
|      */ |      */ | ||||||
|  | @ -39,14 +40,41 @@ class FFProbe extends Binary | ||||||
| 
 | 
 | ||||||
|         $cmd = $this->binary . ' ' . $pathfile . ' -show_format'; |         $cmd = $this->binary . ' ' . $pathfile . ' -show_format'; | ||||||
| 
 | 
 | ||||||
|         return $this->executeProbe($cmd); |         $output = $this->executeProbe($cmd); | ||||||
|  | 
 | ||||||
|  |         $ret = array(); | ||||||
|  | 
 | ||||||
|  |         foreach (explode("\n", $output) as $line) { | ||||||
|  | 
 | ||||||
|  |             if (in_array($line, array('[FORMAT]', '[/FORMAT]'))) { | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             $chunks = explode('=', $line); | ||||||
|  |             $key = array_shift($chunks); | ||||||
|  | 
 | ||||||
|  |             if ('' === trim($key)) { | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             $value = trim(implode('=', $chunks)); | ||||||
|  | 
 | ||||||
|  |             if (ctype_digit($value)) { | ||||||
|  |                 $value = (int) $value; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             $ret[$key] = $value; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return json_encode($ret); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Probe the streams contained in a given file |      * Probe the streams contained in a given file | ||||||
|      * |      * | ||||||
|      * @param  string                   $pathfile |      * @param  string                   $pathfile | ||||||
|      * @return string |      * @return array    An array of streams array | ||||||
|  |      *  | ||||||
|      * @throws InvalidArgumentException |      * @throws InvalidArgumentException | ||||||
|      * @throws RuntimeException |      * @throws RuntimeException | ||||||
|      */ |      */ | ||||||
|  | @ -65,16 +93,32 @@ class FFProbe extends Binary | ||||||
| 
 | 
 | ||||||
|         foreach ($output as $line) { |         foreach ($output as $line) { | ||||||
| 
 | 
 | ||||||
|             if (in_array($line, array('[STREAM]', '[/STREAM]'))) { |             if ($line == '[STREAM]') { | ||||||
|                 $n ++; |                 $n ++; | ||||||
|                 $ret[$n] = array(); |                 $ret[$n] = array(); | ||||||
|                 continue; |                 continue; | ||||||
|             } |             } | ||||||
| 
 |             if ($line == '[/STREAM]') { | ||||||
|             $ret[$n][] = $line; |                 continue; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|         return $ret; |             $chunks = explode('=', $line); | ||||||
|  |             $key = array_shift($chunks); | ||||||
|  | 
 | ||||||
|  |             if ('' === trim($key)) { | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             $value = trim(implode('=', $chunks)); | ||||||
|  | 
 | ||||||
|  |             if (ctype_digit($value)) { | ||||||
|  |                 $value = (int) $value; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             $ret[$n][$key] = $value; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return json_encode(array_values($ret)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue