diff options
author | Jörn Friedrich Dreyer <jfd@butonic.de> | 2014-04-17 11:15:05 +0200 |
---|---|---|
committer | Jörn Friedrich Dreyer <jfd@butonic.de> | 2014-04-17 11:15:05 +0200 |
commit | 8a0c8a1956f5c9f2959a48cf5c3df01eb8f61a9c (patch) | |
tree | e5ec5373d425d27f8c1588dc442e704dc842e902 /lib | |
parent | a7d7ca2fb3cab08447161261c367065e2999a67e (diff) | |
parent | a4389340b822ac8cae051811d838b6c607f88dbd (diff) | |
download | nextcloud-server-8a0c8a1956f5c9f2959a48cf5c3df01eb8f61a9c.tar.gz nextcloud-server-8a0c8a1956f5c9f2959a48cf5c3df01eb8f61a9c.zip |
Merge pull request #8240 from owncloud/thumbnail-on-short-videos-master
videos which are shorter then 5 seconds will now get a proper thumbnail ...
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/preview/movies.php | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/lib/private/preview/movies.php b/lib/private/preview/movies.php index 7e0ff51ad2e..72ccfadc6e9 100644 --- a/lib/private/preview/movies.php +++ b/lib/private/preview/movies.php @@ -42,7 +42,6 @@ if (!\OC_Util::runningOnWindows()) { 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(); $handle = $fileview->fopen($path, 'rb'); @@ -51,14 +50,39 @@ if (!\OC_Util::runningOnWindows()) { $firstmb = stream_get_contents($handle, 5242880); file_put_contents($absPath, $firstmb); + $result = $this->generateThumbNail($maxX, $maxY, $absPath, 5); + if ($result === false) { + $result = $this->generateThumbNail($maxX, $maxY, $absPath, 1); + if ($result === false) { + $result = $this->generateThumbNail($maxX, $maxY, $absPath, 0); + } + } + + unlink($absPath); + + + return $result; + } + + /** + * @param int $maxX + * @param int $maxY + * @param string $absPath + * @param string $tmpPath + * @param int $second + * @return bool|\OC_Image + */ + private function generateThumbNail($maxX, $maxY, $absPath, $second) + { + $tmpPath = \OC_Helper::tmpFile(); + if (self::$avconvBinary) { - $cmd = self::$avconvBinary . ' -an -y -ss 5'. + $cmd = self::$avconvBinary . ' -an -y -ss ' . escapeshellarg($second) . ' -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) . ' > /dev/null 2>&1'; - } - else { - $cmd = self::$ffmpegBinary . ' -y -ss 5' . + } else { + $cmd = self::$ffmpegBinary . ' -y -ss ' . escapeshellarg($second) . ' -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1' . ' -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . @@ -68,14 +92,13 @@ if (!\OC_Util::runningOnWindows()) { exec($cmd, $output, $returnCode); - unlink($absPath); - if ($returnCode === 0) { $image = new \OC_Image(); $image->loadFromFile($tmpPath); unlink($tmpPath); return $image->valid() ? $image : false; } + unlink($tmpPath); return false; } } |