movies.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Frank Karlitschek frank@owncloud.org
  4. * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
  5. * This file is licensed under the Affero General Public License version 3 or
  6. * later.
  7. * See the COPYING-README file.
  8. */
  9. namespace OC\Preview;
  10. $isShellExecEnabled = !in_array('shell_exec', explode(', ', ini_get('disable_functions')));
  11. $whichFFMPEG = shell_exec('which ffmpeg');
  12. $isFFMPEGAvailable = !empty($whichFFMPEG);
  13. if($isShellExecEnabled && $isFFMPEGAvailable) {
  14. class Movie extends Provider {
  15. public function getMimeType() {
  16. return '/video\/.*/';
  17. }
  18. public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
  19. $absPath = \OC_Helper::tmpFile();
  20. $tmpPath = \OC_Helper::tmpFile();
  21. $handle = $fileview->fopen($path, 'rb');
  22. $firstmb = stream_get_contents($handle, 1048576); //1024 * 1024 = 1048576
  23. file_put_contents($absPath, $firstmb);
  24. //$cmd = 'ffmpeg -y -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 -ss 1 -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . $tmpPath;
  25. $cmd = 'ffmpeg -an -y -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 -ss 1 ' . escapeshellarg($tmpPath);
  26. shell_exec($cmd);
  27. $image = new \OC_Image($tmpPath);
  28. unlink($absPath);
  29. unlink($tmpPath);
  30. return $image->valid() ? $image : false;
  31. }
  32. }
  33. \OC\Preview::registerProvider('OC\Preview\Movie');
  34. }