video_ffmpeg_php.inc in Video 7
File
transcoders/video_ffmpeg_php.inc
View source
<?php
include_once 'video_ffmpeg.inc';
class video_ffmpeg_php extends video_ffmpeg implements transcoder_interface {
private $name = 'FFMPEG-PHP (Use ffmpeg-php when possible)';
private $value = 'video_ffmpeg_php';
public function __construct() {
parent::__construct();
}
public function generate_thumbnails($video) {
global $user;
$video_thumb_path = variable_get('video_thumb_path', 'videos/thumbnails');
$schema_thumb_path = file_default_scheme() . '://' . $video_thumb_path . '/' . $video['fid'];
file_prepare_directory($schema_thumb_path, FILE_CREATE_DIRECTORY);
$total_thumbs = variable_get('video_thumbs', 5);
$videofile = file_load($video['fid']);
$videopath = drupal_realpath($videofile->uri);
$duration = $this
->get_playtime($videopath);
$files = NULL;
for ($i = 1; $i <= $total_thumbs; $i++) {
$seek = $duration / $total_thumbs * $i - 1;
$filename = file_munge_filename("video-thumb-" . $video['fid'] . "-{$i}.jpg", '', TRUE);
$thumbfile = $schema_thumb_path . '/' . $filename;
if (!is_file(drupal_realpath($thumbfile))) {
$movie = new ffmpeg_movie($videopath);
$frames = $movie
->getFrameCount();
$fps = $movie
->getFrameRate();
$framenumber = (int) $seek * $fps;
if ($framenumber > $frames) {
$framenumber = $frames;
}
$frame = $movie
->getFrame($framenumber);
$thumb = $frame
->toGDImage();
imagejpeg($thumb, drupal_realpath($thumbfile));
if (!file_exists(drupal_realpath($thumbfile))) {
$error_param = array(
'%file' => $thumbfile,
'%cmd' => $command,
'%out' => $command_output,
);
$error_msg = t("Error generating thumbnail for video: generated file %file does not exist.<br />Command Executed:<br />%cmd<br />Command Output:<br />%out", $error_param);
watchdog('transcoder', $error_msg, array(), WATCHDOG_ERROR);
continue;
}
}
$file = new stdClass();
$file->uid = $user->uid;
$file->status = 0;
$file->filename = trim($filename);
$file->uri = $thumbfile;
$file->filemime = file_get_mimetype($filename);
$file->filesize = filesize(drupal_realpath($thumbfile));
$file->timestamp = time();
$files[] = $file;
}
return $files;
}
public function get_playtime($video) {
$movie = new ffmpeg_movie($video);
return $movie
->getDuration();
}
public function get_dimensions($video) {
$movie = new ffmpeg_movie($video);
$res['width'] = $movie
->getFrameWidth();
$res['height'] = $movie
->getFrameHeight();
return $res;
}
public function get_name() {
return $this->name;
}
public function get_value() {
return $this->value;
}
public function get_help() {
return l(t('FFMPEG-PHP Online Manual'), 'http://ffmpeg-php.sourceforge.net/');
}
public function admin_settings() {
return parent::admin_settings();
}
public function admin_settings_validate($form, &$form_state) {
return;
}
public function create_job($video, $nid) {
return parent::create_job($video, $nid);
}
public function delete_job($video) {
return parent::delete_job($video);
}
public function load_job($fid) {
return parent::load_job($fid);
}
public function load_job_queue() {
return parent::load_job_queue();
}
public function load_completed_job(&$video) {
return parent::load_completed_job($video);
}
}