From 1f2d2790eed7f5bec84e52e63dc40d46ef170150 Mon Sep 17 00:00:00 2001 From: Silvio Date: Wed, 27 Jul 2011 16:26:39 -0300 Subject: Checks if ffmpeg extension is available at video_ffmpeg_php transcoder --- transcoders/video_ffmpeg_php.inc | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'transcoders/video_ffmpeg_php.inc') diff --git a/transcoders/video_ffmpeg_php.inc b/transcoders/video_ffmpeg_php.inc index 2569616..f22c6cb 100644 --- a/transcoders/video_ffmpeg_php.inc +++ b/transcoders/video_ffmpeg_php.inc @@ -21,6 +21,25 @@ class video_ffmpeg_php extends video_ffmpeg implements transcoder_interface { parent::__construct(); } + /** + * Load a movie. + * + * @param $videopath + * Video file path. + * + * @return + * An ffmpeg_movie object on success, FALSE otherwise. + */ + private function load_movie($videopath) { + if(!extension_loaded('ffmpeg')) { + $error_msg = t("Extension ffmpeg-php not available."); + watchdog('transcoder', $error_msg, array(), WATCHDOG_ERROR); + return FALSE; + } + + return new ffmpeg_movie($videopath); + } + /** * Generate video thumbs. */ @@ -48,7 +67,12 @@ class video_ffmpeg_php extends video_ffmpeg implements transcoder_interface { //skip files already exists, this will save ffmpeg traffic if (!is_file(drupal_realpath($thumbfile))) { // Use PHP-FFMPEG - $movie = new ffmpeg_movie($videopath); + $movie = $this->load_movie($videopath); + + if (!$movie) { + return $files; + } + $frames = $movie->getFrameCount(); $fps = $movie->getFrameRate(); @@ -88,15 +112,23 @@ class video_ffmpeg_php extends video_ffmpeg implements transcoder_interface { * Return the playtime seconds of a video */ public function get_playtime($video) { - $movie = new ffmpeg_movie($video); - return $movie->getDuration(); + $movie = $this->load_movie($video); + return (!$movie) ? 0 : $movie->getDuration(); } /** * Return the dimensions of a video */ public function get_dimensions($video) { - $movie = new ffmpeg_movie($video); + $movie = $this->load_movie($video); + + if (!$movie) { + return array( + 'width' => 0, + 'height' => 0, + ); + } + $res['width'] = $movie->getFrameWidth(); $res['height'] = $movie->getFrameHeight(); return $res; -- cgit v1.2.3