public function Transcoder::extractFrames in Video 7.2
Extract frames from the video file. This helper function will interact with only the database and it will save all the thumbnail file reference in to the database.
Return value
array of file objects, or false on failure
File
- includes/
Transcoder.inc, line 40 - Class file used to wrap the transcoder helper functions.
Class
- Transcoder
- @file Class file used to wrap the transcoder helper functions.
Code
public function extractFrames(array $video, array $field) {
global $user;
$thumbnails = db_query('SELECT f.* FROM {file_managed} f INNER JOIN {video_thumbnails} tn ON tn.thumbnailfid = f.fid WHERE tn.videofid = :fid ORDER BY f.fid', array(
':fid' => $video['fid'],
))
->fetchAllAssoc('fid');
if (!empty($thumbnails)) {
return $thumbnails;
}
if ($this->transcoder == NULL) {
return array();
}
$scheme = !empty($field['settings']['uri_scheme_thumbnails']) ? $field['settings']['uri_scheme_thumbnails'] : 'public';
$format = !empty($field['settings']['thumbnail_format']) ? $field['settings']['thumbnail_format'] : 'png';
$this->transcoder
->setInput($video);
$thumbnails = $this->transcoder
->extractFrames($scheme, $format);
$this->transcoder
->reset();
if ($thumbnails === FALSE) {
return FALSE;
}
foreach ($thumbnails as $thumb) {
// Determine whether there is an existing thumbnail
$thumb->fid = (int) db_query('SELECT fid FROM {file_managed} WHERE uri = :uri', array(
':uri' => $thumb->uri,
))
->fetchField(0);
$thumb->uid = (int) $user->uid;
// For the media module
$thumb->type = 'image';
file_save($thumb);
db_merge('video_thumbnails')
->key(array(
'videofid' => $video['fid'],
'thumbnailfid' => $thumb->fid,
))
->execute();
}
return $thumbnails;
}