summaryrefslogtreecommitdiffstats
path: root/lib/private/preview
diff options
context:
space:
mode:
authorMorris Jobke <morris.jobke@gmail.com>2013-11-14 16:39:39 -0800
committerMorris Jobke <morris.jobke@gmail.com>2013-11-14 16:39:39 -0800
commit6ef39931cb484286e7bb7bcd8373060d3a8a5ffc (patch)
treef6f7c781a900c3e610a60d6b89142216a55638fe /lib/private/preview
parent57a3141cb19e0253ff333175a9d23188689d4f8f (diff)
parent617dc0e468cd285a28f337c565f9f9ae1aa2e85f (diff)
downloadnextcloud-server-6ef39931cb484286e7bb7bcd8373060d3a8a5ffc.tar.gz
nextcloud-server-6ef39931cb484286e7bb7bcd8373060d3a8a5ffc.zip
Merge pull request #5767 from owncloud/moviepreviewfallback
Added ffmpeg fallback when avconv is not available
Diffstat (limited to 'lib/private/preview')
-rw-r--r--lib/private/preview/movies.php60
1 files changed, 48 insertions, 12 deletions
diff --git a/lib/private/preview/movies.php b/lib/private/preview/movies.php
index 1802a20711e..28f130f7506 100644
--- a/lib/private/preview/movies.php
+++ b/lib/private/preview/movies.php
@@ -8,21 +8,39 @@
*/
namespace OC\Preview;
+function findBinaryPath($program) {
+ exec('which ' . escapeshellarg($program) . ' 2> /dev/null', $output, $returnCode);
+ if ($returnCode === 0 && count($output) > 0) {
+ return escapeshellcmd($output[0]);
+ }
+ return null;
+}
+
// movie preview is currently not supported on Windows
if (!\OC_Util::runningOnWindows()) {
- $isShellExecEnabled = !in_array('shell_exec', explode(', ', ini_get('disable_functions')));
- $whichAVCONV = ($isShellExecEnabled ? shell_exec('which avconv') : '');
- $isAVCONVAvailable = !empty($whichAVCONV);
+ $isExecEnabled = !in_array('exec', explode(', ', ini_get('disable_functions')));
+ $ffmpegBinary = null;
+ $avconvBinary = null;
+
+ if ($isExecEnabled) {
+ $avconvBinary = findBinaryPath('avconv');
+ if (!$avconvBinary) {
+ $ffmpegBinary = findBinaryPath('ffmpeg');
+ }
+ }
- if($isShellExecEnabled && $isAVCONVAvailable) {
+ if($isExecEnabled && ( $avconvBinary || $ffmpegBinary )) {
class Movie extends Provider {
+ public static $avconvBinary;
+ public static $ffmpegBinary;
public function getMimeType() {
return '/video\/.*/';
}
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
+ // TODO: use proc_open() and stream the source file ?
$absPath = \OC_Helper::tmpFile();
$tmpPath = \OC_Helper::tmpFile();
@@ -31,21 +49,39 @@ if (!\OC_Util::runningOnWindows()) {
$firstmb = stream_get_contents($handle, 1048576); //1024 * 1024 = 1048576
file_put_contents($absPath, $firstmb);
- //$cmd = 'ffmpeg -y -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 -ss 1 -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . $tmpPath;
- $cmd = 'avconv -an -y -ss 1 -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 ' . escapeshellarg($tmpPath);
+ if (self::$avconvBinary) {
+ $cmd = self::$avconvBinary . ' -an -y -ss 1'.
+ ' -i ' . escapeshellarg($absPath) .
+ ' -f mjpeg -vframes 1 ' . escapeshellarg($tmpPath) .
+ ' > /dev/null 2>&1';
+ }
+ else {
+ $cmd = self::$ffmpegBinary . ' -y -ss 1' .
+ ' -i ' . escapeshellarg($absPath) .
+ ' -f mjpeg -vframes 1' .
+ ' -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) .
+ ' ' . escapeshellarg($tmpPath) .
+ ' > /dev/null 2>&1';
+ }
- shell_exec($cmd);
-
- $image = new \OC_Image();
- $image->loadFromFile($tmpPath);
+ exec($cmd, $output, $returnCode);
unlink($absPath);
- unlink($tmpPath);
- return $image->valid() ? $image : false;
+ if ($returnCode === 0) {
+ $image = new \OC_Image();
+ $image->loadFromFile($tmpPath);
+ unlink($tmpPath);
+ return $image->valid() ? $image : false;
+ }
+ return false;
}
}
+ // a bit hacky but didn't want to use subclasses
+ Movie::$avconvBinary = $avconvBinary;
+ Movie::$ffmpegBinary = $ffmpegBinary;
+
\OC\Preview::registerProvider('OC\Preview\Movie');
}
}