From 0efed16fb38616e5a1c94fa5f1f74107059d6d43 Mon Sep 17 00:00:00 2001 From: Heshan Date: Wed, 6 Jul 2011 11:08:33 +0530 Subject: #1209984 by silvio, Support for ffmpeg-php --- transcoders/video_ffmpeg_php.inc | 190 ++++++++++++++++++++++++++++++++++ transcoders/video_phpvideotoolkit.inc | 2 - 2 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 transcoders/video_ffmpeg_php.inc diff --git a/transcoders/video_ffmpeg_php.inc b/transcoders/video_ffmpeg_php.inc new file mode 100644 index 0000000..478c333 --- /dev/null +++ b/transcoders/video_ffmpeg_php.inc @@ -0,0 +1,190 @@ +uri); + //get the playtime from the current transcoder + $duration = $this->get_playtime($videopath); + + $files = NULL; + for ($i = 1; $i <= $total_thumbs; $i++) { + $seek = ($duration / $total_thumbs) * $i - 1; //adding minus one to prevent seek times equaling the last second of the video + $filename = file_munge_filename("video-thumb-" . $video['fid'] . "-$i.jpg", '', TRUE); + $thumbfile = $schema_thumb_path . '/' . $filename; + //skip files already exists, this will save ffmpeg traffic + if (!is_file(drupal_realpath($thumbfile))) { + // Use PHP-FFMPEG + $movie = new ffmpeg_movie($videopath); + $frames = $movie->getFrameCount(); + $fps = $movie->getFrameRate(); + + // Get the right frame number + $framenumber = (int) $seek * $fps; + if ($framenumber > $frames) { + $framenumber = $frames; + } + + // Get the frame and create thumb file + $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.
Command Executed:
%cmd
Command Output:
%out", $error_param); + // Log the error message. + watchdog('transcoder', $error_msg, array(), WATCHDOG_ERROR); + continue; + } + } + // Begin building the file object. + // @TODO : use file_munge_filename() + $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; + } + + /** + * Return the playtime seconds of a video + */ + public function get_playtime($video) { + $movie = new ffmpeg_movie($video); + return $movie->getDuration(); + } + + /** + * Return the dimensions of a video + */ + public function get_dimensions($video) { + $movie = new ffmpeg_movie($video); + $res['width'] = $movie->getFrameWidth(); + $res['height'] = $movie->getFrameHeight(); + return $res; + } + + /** + * Interface Implementations + * @see sites/all/modules/video/includes/transcoder_interface#get_name() + */ + public function get_name() { + return $this->name; + } + + /** + * Interface Implementations + * @see sites/all/modules/video/includes/transcoder_interface#get_value() + */ + public function get_value() { + return $this->value; + } + + /** + * Interface Implementations + * @see sites/all/modules/video/includes/transcoder_interface#get_help() + */ + public function get_help() { + return l(t('FFMPEG-PHP Online Manual'), 'http://ffmpeg-php.sourceforge.net/'); + } + + /** + * Interface Implementations + * @see sites/all/modules/video/includes/transcoder_interface#admin_settings() + */ + public function admin_settings() { + return parent::admin_settings(); + } + + /** + * Interface Implementations + * @see sites/all/modules/video/includes/transcoder_interface#admin_settings_validate() + */ + public function admin_settings_validate($form, &$form_state) { + return; + } + + /** + * Interface Implementations + * @see sites/all/modules/video/includes/transcoder_interface#create_job() + */ + public function create_job($video, $nid) { + return parent::create_job($video, $nid); + } + + /** + * Interface Implementations + * @see sites/all/modules/video/includes/transcoder_interface#delete_job() + */ + public function delete_job($video) { + return parent::delete_job($video); + } + + /** + * Interface Implementations + * @see sites/all/modules/video/includes/transcoder_interface#load_job() + */ + public function load_job($fid) { + return parent::load_job($fid); + } + + /** + * Interface Implementations + * @see sites/all/modules/video/includes/transcoder_interface#load_job_queue() + */ + public function load_job_queue() { + return parent::load_job_queue(); + } + + /** + * Interface Implementations + * @see sites/all/modules/video/includes/transcoder_interface#load_completed_job() + */ + public function load_completed_job(&$video) { + return parent::load_completed_job($video); + } + +} diff --git a/transcoders/video_phpvideotoolkit.inc b/transcoders/video_phpvideotoolkit.inc index 5306fed..a16aded 100644 --- a/transcoders/video_phpvideotoolkit.inc +++ b/transcoders/video_phpvideotoolkit.inc @@ -54,7 +54,6 @@ class video_phpvideotoolkit implements transcoder_interface { foreach ($available_codecs as $key => $value) { $codecs['encode'][$key] = array(); $codecs['decode'][$key] = array(); - foreach ($value as $codec_key => $codec) { if ($codec['encode']) { $codecs['encode'][$key][$codec_key] = $codec['fullname']; @@ -64,7 +63,6 @@ class video_phpvideotoolkit implements transcoder_interface { } } } - return $codecs; } -- cgit v1.2.3