diff options
-rw-r--r-- | transcoders/video_ffmpeg_php.inc | 40 |
1 files changed, 36 insertions, 4 deletions
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 @@ -22,6 +22,25 @@ class video_ffmpeg_php extends video_ffmpeg implements transcoder_interface { } /** + * 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. */ public function generate_thumbnails($video) { @@ -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; |