You are here

public function PHPVideoToolkit::extractFrame in Video 7.2

Same name and namespace in other branches
  1. 7 libraries/phpvideotoolkit/phpvideotoolkit.php5.php \PHPVideoToolkit::extractFrame()

Extracts exactly one frame

@access public @uses $toolkit->extractFrames

Parameters

string $frame_timecode A timecode (hh:mm:ss.fn) where fn is the frame number of that second:

integer|boolean $frames_per_second The frame rate of the movie. If left as the default, FALSE. We will use PHPVideoToolkit::getFileInfo() to get: the actual frame rate. It is recommended that it is left as FALSE because an incorrect frame rate may produce unexpected results.

integer $timecode_format The format of the $extract_begin_timecode and $extract_end_timecode timecodes are being given in.: default '%hh:%mm:%ss' - %hh (hours) representative of hours - %mm (minutes) representative of minutes - %ss (seconds) representative of seconds - %fn (frame number) representative of frames (of the current second, not total frames) - %ms (milliseconds) representative of milliseconds (of the current second, not total milliseconds) (rounded to 3 decimal places) - %ft (frames total) representative of total frames (ie frame number) - %st (seconds total) representative of total seconds (rounded). - %sf (seconds floored) representative of total seconds (floored). - %mt (milliseconds total) representative of total milliseconds. (rounded to 3 decimal places) Thus you could use an alternative, '%hh:%mm:%ss:%ms', or '%hh:%mm:%ss' dependent on your usage.

boolean $check_frame_exists Makes an explicit check to see if the frame exists, default = TRUE.: Thanks to Istvan Szakacs for suggesting this check. Note, to improve performance disable this check.

File

libraries/phpvideotoolkit/phpvideotoolkit.php5.php, line 1952
Libary to access FFmpeg

Class

PHPVideoToolkit

Code

public function extractFrame($frame_timecode, $frames_per_second = FALSE, $frame_timecode_format = '%hh:%mm:%ss.%fn', $check_frame_exists = TRUE) {

  // 			get the file info, will exit if no input has been set
  if ($check_frame_exists || $frames_per_second === FALSE) {
    $info = $this
      ->getFileInfo();
    if ($info === FALSE || isset($info['video']) === FALSE) {

      // 					the input has not returned any video data so the frame rate can not be guessed
      return $this
        ->_raiseError('extractFrame_video_info_404');
    }
  }

  // 			are we autoguessing the frame rate?
  if ($frames_per_second === FALSE) {
    if (isset($info['video']['frame_rate']) === FALSE) {

      // 					the input has not returned any video data so the frame rate can not be guessed
      return $this
        ->_raiseError('extractFrame_video_frame_rate_404');
    }
    $frames_per_second = $info['video']['frame_rate'];
  }

  // 			check if frame exists
  if ($check_frame_exists) {
    if ($info['video']['frame_count'] < $this
      ->formatTimecode($frame_timecode, $frame_timecode_format, '%ft', $frames_per_second)) {

      // 					the input has not returned any video data so the frame rate can not be guessed
      return $this
        ->_raiseError('extractFrame_video_frame_count');
    }
  }

  // 			format the frame details if the timecode format is not already ok.

  /*
   if($frame_timecode_format !== '%hh:%mm:%ss.%ms')
   $frame_timecode = $this->formatTimecode($frame_timecode, $frame_timecode_format, '%hh:%mm:%ss.%ms', $frames_per_second);
   }
  */
  $this->_single_frame_extraction = 1;

  // 			we will limit the number of frames produced so the desired frame is the last image
  // 			this way we limit the cpu usage of ffmpeg
  // 			Thanks to Istvan Szakacs for pointing out that ffmpeg can export frames using the -ss hh:mm:ss[.xxx]
  // 			it has saved a lot of cpu intensive processes.
  $this
    ->extractFrames($frame_timecode, $frame_timecode, $frames_per_second, 1, $frame_timecode_format, FALSE);

  // 			register the post tidy process
  // 			$this->registerPostProcess('_extractFrameTidy', $this);
}