Change the resize, it now depends of the format
This commit is contained in:
		
					parent
					
						
							
								b1e6eeaf95
							
						
					
				
			
			
				commit
				
					
						68852ca65a
					
				
			
		
					 2 changed files with 33 additions and 54 deletions
				
			
		|  | @ -29,7 +29,7 @@ class FFMpeg extends Binary | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * |      * | ||||||
|      * @var FFProbe  |      * @var FFProbe | ||||||
|      */ |      */ | ||||||
|     protected $prober; |     protected $prober; | ||||||
| 
 | 
 | ||||||
|  | @ -38,7 +38,7 @@ class FFMpeg extends Binary | ||||||
|         $this->prober = null; |         $this->prober = null; | ||||||
|         parent::__destruct(); |         parent::__destruct(); | ||||||
|     } |     } | ||||||
|      | 
 | ||||||
|     /** |     /** | ||||||
|      * Opens a file in order to be processed |      * Opens a file in order to be processed | ||||||
|      * |      * | ||||||
|  | @ -63,13 +63,13 @@ class FFMpeg extends Binary | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Set a prober |      * Set a prober | ||||||
|      *  |      * | ||||||
|      * @return \FFMpeg\FFMpeg |      * @return \FFMpeg\FFMpeg | ||||||
|      */ |      */ | ||||||
|     public function setProber(FFProbe $prober) |     public function setProber(FFProbe $prober) | ||||||
|     { |     { | ||||||
|         $this->prober = $prober; |         $this->prober = $prober; | ||||||
|          | 
 | ||||||
|         return $this; |         return $this; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -113,7 +113,7 @@ class FFMpeg extends Binary | ||||||
|         try { |         try { | ||||||
|             $process->run(); |             $process->run(); | ||||||
|         } catch (\RuntimeException $e) { |         } catch (\RuntimeException $e) { | ||||||
|              | 
 | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if ( ! $process->isSuccessful()) { |         if ( ! $process->isSuccessful()) { | ||||||
|  | @ -188,7 +188,7 @@ class FFMpeg extends Binary | ||||||
|         try { |         try { | ||||||
|             $process->run(); |             $process->run(); | ||||||
|         } catch (\RuntimeException $e) { |         } catch (\RuntimeException $e) { | ||||||
|              | 
 | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if ( ! $process->isSuccessful()) { |         if ( ! $process->isSuccessful()) { | ||||||
|  | @ -219,55 +219,34 @@ class FFMpeg extends Binary | ||||||
| 
 | 
 | ||||||
|         $cmd_part2 = ''; |         $cmd_part2 = ''; | ||||||
| 
 | 
 | ||||||
|         if ($format->getWidth() && $format->getHeight()) { |         if ($format instanceof Format\ResizableVideo) { | ||||||
| 
 |             if ( ! $this->prober) { | ||||||
|             switch ($format->getResizeMode()) { |                 throw new LogicException('You must set a valid prober if you use RESIZEMODE_INSET'); | ||||||
|                 case Video::RESIZEMODE_FIT: |  | ||||||
|                 default: |  | ||||||
|                     $width = $this->getMultiple($format->getWidth(), 16); |  | ||||||
|                     $height = $this->getMultiple($format->getHeight(), 16); |  | ||||||
|                     break; |  | ||||||
|                 case Video::RESIZEMODE_INSET: |  | ||||||
| 
 |  | ||||||
|                     if ( ! $this->prober) { |  | ||||||
|                         throw new LogicException('You must set a valid prober if you use RESIZEMODE_INSET'); |  | ||||||
|                     } |  | ||||||
| 
 |  | ||||||
|                     $result = $this->prober->probeStreams($this->pathfile); |  | ||||||
| 
 |  | ||||||
|                     $originalWidth = $format->getWidth(); |  | ||||||
|                     $originalHeight = $format->getHeight(); |  | ||||||
| 
 |  | ||||||
|                     foreach ($result as $stream) { |  | ||||||
|                         foreach ($stream as $info) { |  | ||||||
|                             if (strpos($info, 'width=') === 0) { |  | ||||||
|                                 $originalWidth = substr($info, 6); |  | ||||||
|                                 continue; |  | ||||||
|                             } |  | ||||||
|                             if (strpos($info, 'height=') === 0) { |  | ||||||
|                                 $originalHeight = substr($info, 7); |  | ||||||
|                                 continue; |  | ||||||
|                             } |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                      |  | ||||||
|                     $originalRatio = $originalWidth / $originalHeight; |  | ||||||
|                      |  | ||||||
|                     $targetRatio = $format->getWidth() / $format->getHeight(); |  | ||||||
|                      |  | ||||||
|                     if($targetRatio >= $originalRatio){ |  | ||||||
|                         $height = $format->getHeight(); |  | ||||||
|                         $width = $format->getHeight() * $originalRatio; |  | ||||||
|                     }else{ |  | ||||||
|                         $width = $format->getWidth(); |  | ||||||
|                         $height = $format->getWidth() / $originalRatio; |  | ||||||
|                     } |  | ||||||
| 
 |  | ||||||
|                     $width = $this->getMultiple($width, 16); |  | ||||||
|                     $height = $this->getMultiple($height, 16); |  | ||||||
|                     break; |  | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|  |             $result = $this->prober->probeStreams($this->pathfile); | ||||||
|  | 
 | ||||||
|  |             $originalWidth = $format->getWidth(); | ||||||
|  |             $originalHeight = $format->getHeight(); | ||||||
|  | 
 | ||||||
|  |             foreach ($result as $stream) { | ||||||
|  |                 foreach ($stream as $info) { | ||||||
|  |                     if (strpos($info, 'width=') === 0) { | ||||||
|  |                         $originalWidth = substr($info, 6); | ||||||
|  |                         continue; | ||||||
|  |                     } | ||||||
|  |                     if (strpos($info, 'height=') === 0) { | ||||||
|  |                         $originalHeight = substr($info, 7); | ||||||
|  |                         continue; | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             list($width, $height) = $format->getComputedDimensions($originalWidth, $originalHeight); | ||||||
|  | 
 | ||||||
|  |             $width = $this->getMultiple($format->getWidth(), 16); | ||||||
|  |             $height = $this->getMultiple($format->getHeight(), 16); | ||||||
|  | 
 | ||||||
|             $cmd_part2 .= ' -s ' . $width . 'x' . $height; |             $cmd_part2 .= ' -s ' . $width . 'x' . $height; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -73,7 +73,7 @@ class FFProbe extends Binary | ||||||
| 
 | 
 | ||||||
|             $ret[$n][] = $line; |             $ret[$n][] = $line; | ||||||
|         } |         } | ||||||
|          | 
 | ||||||
|         return $ret; |         return $ret; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue