Browse Source

上次视频保存优化、后台转发视频问题优化

master
wanghongjun 7 months ago
parent
commit
81b09278f9
  1. 16
      app/common/controller/Upload.php
  2. 12
      app/enterprise/model/Message.php

16
app/common/controller/Upload.php

@ -154,10 +154,13 @@ class Upload extends BaseController
return $data;
}else{
$fileInfo=new FileModel;
$fileInfo->save($ret);
$exists = $fileInfo->where($ret)->find();
if (!$exists) {
$fileInfo->save($ret);
}
// 上传视频切片
if ($fileType == 4) {
$videoInfo=$this->getVideoCover($filePath);
$videoInfo=$this->getVideoCover($filePath, true);
if($videoInfo){
$poster=$this->url.$videoInfo['src'];
}else{
@ -346,7 +349,7 @@ class Upload extends BaseController
}
// 获取视频封面
public function getVideoCover($filePath){
public function getVideoCover($filePath, $is_save = false){
$fileName=pathinfo($filePath,PATHINFO_FILENAME).'.jpg';
$ffmpegPath=env('ffmpeg.bin_path','');
if(!$ffmpegPath){
@ -369,9 +372,12 @@ class Upload extends BaseController
$info=$this->upload([],$savePath,'cover/'.date('Y-m-d').'/',false);
$info['videoInfo']['duration']= ceil($duration);
unlink($savePath);
if ($info) {
if ($info && $is_save) {
$fileInfo=new FileModel;
$fileInfo->save($info);
$exists = $fileInfo->where($info)->find();
if (!$exists) {
$fileInfo->save($info);
}
}
return $info;
}

12
app/enterprise/model/Message.php

@ -6,6 +6,7 @@
namespace app\enterprise\model;
use app\BaseModel;
use app\common\controller\Upload;
use think\facade\Db;
use think\facade\Cache;
use think\model\concern\SoftDelete;
@ -217,6 +218,17 @@ class Message extends BaseModel
$sendData['fileSize']=$fileSzie;
$sendData['fileName']=$fileName;
if(in_array($sendData['type'],self::$fileType)){
if ($sendData['type'] == 'video') {
$filePath = root_path().'public' . $sendData['content'];
$videoInfo=(new Upload())->getVideoCover($filePath);
if($videoInfo){
$extends=$videoInfo['videoInfo'];
$extends['poster']=getFileUrl($videoInfo['src']);
$sendData['extends']=$extends;
}else{
$sendData['poster']=getMainHost().'/static/common/img/video.png';
}
}
$sendData['content']=getFileUrl($sendData['content']);
if($sendData['type']=='image'){
$pre=1;

Loading…
Cancel
Save