Exemplo n.º 1
0
 /**
  * Returns a frame from the movie as an ffmpeg_frame object. 
  * Returns false if the frame was not found.
  * @access public
  * @return mixed boolean | ffmpeg_frame
  */
 public function getFrame($frame_number = null)
 {
     //          check that we have video.
     if ($this->hasVideo() === false) {
         return false;
     }
     //          check that the frame number is not less than or equal to 0 as the argument is not
     //          zero indexed and cannot get a negative rframe number.
     if ($frame_number <= 0) {
         return false;
     }
     //          update the current frame index
     if ($frame_number === null) {
         $this->_frame_index += 1;
         $frame_number = $this->_frame_index;
     } else {
         //              zero indexed
         $frame_number -= 1;
         $this->_frame_index = $frame_number;
     }
     //          check the frame required exists in the video
     if ($frame_number > $this->getFrameCount()) {
         return false;
     }
     //          get the timecode of the frame to extract;
     $timecode = Timecode::parseTimecode($frame_number, '%fn', $this->getFrameRate());
     //          get the temp directory for the output.
     $config = Config::getInstance();
     $temp = new TempFile($config->temp_directory);
     $output_path = $temp->file(false, 'png');
     //          perform the extraction
     $output = $this->_toolkit->extractFrame($timecode)->save($output_path, null, Media::OVERWRITE_UNIQUE);
     //          then convert the image to GD resource and tidy the temp file.
     $gd_img = $output->toGdImage();
     unlink($output->getOutput()->getMediaPath());
     //          return the ffmpeg_frame object.
     require_once dirname(__FILE__) . 'ffmpeg_frame.php';
     return new ffmpeg_frame($gd_img, $timecode->getTimecode('%sf.%ms'));
 }