Skip to content

Commit

Permalink
perf: 优化聊天视频预览
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Aug 6, 2024
1 parent e8af0f2 commit 79d4932
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/Models/WebSocketDialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,8 @@ public static function sendMsgFiles($user, $dialogIds, $files, $image64, $fileNa
"type" => 'more',
"path" => $path,
"fileName" => $fileName,
"size" => ($setting['file_upload_limit'] ?: 0) * 1024
"size" => ($setting['file_upload_limit'] ?: 0) * 1024,
"convertVideo" => true
]);
}
//
Expand Down
26 changes: 22 additions & 4 deletions app/Module/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -2229,8 +2229,26 @@ public static function image64save($param)

/**
* 上传文件
* @param array $param [ type=[文件类型], file=>Request::file, path=>文件路径, fileName=>文件名称, scale=>[压缩原图宽,高, 压缩方式], size=>限制大小KB, autoThumb=>false不要自动生成缩略图, chmod=>权限(默认0644), 'compress'=>是否压缩图片(默认true) ]
* @return array [name=>原文件名, size=>文件大小(单位KB),file=>绝对地址, path=>相对地址, url=>全路径地址, ext=>文件后缀名]
* @param array $param [
type=[文件类型],
file=>Request::file,
path=>文件路径,
fileName=>文件名称,
scale=>[压缩原图宽,高, 压缩方式],
size=>限制大小KB,
autoThumb=>false不要自动生成缩略图,
chmod=>权限(默认0644),
compress=>是否压缩图片(默认true) ,
convertVideo=>转换视频格式(默认false) ,
]
* @return array [
name=>原文件名,
size=>文件大小(单位KB),
file=>绝对地址,
path=>相对地址,
url=>全路径地址,
ext=>文件后缀名,
]
*/
public static function upload($param)
{
Expand Down Expand Up @@ -2352,7 +2370,7 @@ public static function upload($param)
}
}
//
if (in_array($array['ext'], ['mov', 'webm'])) {
if ($param['convertVideo'] && in_array($array['ext'], ['mov', 'webm'])) {
// 转换视频格式
$output = Base::rightReplace($array['file'], ".{$array['ext']}", '.mp4');
if ($array['ext'] === 'webm') {
Expand All @@ -2372,7 +2390,7 @@ public static function upload($param)
]);
}
}
if ($array['ext'] == 'mp4') {
if (in_array($array['ext'], ['mov', 'webm', 'mp4'])) {
// 视频尺寸
$thumbFile = $array['file'] . '_thumb.jpg';
shell_exec("ffmpeg -y -i {$array['file']} -ss 1 -vframes 1 {$thumbFile} 2>&1");
Expand Down

0 comments on commit 79d4932

Please sign in to comment.