@@ -29,73 +29,73 @@ |
||
29 | 29 | use OCP\IImage; |
30 | 30 | |
31 | 31 | class Movie extends ProviderV2 { |
32 | - public static $avconvBinary; |
|
33 | - public static $ffmpegBinary; |
|
32 | + public static $avconvBinary; |
|
33 | + public static $ffmpegBinary; |
|
34 | 34 | |
35 | - /** |
|
36 | - * {@inheritDoc} |
|
37 | - */ |
|
38 | - public function getMimeType(): string { |
|
39 | - return '/video\/.*/'; |
|
40 | - } |
|
35 | + /** |
|
36 | + * {@inheritDoc} |
|
37 | + */ |
|
38 | + public function getMimeType(): string { |
|
39 | + return '/video\/.*/'; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * {@inheritDoc} |
|
44 | - */ |
|
45 | - public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage { |
|
46 | - // TODO: use proc_open() and stream the source file ? |
|
42 | + /** |
|
43 | + * {@inheritDoc} |
|
44 | + */ |
|
45 | + public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage { |
|
46 | + // TODO: use proc_open() and stream the source file ? |
|
47 | 47 | |
48 | - $absPath = $this->getLocalFile($file, 5242880); // only use the first 5MB |
|
48 | + $absPath = $this->getLocalFile($file, 5242880); // only use the first 5MB |
|
49 | 49 | |
50 | - $result = $this->generateThumbNail($maxX, $maxY, $absPath, 5); |
|
51 | - if ($result === false) { |
|
52 | - $result = $this->generateThumbNail($maxX, $maxY, $absPath, 1); |
|
53 | - if ($result === false) { |
|
54 | - $result = $this->generateThumbNail($maxX, $maxY, $absPath, 0); |
|
55 | - } |
|
56 | - } |
|
50 | + $result = $this->generateThumbNail($maxX, $maxY, $absPath, 5); |
|
51 | + if ($result === false) { |
|
52 | + $result = $this->generateThumbNail($maxX, $maxY, $absPath, 1); |
|
53 | + if ($result === false) { |
|
54 | + $result = $this->generateThumbNail($maxX, $maxY, $absPath, 0); |
|
55 | + } |
|
56 | + } |
|
57 | 57 | |
58 | - $this->cleanTmpFiles(); |
|
58 | + $this->cleanTmpFiles(); |
|
59 | 59 | |
60 | - return $result; |
|
61 | - } |
|
60 | + return $result; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @param int $maxX |
|
65 | - * @param int $maxY |
|
66 | - * @param string $absPath |
|
67 | - * @param int $second |
|
68 | - * @return null|\OCP\IImage |
|
69 | - */ |
|
70 | - private function generateThumbNail($maxX, $maxY, $absPath, $second): ?IImage { |
|
71 | - $tmpPath = \OC::$server->getTempManager()->getTemporaryFile(); |
|
63 | + /** |
|
64 | + * @param int $maxX |
|
65 | + * @param int $maxY |
|
66 | + * @param string $absPath |
|
67 | + * @param int $second |
|
68 | + * @return null|\OCP\IImage |
|
69 | + */ |
|
70 | + private function generateThumbNail($maxX, $maxY, $absPath, $second): ?IImage { |
|
71 | + $tmpPath = \OC::$server->getTempManager()->getTemporaryFile(); |
|
72 | 72 | |
73 | - if (self::$avconvBinary) { |
|
74 | - $cmd = self::$avconvBinary . ' -y -ss ' . escapeshellarg($second) . |
|
75 | - ' -i ' . escapeshellarg($absPath) . |
|
76 | - ' -an -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) . |
|
77 | - ' > /dev/null 2>&1'; |
|
78 | - } else { |
|
79 | - $cmd = self::$ffmpegBinary . ' -y -ss ' . escapeshellarg($second) . |
|
80 | - ' -i ' . escapeshellarg($absPath) . |
|
81 | - ' -f mjpeg -vframes 1' . |
|
82 | - ' ' . escapeshellarg($tmpPath) . |
|
83 | - ' > /dev/null 2>&1'; |
|
84 | - } |
|
73 | + if (self::$avconvBinary) { |
|
74 | + $cmd = self::$avconvBinary . ' -y -ss ' . escapeshellarg($second) . |
|
75 | + ' -i ' . escapeshellarg($absPath) . |
|
76 | + ' -an -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) . |
|
77 | + ' > /dev/null 2>&1'; |
|
78 | + } else { |
|
79 | + $cmd = self::$ffmpegBinary . ' -y -ss ' . escapeshellarg($second) . |
|
80 | + ' -i ' . escapeshellarg($absPath) . |
|
81 | + ' -f mjpeg -vframes 1' . |
|
82 | + ' ' . escapeshellarg($tmpPath) . |
|
83 | + ' > /dev/null 2>&1'; |
|
84 | + } |
|
85 | 85 | |
86 | - exec($cmd, $output, $returnCode); |
|
86 | + exec($cmd, $output, $returnCode); |
|
87 | 87 | |
88 | - if ($returnCode === 0) { |
|
89 | - $image = new \OC_Image(); |
|
90 | - $image->loadFromFile($tmpPath); |
|
91 | - if ($image->valid()) { |
|
92 | - unlink($tmpPath); |
|
93 | - $image->scaleDownToFit($maxX, $maxY); |
|
88 | + if ($returnCode === 0) { |
|
89 | + $image = new \OC_Image(); |
|
90 | + $image->loadFromFile($tmpPath); |
|
91 | + if ($image->valid()) { |
|
92 | + unlink($tmpPath); |
|
93 | + $image->scaleDownToFit($maxX, $maxY); |
|
94 | 94 | |
95 | - return $image; |
|
96 | - } |
|
97 | - } |
|
98 | - unlink($tmpPath); |
|
99 | - return null; |
|
100 | - } |
|
95 | + return $image; |
|
96 | + } |
|
97 | + } |
|
98 | + unlink($tmpPath); |
|
99 | + return null; |
|
100 | + } |
|
101 | 101 | } |