aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Preview/Movie.php
diff options
context:
space:
mode:
authorJ0WI <J0WI@users.noreply.github.com>2021-04-13 01:17:28 +0200
committerJ0WI <J0WI@users.noreply.github.com>2021-10-23 23:15:42 +0200
commit047cab8dd26d9c31c6a747499a06c80c7e29c37e (patch)
tree3c7b148601ce333e72cfb1960a3cd453d8ab0064 /lib/private/Preview/Movie.php
parent623ac8c7066227d9bf499cd42ca7c8a27ecf4346 (diff)
downloadnextcloud-server-047cab8dd26d9c31c6a747499a06c80c7e29c37e.tar.gz
nextcloud-server-047cab8dd26d9c31c6a747499a06c80c7e29c37e.zip
Use findBinaryPath for previews
Signed-off-by: J0WI <J0WI@users.noreply.github.com>
Diffstat (limited to 'lib/private/Preview/Movie.php')
-rw-r--r--lib/private/Preview/Movie.php49
1 files changed, 45 insertions, 4 deletions
diff --git a/lib/private/Preview/Movie.php b/lib/private/Preview/Movie.php
index b139758596c..eab81e1ed48 100644
--- a/lib/private/Preview/Movie.php
+++ b/lib/private/Preview/Movie.php
@@ -30,13 +30,27 @@
namespace OC\Preview;
use OCP\Files\File;
+use OCP\Files\FileInfo;
use OCP\IImage;
use Psr\Log\LoggerInterface;
class Movie extends ProviderV2 {
+
+ /**
+ * @deprecated 23.0.0 pass option to \OCP\Preview\ProviderV2
+ * @var string
+ */
public static $avconvBinary;
+
+ /**
+ * @deprecated 23.0.0 pass option to \OCP\Preview\ProviderV2
+ * @var string
+ */
public static $ffmpegBinary;
+ /** @var string */
+ private $binary;
+
/**
* {@inheritDoc}
*/
@@ -47,9 +61,30 @@ class Movie extends ProviderV2 {
/**
* {@inheritDoc}
*/
+ public function isAvailable(FileInfo $file): bool {
+ // TODO: remove when avconv is dropped
+ if (is_null($this->binary)) {
+ if (isset($this->options['movieBinary'])) {
+ $this->binary = $this->options['movieBinary'];
+ } elseif (is_string(self::$avconvBinary)) {
+ $this->binary = self::$avconvBinary;
+ } elseif (is_string(self::$ffmpegBinary)) {
+ $this->binary = self::$ffmpegBinary;
+ }
+ }
+ return is_string($this->binary);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
// TODO: use proc_open() and stream the source file ?
+ if (!$this->isAvailable($file)) {
+ return null;
+ }
+
$result = null;
if ($this->useTempFile($file)) {
// try downloading 5 MB first as it's likely that the first frames are present there
@@ -92,17 +127,23 @@ class Movie extends ProviderV2 {
private function generateThumbNail($maxX, $maxY, $absPath, $second): ?IImage {
$tmpPath = \OC::$server->getTempManager()->getTemporaryFile();
- if (self::$avconvBinary) {
- $cmd = self::$avconvBinary . ' -y -ss ' . escapeshellarg($second) .
+ $binaryType = substr(strrchr($this->binary, '/'), 1);
+
+ if ($binaryType === 'avconv') {
+ $cmd = $this->binary . ' -y -ss ' . escapeshellarg($second) .
' -i ' . escapeshellarg($absPath) .
' -an -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) .
' 2>&1';
- } else {
- $cmd = self::$ffmpegBinary . ' -y -ss ' . escapeshellarg($second) .
+ } elseif ($binaryType === 'ffmpeg') {
+ $cmd = $this->binary . ' -y -ss ' . escapeshellarg($second) .
' -i ' . escapeshellarg($absPath) .
' -f mjpeg -vframes 1' .
' ' . escapeshellarg($tmpPath) .
' 2>&1';
+ } else {
+ // Not supported
+ unlink($tmpPath);
+ return null;
}
exec($cmd, $output, $returnCode);