mirror of
https://github.com/kuaifan/dootask.git
synced 2026-02-04 04:08:16 +00:00
perf: 支持上传mov、webm视频
This commit is contained in:
parent
ee6eddf308
commit
18eaf56ff9
@ -1252,6 +1252,38 @@ class Base
|
|||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 替换开头指定字符串
|
||||||
|
* @param $string
|
||||||
|
* @param $find
|
||||||
|
* @param $replace
|
||||||
|
* @param $lower
|
||||||
|
* @return mixed|string
|
||||||
|
*/
|
||||||
|
public static function leftReplace($string, $find, $replace, $lower = false)
|
||||||
|
{
|
||||||
|
if (Base::leftExists($string, $find, $lower)) {
|
||||||
|
$string = $replace . substr($string, strlen($find));
|
||||||
|
}
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 替换结尾指定字符串
|
||||||
|
* @param $string
|
||||||
|
* @param $find
|
||||||
|
* @param $replace
|
||||||
|
* @param $lower
|
||||||
|
* @return mixed|string
|
||||||
|
*/
|
||||||
|
public static function rightReplace($string, $find, $replace, $lower = false)
|
||||||
|
{
|
||||||
|
if (Base::rightExists($string, $find, $lower)) {
|
||||||
|
$string = substr($string, 0, strlen($find) * -1) . $replace;
|
||||||
|
}
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 截取指定字符串
|
* 截取指定字符串
|
||||||
* @param $str
|
* @param $str
|
||||||
@ -2218,7 +2250,7 @@ class Base
|
|||||||
$type = ['jpg', 'jpeg', 'webp', 'gif', 'png'];
|
$type = ['jpg', 'jpeg', 'webp', 'gif', 'png'];
|
||||||
break;
|
break;
|
||||||
case 'video':
|
case 'video':
|
||||||
$type = ['rm', 'rmvb', 'wmv', 'avi', 'mpg', 'mpeg', 'mp4', 'webm'];
|
$type = ['rm', 'rmvb', 'wmv', 'avi', 'mpg', 'mpeg', 'mp4', 'mov', 'webm'];
|
||||||
break;
|
break;
|
||||||
case 'audio':
|
case 'audio':
|
||||||
$type = ['mp3', 'wma', 'wav', 'amr'];
|
$type = ['mp3', 'wma', 'wav', 'amr'];
|
||||||
@ -2233,7 +2265,7 @@ class Base
|
|||||||
$type = ['zip'];
|
$type = ['zip'];
|
||||||
break;
|
break;
|
||||||
case 'file':
|
case 'file':
|
||||||
$type = ['jpg', 'jpeg', 'webp', 'png', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'esp', 'pdf', 'rar', 'zip', 'gz', 'ai', 'avi', 'bmp', 'cdr', 'eps', 'mov', 'mp3', 'mp4', 'webm', 'pr', 'psd', 'svg', 'tif'];
|
$type = ['jpg', 'jpeg', 'webp', 'png', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'esp', 'pdf', 'rar', 'zip', 'gz', 'ai', 'avi', 'bmp', 'cdr', 'eps', 'mp3', 'mp4', 'mov', 'webm', 'pr', 'psd', 'svg', 'tif'];
|
||||||
break;
|
break;
|
||||||
case 'firmware':
|
case 'firmware':
|
||||||
$type = ['img', 'tar', 'bin'];
|
$type = ['img', 'tar', 'bin'];
|
||||||
@ -2304,7 +2336,7 @@ class Base
|
|||||||
}
|
}
|
||||||
@chmod($array['file'], $chmod);
|
@chmod($array['file'], $chmod);
|
||||||
//iOS照片颠倒处理
|
//iOS照片颠倒处理
|
||||||
if (in_array($extension, ['jpg', 'jpeg']) && function_exists('exif_read_data')) {
|
if (in_array($array['ext'], ['jpg', 'jpeg']) && function_exists('exif_read_data')) {
|
||||||
$data = imagecreatefromstring(file_get_contents($array['file']));
|
$data = imagecreatefromstring(file_get_contents($array['file']));
|
||||||
$exif = @exif_read_data($array['file']);
|
$exif = @exif_read_data($array['file']);
|
||||||
if (!empty($exif['Orientation'])) {
|
if (!empty($exif['Orientation'])) {
|
||||||
@ -2320,18 +2352,38 @@ class Base
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
if (in_array($extension, ['mp4', 'webm'])) {
|
if (in_array($array['ext'], ['mov', 'webm'])) {
|
||||||
|
// 转换视频格式
|
||||||
|
$output = Base::rightReplace($array['file'], ".{$array['ext']}", '.mp4');
|
||||||
|
if ($array['ext'] === 'webm') {
|
||||||
|
shell_exec("ffmpeg -y -i {$array['file']} -strict experimental {$output} 2>&1");
|
||||||
|
} else {
|
||||||
|
shell_exec("ffmpeg -y -i {$array['file']} -c:v copy -c:a copy {$output} 2>&1");
|
||||||
|
}
|
||||||
|
if (file_exists($output) && filesize($output) > 0) {
|
||||||
|
@unlink($array['file']);
|
||||||
|
$array = array_merge($array, [
|
||||||
|
"name" => Base::rightReplace($array['name'], ".{$array['ext']}", '.mp4'),
|
||||||
|
"size" => Base::twoFloat(filesize($output) / 1024, true),
|
||||||
|
"file" => $output,
|
||||||
|
"path" => Base::rightReplace($array['path'], ".{$array['ext']}", '.mp4'),
|
||||||
|
"url" => Base::rightReplace($array['url'], ".{$array['ext']}", '.mp4'),
|
||||||
|
"ext" => 'mp4',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($array['ext'] == 'mp4') {
|
||||||
// 视频尺寸
|
// 视频尺寸
|
||||||
$thumbFile = $array['file'] . '_thumb.jpg';
|
$thumbFile = $array['file'] . '_thumb.jpg';
|
||||||
shell_exec("ffmpeg -i {$array['file']} -ss 1 -vframes 1 {$thumbFile} 2>&1");
|
shell_exec("ffmpeg -y -i {$array['file']} -ss 1 -vframes 1 {$thumbFile} 2>&1");
|
||||||
if (file_exists($thumbFile)) {
|
if (file_exists($thumbFile) && filesize($thumbFile) > 0) {
|
||||||
$paramet = getimagesize($thumbFile);
|
$paramet = getimagesize($thumbFile);
|
||||||
$array['width'] = $paramet[0];
|
$array['width'] = $paramet[0];
|
||||||
$array['height'] = $paramet[1];
|
$array['height'] = $paramet[1];
|
||||||
$array['thumb'] = $array['path'] . '_thumb.jpg';
|
$array['thumb'] = $array['path'] . '_thumb.jpg';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (in_array($extension, ['jpg', 'jpeg', 'webp', 'gif', 'png'])) {
|
if (in_array($array['ext'], ['jpg', 'jpeg', 'webp', 'gif', 'png'])) {
|
||||||
//图片尺寸
|
//图片尺寸
|
||||||
$paramet = getimagesize($array['file']);
|
$paramet = getimagesize($array['file']);
|
||||||
$array['width'] = $paramet[0];
|
$array['width'] = $paramet[0];
|
||||||
@ -2370,12 +2422,12 @@ class Base
|
|||||||
}
|
}
|
||||||
//生成缩略图
|
//生成缩略图
|
||||||
$array['thumb'] = $array['path'];
|
$array['thumb'] = $array['path'];
|
||||||
if ($extension === 'gif' && !isset($param['autoThumb'])) {
|
if ($array['ext'] === 'gif' && !isset($param['autoThumb'])) {
|
||||||
$param['autoThumb'] = false;
|
$param['autoThumb'] = false;
|
||||||
}
|
}
|
||||||
if ($param['autoThumb'] !== false) {
|
if ($param['autoThumb'] !== false) {
|
||||||
if ($extension = Image::thumbImage($array['file'], $array['file'] . "_thumb.{*}", 320, 0)) {
|
if ($array['ext'] = Image::thumbImage($array['file'], $array['file'] . "_thumb.{*}", 320, 0)) {
|
||||||
$array['thumb'] .= "_thumb.{$extension}";
|
$array['thumb'] .= "_thumb.{$array['ext']}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$array['thumb'] = Base::fillUrl($array['thumb']);
|
$array['thumb'] = Base::fillUrl($array['thumb']);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user