diff options
author | Vincent Petry <vincent@nextcloud.com> | 2021-09-18 10:46:48 +0200 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2021-09-20 09:32:34 +0000 |
commit | 7aaf41d0f63e104c9d8d4d9a643538aab64250d0 (patch) | |
tree | 92d66594c8d7edf19a2498c602655f9fb6fe3c4f /lib | |
parent | 6c45ef5b00f5d5ba67e7bf4d2f280ef18cfc0e59 (diff) | |
download | nextcloud-server-7aaf41d0f63e104c9d8d4d9a643538aab64250d0.tar.gz nextcloud-server-7aaf41d0f63e104c9d8d4d9a643538aab64250d0.zip |
Fall back to full file for video previews
If the first 5 MB are not enough to grab a useful frame for the
thumbnail preview, fall back to reading the full file.
Signed-off-by: Vincent Petry <vincent@nextcloud.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Preview/Movie.php | 31 | ||||
-rw-r--r-- | lib/private/Preview/ProviderV2.php | 7 |
2 files changed, 29 insertions, 9 deletions
diff --git a/lib/private/Preview/Movie.php b/lib/private/Preview/Movie.php index a8d013452e2..963b2cb746e 100644 --- a/lib/private/Preview/Movie.php +++ b/lib/private/Preview/Movie.php @@ -51,17 +51,34 @@ class Movie extends ProviderV2 { public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage { // TODO: use proc_open() and stream the source file ? - $absPath = $this->getLocalFile($file, 5242880); // only use the first 5MB + $result = null; + if ($this->useTempFile($file)) { + // try downloading 5 MB first as it's likely that the first frames are present there + // in some cases this doesn't work for example when the moov atom is at the + // end of the file, so if it fails we fall back to getting the full file + $sizeAttempts = [5242880, null]; + } else { + // size is irrelevant, only attempt once + $sizeAttempts = [null]; + } - $result = $this->generateThumbNail($maxX, $maxY, $absPath, 5); - if ($result === null) { - $result = $this->generateThumbNail($maxX, $maxY, $absPath, 1); + foreach ($sizeAttempts as $size) { + $absPath = $this->getLocalFile($file, $size); + + $result = $this->generateThumbNail($maxX, $maxY, $absPath, 5); if ($result === null) { - $result = $this->generateThumbNail($maxX, $maxY, $absPath, 0); + $result = $this->generateThumbNail($maxX, $maxY, $absPath, 1); + if ($result === null) { + $result = $this->generateThumbNail($maxX, $maxY, $absPath, 0); + } } - } - $this->cleanTmpFiles(); + $this->cleanTmpFiles(); + + if ($result !== null) { + break; + } + } return $result; } diff --git a/lib/private/Preview/ProviderV2.php b/lib/private/Preview/ProviderV2.php index 5a369639892..ae2c678d66d 100644 --- a/lib/private/Preview/ProviderV2.php +++ b/lib/private/Preview/ProviderV2.php @@ -71,6 +71,10 @@ abstract class ProviderV2 implements IProviderV2 { */ abstract public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage; + protected function useTempFile(File $file) { + return $file->isEncrypted() || !$file->getStorage()->isLocal(); + } + /** * Get a path to either the local file or temporary file * @@ -79,8 +83,7 @@ abstract class ProviderV2 implements IProviderV2 { * @return string */ protected function getLocalFile(File $file, int $maxSize = null): string { - $useTempFile = $file->isEncrypted() || !$file->getStorage()->isLocal(); - if ($useTempFile) { + if ($this->useTempFile($file)) { $absPath = \OC::$server->getTempManager()->getTemporaryFile(); $content = $file->fopen('r'); |