videos which are shorter then 5 seconds will now get a proper thumbnail at 1 second
This commit is contained in:
parent
f6551d214f
commit
d0f8cc20c5
1 changed files with 30 additions and 7 deletions
|
@ -42,7 +42,6 @@ if (!\OC_Util::runningOnWindows()) {
|
||||||
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
|
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
|
||||||
// TODO: use proc_open() and stream the source file ?
|
// TODO: use proc_open() and stream the source file ?
|
||||||
$absPath = \OC_Helper::tmpFile();
|
$absPath = \OC_Helper::tmpFile();
|
||||||
$tmpPath = \OC_Helper::tmpFile();
|
|
||||||
|
|
||||||
$handle = $fileview->fopen($path, 'rb');
|
$handle = $fileview->fopen($path, 'rb');
|
||||||
|
|
||||||
|
@ -51,14 +50,39 @@ if (!\OC_Util::runningOnWindows()) {
|
||||||
$firstmb = stream_get_contents($handle, 5242880);
|
$firstmb = stream_get_contents($handle, 5242880);
|
||||||
file_put_contents($absPath, $firstmb);
|
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 $maxX
|
||||||
|
* @param $maxY
|
||||||
|
* @param $absPath
|
||||||
|
* @param $tmpPath
|
||||||
|
* @param $second
|
||||||
|
* @return bool|\OC_Image
|
||||||
|
*/
|
||||||
|
private function generateThumbNail($maxX, $maxY, $absPath, $second)
|
||||||
|
{
|
||||||
|
$tmpPath = \OC_Helper::tmpFile();
|
||||||
|
|
||||||
if (self::$avconvBinary) {
|
if (self::$avconvBinary) {
|
||||||
$cmd = self::$avconvBinary . ' -an -y -ss 5'.
|
$cmd = self::$avconvBinary . ' -an -y -ss ' . $second .
|
||||||
' -i ' . escapeshellarg($absPath) .
|
' -i ' . escapeshellarg($absPath) .
|
||||||
' -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) .
|
' -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) .
|
||||||
' > /dev/null 2>&1';
|
' > /dev/null 2>&1';
|
||||||
}
|
} else {
|
||||||
else {
|
$cmd = self::$ffmpegBinary . ' -y -ss ' .$second .
|
||||||
$cmd = self::$ffmpegBinary . ' -y -ss 5' .
|
|
||||||
' -i ' . escapeshellarg($absPath) .
|
' -i ' . escapeshellarg($absPath) .
|
||||||
' -f mjpeg -vframes 1' .
|
' -f mjpeg -vframes 1' .
|
||||||
' -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) .
|
' -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) .
|
||||||
|
@ -68,14 +92,13 @@ if (!\OC_Util::runningOnWindows()) {
|
||||||
|
|
||||||
exec($cmd, $output, $returnCode);
|
exec($cmd, $output, $returnCode);
|
||||||
|
|
||||||
unlink($absPath);
|
|
||||||
|
|
||||||
if ($returnCode === 0) {
|
if ($returnCode === 0) {
|
||||||
$image = new \OC_Image();
|
$image = new \OC_Image();
|
||||||
$image->loadFromFile($tmpPath);
|
$image->loadFromFile($tmpPath);
|
||||||
unlink($tmpPath);
|
unlink($tmpPath);
|
||||||
return $image->valid() ? $image : false;
|
return $image->valid() ? $image : false;
|
||||||
}
|
}
|
||||||
|
unlink($tmpPath);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue