public function PHPVideoToolkit::extractFrames in Video 7
Same name and namespace in other branches
- 7.2 libraries/phpvideotoolkit/phpvideotoolkit.php5.php \PHPVideoToolkit::extractFrames()
* Extracts frames from a video. * (Note; If set to 1 and the duration set by $extract_begin_timecode and $extract_end_timecode is equal to 1 you get more than one frame. * For example if you set $extract_begin_timecode='00:00:00' and $extract_end_timecode='00:00:01' you might expect because the time span is * 1 second only to get one frame if you set $frames_per_second=1. However this is not correct. The timecode you set in $extract_begin_timecode * acts as the beginning frame. Thus in this example the first frame exported will be from the very beginning of the video, the video will * then move onto the next frame and export a frame there. Therefore if you wish to export just one frame from one position in the video, * say 1 second in you should set $extract_begin_timecode='00:00:01' and set $extract_end_timecode='00:00:01'.) * * @access public *
Parameters
string $extract_begin_timecode A timecode (hh:mm:ss.fn - you can change the timecode format by changing the $timecode_format param: * it obeys the formatting of PHPVideoToolkit::formatTimecode(), see below for more info) * @param string|integer|boolean $extract_end_timecode A timecode (hh:mm:ss.fn - you can change the timecode format by changing the $timecode_format param * it obeys the formatting of PHPVideoToolkit::formatTimecode(), see below for more info), or false * if all frames from the begin timecode are to be exported. (Boolean added by Matthias. Thanks. 12th March 2007) * @param boolean|integer $frames_per_second The number of frames per second to extract. If left as default false, then the number of frames per second * will be automagically gained from PHPVideoToolkit::fileGetInfo(); * @param boolean|integer $frame_limit Frame limiter. If set to false then all the frames will be exported from the given time codes, however * if you wish to set a export limit to the number of frames that are exported you can set an integer. For example; if you set * $extract_begin_timecode='00:00:11.01', $extract_end_timecode='00:01:10.01', $frames_per_second=1, you will get one frame for every second * in the video between 00:00:11 and 00:01:10 (ie 60 frames), however if you ant to artificially limit this to exporting only ten frames * then you set $frame_limit=10. You could of course alter the timecode to reflect you desired frame number, however there are situations * when a shortcut such as this is useful and necessary. * @param 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. * @param boolean $check_frames_exist Determines if a frame exists check should be made to ensure the timecode given by $extract_end_timecode * actually exists.
1 call to PHPVideoToolkit::extractFrames()
- PHPVideoToolkit::extractFrame in libraries/
phpvideotoolkit/ phpvideotoolkit.php5.php - * Extracts exactly one frame * * @access public * @uses $toolkit->extractFrames *
File
- libraries/
phpvideotoolkit/ phpvideotoolkit.php5.php, line 1897
Class
Code
public function extractFrames($extract_begin_timecode, $extract_end_timecode, $frames_per_second = false, $frame_limit = false, $timecode_format = '%hh:%mm:%ss.%fn', $check_frames_exist = true) {
// are we autoguessing the frame rate?
if ($frames_per_second === false || $check_frames_exist) {
// get the file info, will exit if no input has been set
$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_frame_rate_404');
}
$frames_per_second = $info['video']['frame_rate'];
}
// check if frame exists
if ($check_frames_exist) {
if ($info['video']['frame_count'] < $this
->formatTimecode($extract_end_timecode, $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('extractFrames_video_end_frame_count');
}
else {
if ($extract_end_timecode !== false && $info['video']['frame_count'] < $this
->formatTimecode($extract_begin_timecode, $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('extractFrames_video_begin_frame_count');
}
}
}
// disable audio output
$this
->disableAudio();
// format the begin timecode if the timecode format is not already ok.
/*
if($timecode_format !== '%hh:%mm:%ss.%ms')
{
$extract_begin_timecode = $this->formatTimecode($extract_begin_timecode, $timecode_format, '%hh:%mm:%ss.%ms', $frames_per_second);
}
*/
$this
->addCommand('-ss', $extract_begin_timecode);
// added by Matthias on 12th March 2007
// allows for exporting the entire timeline
if ($extract_end_timecode !== false) {
// format the end timecode if the timecode format is not already ok.
if ($timecode_format !== '%hh:%mm:%ss.%ms') {
$extract_end_timecode = $this
->formatTimecode($extract_end_timecode, $timecode_format, '%hh:%mm:%ss.%ms', $frames_per_second);
}
$this
->addCommand('-t', $extract_end_timecode);
}
// set the output frame rate
$this
->setVideoFrameRate($frames_per_second);
// do we need to limit the number of frames outputted?
if ($frame_limit !== false) {
$this
->addCommand('-vframes', $frame_limit);
}
$this->_image_output_timecode_start = $extract_begin_timecode;
$this->_image_output_timecode_fps = $frames_per_second;
}