]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/VideoThumbnails/VideoThumbnailsPlugin.php
Merge branch 'master' of git.gnu.io:Quix0r/gnu-social
[quix0rs-gnu-social.git] / plugins / VideoThumbnails / VideoThumbnailsPlugin.php
index 6bd697cd0210012e9a1d9d3aa69b0c5f67c445f3..32ce37c1cf2945d4286f6d0e9177ec0aa44f440a 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * GNU social - a federating social network
  *
- * Plugin to make thumbnails of video files with ffmpeg
+ * Plugin to make thumbnails of video files with avconv
  *
  * PHP version 5
  *
@@ -31,10 +31,13 @@ if (!defined('GNUSOCIAL')) { exit(1); }
 
 /*
  * Dependencies:
- *  php5-ffmpeg
+ *  avconv (external program call)
  *  php5-gd
  *
- * Video support will depend on your ffmpeg.
+ * Todo:
+ *  Make sure we support ffmpeg too, so we're not super Debian oriented.
+ *
+ * Video support will depend on your avconv.
  */
 
 class VideoThumbnailsPlugin extends Plugin
@@ -48,28 +51,19 @@ class VideoThumbnailsPlugin extends Plugin
     {
         // The calling function might accidentally pass application/ogg videos.
         // If that's a problem, let's fix it in the calling function.
-        if ($media !== 'video') {
+        if ($media !== 'video' || empty($file->filename)) {
             return true;
         }
 
-        $movie = new ffmpeg_movie($file->getPath(), false);
+        // Let's save our frame to a temporary file. If we fail, remove it.
+        $imgPath = tempnam(sys_get_temp_dir(), 'socialthumb-');
 
-        $frames = $movie->getFrameCount();
-        if ($frames > 0) {
-            $frame = $movie->getFrame(floor($frames/2));
-        } else {
-            $frame = $movie->getNextKeyFrame();
-        }
+        $result = exec('avconv -i '.escapeshellarg($file->getPath()).' -vcodec mjpeg -vframes 1 -f image2 -an '.escapeshellarg($imgPath));
 
-        // We failed to get a frame.
-        if (!$frame instanceof ffmpeg_frame) {
-            return true;
-        }
-
-        // Let's save our frame to a temporary file. If we fail, remove it.
-        $imgPath = tempnam(common_get_temp_dir(), 'socialthumb');
-        if (!imagejpeg($frame->toGDImage(), $imgPath)) {
+        if (!getimagesize($imgPath)) {
+            common_debug('exec of "avconv" produced a bad/nonexisting image it seems');
             @unlink($imgPath);
+            $imgPath = null;    // pretend we didn't touch it
             return true;
         }
         return false;