Added a getAsBase64() method to Frame object (#292)
* Added a getAsBase64() method to Frame object * Merged the getBase64 method in save method * Differentiate the two possible return * Corrected typo (Edited from github)
This commit is contained in:
		
					parent
					
						
							
								21c28dea25
							
						
					
				
			
			
				commit
				
					
						fe47ab74ef
					
				
			
		
					 2 changed files with 40 additions and 14 deletions
				
			
		|  | @ -85,26 +85,31 @@ class Frame extends AbstractMediaType | |||
|      * | ||||
|      * @throws RuntimeException | ||||
|      */ | ||||
|     public function save($pathfile, $accurate = false) | ||||
|     public function save($pathfile, $accurate = false, $returnBase64 = false) | ||||
|     { | ||||
|         /** | ||||
|          * might be optimized with http://ffmpeg.org/trac/ffmpeg/wiki/Seeking%20with%20FFmpeg | ||||
|          * @see http://ffmpeg.org/ffmpeg.html#Main-options
 | ||||
|          */ | ||||
|         $outputFormat = $returnBase64 ? "image2pipe" : "image2"; | ||||
|         if (!$accurate) { | ||||
|             $commands = array( | ||||
|                 '-y', '-ss', (string) $this->timecode, | ||||
|                 '-i', $this->pathfile, | ||||
|                 '-vframes', '1', | ||||
|                 '-f', 'image2' | ||||
|                 '-f', $outputFormat | ||||
|             ); | ||||
|         } else { | ||||
|             $commands = array( | ||||
|                 '-y', '-i', $this->pathfile, | ||||
|                 '-vframes', '1', '-ss', (string) $this->timecode, | ||||
|                 '-f', 'image2' | ||||
|                 '-f', $outputFormat | ||||
|             ); | ||||
|         } | ||||
|          | ||||
|         if($returnBase64) { | ||||
|             array_push($commands, "-"); | ||||
|         } | ||||
| 
 | ||||
|         foreach ($this->filters as $filter) { | ||||
|             $commands = array_merge($commands, $filter->apply($this)); | ||||
|  | @ -113,12 +118,16 @@ class Frame extends AbstractMediaType | |||
|         $commands = array_merge($commands, array($pathfile)); | ||||
| 
 | ||||
|         try { | ||||
|             $this->driver->command($commands); | ||||
|             if(!$returnBase64) { | ||||
|                 $this->driver->command($commands); | ||||
|                 return $this; | ||||
|             } | ||||
|             else { | ||||
|                 return $this->driver->command($commands); | ||||
|             } | ||||
|         } catch (ExecutionFailureException $e) { | ||||
|             $this->cleanupTemporaryFile($pathfile); | ||||
|             throw new RuntimeException('Unable to save frame', $e->getCode(), $e); | ||||
|         } | ||||
| 
 | ||||
|         return $this; | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue