Skip to content

Commit 65988e7

Browse files
authored
Merge pull request #28889 from nextcloud/bug/28694/fallback-movie-provider
Fall back to full file for video previews
2 parents 29cbff9 + 24e0255 commit 65988e7

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

lib/private/Preview/Movie.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,34 @@ public function getMimeType(): string {
5050
public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
5151
// TODO: use proc_open() and stream the source file ?
5252
53-
$absPath = $this->getLocalFile($file, 5242880); // only use the first 5MB
53+
$result = null;
54+
if ($this->useTempFile($file)) {
55+
// try downloading 5 MB first as it's likely that the first frames are present there
56+
// in some cases this doesn't work for example when the moov atom is at the
57+
// end of the file, so if it fails we fall back to getting the full file
58+
$sizeAttempts = [5242880, null];
59+
} else {
60+
// size is irrelevant, only attempt once
61+
$sizeAttempts = [null];
62+
}
5463

55-
$result = $this->generateThumbNail($maxX, $maxY, $absPath, 5);
56-
if ($result === null) {
57-
$result = $this->generateThumbNail($maxX, $maxY, $absPath, 1);
64+
foreach ($sizeAttempts as $size) {
65+
$absPath = $this->getLocalFile($file, $size);
66+
67+
$result = $this->generateThumbNail($maxX, $maxY, $absPath, 5);
5868
if ($result === null) {
59-
$result = $this->generateThumbNail($maxX, $maxY, $absPath, 0);
69+
$result = $this->generateThumbNail($maxX, $maxY, $absPath, 1);
70+
if ($result === null) {
71+
$result = $this->generateThumbNail($maxX, $maxY, $absPath, 0);
72+
}
6073
}
61-
}
6274

63-
$this->cleanTmpFiles();
75+
$this->cleanTmpFiles();
76+
77+
if ($result !== null) {
78+
break;
79+
}
80+
}
6481

6582
return $result;
6683
}

lib/private/Preview/ProviderV2.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ public function isAvailable(FileInfo $file): bool {
7070
*/
7171
abstract public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage;
7272

73+
protected function useTempFile(File $file) {
74+
return $file->isEncrypted() || !$file->getStorage()->isLocal();
75+
}
76+
7377
/**
7478
* Get a path to either the local file or temporary file
7579
*
@@ -78,8 +82,7 @@ abstract public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage
7882
* @return string
7983
*/
8084
protected function getLocalFile(File $file, int $maxSize = null): string {
81-
$useTempFile = $file->isEncrypted() || !$file->getStorage()->isLocal();
82-
if ($useTempFile) {
85+
if ($this->useTempFile($file)) {
8386
$absPath = \OC::$server->getTempManager()->getTemporaryFile();
8487

8588
$content = $file->fopen('r');

0 commit comments

Comments
 (0)