视频录制,停止录制

This commit is contained in:
18792927508
2023-11-15 16:12:48 +08:00
parent cd22f387f4
commit eb09ba6ae9
6 changed files with 167 additions and 11 deletions
@@ -17,4 +17,13 @@ public interface VideoService {
AjaxResult bindCaseId(Long caseId, String roomId);
AjaxResult videoList(Long caseId);
/**
* 开启腾讯云录制
* @param roomId
* @return
*/
AjaxResult openCloudRecording(long caseId,String roomId);
AjaxResult closeDeleteCloudRecording(String taskId);
}
@@ -79,8 +79,8 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
@Value("${imConfig.sdkAppId}")
private long sdkAppId;
// 腾讯云即时通信密钥
@Value("${imConfig.secretKey}")
private String secretKey;
@Value("${imConfig.sdkSecretKey}")
private String sdkSecretKey;
@Autowired
private CaseApplicationMapper caseApplicationMapper;
@@ -113,8 +113,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
private DeptIdentifyMapper deptIdentifyMapper;
@Autowired
private ReservedConferenceMapper reservedConferenceMapper;
@Autowired
private SysDeptMapper deptMapper;
// 手机号正则
private static final Pattern TELEPHONE_REGX = Pattern.compile("^1(3\\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\\d|9[0-35-9])\\d{8}$");
@@ -2520,7 +2519,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
* @return
*/
public String generateUserSign(String userId) {
TLSSigAPIv2 tlsSigAPIv2 = new TLSSigAPIv2(sdkAppId, secretKey);
TLSSigAPIv2 tlsSigAPIv2 = new TLSSigAPIv2(sdkAppId, sdkSecretKey);
return tlsSigAPIv2.genUserSig(userId, 60 * 60 * 10);
}
@@ -2543,6 +2542,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
}
// 生成房间号id
String roomId = generateRoomId();
// String roomId = reservedConferenceVO.getRoomId();
Date startTime = reservedConferenceVO.getScheduleStartTime();
Date endTime = reservedConferenceVO.getScheduleEndTime();
Random rand = new Random();
@@ -31,11 +31,15 @@ import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.trtc.v20190722.TrtcClient;
import com.tencentcloudapi.trtc.v20190722.models.*;
import com.tencentcloudapi.vod.v20180717.VodClient;
import com.tencentcloudapi.vod.v20180717.models.DescribeMediaInfosRequest;
import com.tencentcloudapi.vod.v20180717.models.DescribeMediaInfosResponse;
import com.tencentyun.TLSSigAPIv2;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ResourceUtils;
@@ -63,6 +67,18 @@ import static com.ruoyi.common.utils.file.FileUploadUtils.getPathFileName;
@Service
@Slf4j
public class VideoServiceImpl implements VideoService {
// 腾讯云即时通信sdkAppId
@Value("${imConfig.sdkAppId}")
private long sdkAppId;
// 腾讯云即时通信密钥
@Value("${imConfig.sdkSecretKey}")
private String sdkSecretKey;
// 腾讯云个人账户secretId
@Value("${imConfig.secretId}")
private String secretId;
// 腾讯云个人账户密钥
@Value("${imConfig.secretKey}")
private String secretKey;
@Autowired
private CaseApplicationMapper caseApplicationMapper;
@Autowired
@@ -149,6 +165,98 @@ public class VideoServiceImpl implements VideoService {
return AjaxResult.success(caseAttachList);
}
/**
* 开启腾讯云录制
* @param roomId
* @return
*/
@Override
public AjaxResult openCloudRecording(long caseId,String roomId) {
try {
String userId="recorder_"+roomId;
Credential cred = new Credential(secretId, secretKey);
// 实例化一个http选项,可选的,没有特殊需求可以跳过
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("trtc.tencentcloudapi.com");
// 实例化一个client选项,可选的,没有特殊需求可以跳过
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
// 实例化要请求产品的client对象,clientProfile是可选的
TrtcClient client = new TrtcClient(cred, "ap-beijing", clientProfile);
// 实例化一个请求对象,每个接口都会对应一个request对象
CreateCloudRecordingRequest req = new CreateCloudRecordingRequest();
req.setSdkAppId(sdkAppId); // SdkAppId – TRTC的[SdkAppId](https://cloud.tencent.com/document/product/647/46351#sdkappid),和录制的房间所对应的SdkAppId相同
req.setRoomId(roomId); // RoomId – TRTC的[RoomId](https://cloud.tencent.com/document/product/647/46351#roomid),录制的TRTC房间所对应的RoomId
req.setRoomIdType(1L);
/**
* 录制机器人用于进入TRTC房间拉流的[UserId](https://cloud.tencent.com/document/product/647/46351#userid),
* 注意这个UserId不能与其他TRTC房间内的主播或者其他录制任务等已经使用的UserId重复,建议可以把房间ID作为userId的标识的一部分,
* 即录制机器人进入房间的userid应保证独立且唯一
*/
req.setUserId(userId);
TLSSigAPIv2 api = new TLSSigAPIv2(Long.valueOf(sdkAppId), sdkSecretKey);
String userSign = api.genUserSig(userId, 60 * 60 * 10);
req.setUserSig(userSign); // 录制机器人用于进入TRTC房间拉流的用户签名,当前 UserId 对应的验证签名,相当于登录密码
RecordParams recordParams = new RecordParams();
// 混流录制
recordParams.setMaxIdleTime(60L*5); // 5分钟内房间里面没有主播,自动停止录制
recordParams.setStreamType(0L); // 0:录制音频+视频流(默认); 1:仅录制音频流; 2:仅录制视频流
recordParams.setRecordMode(2L); // 1:单流录制,分别录制房间的订阅UserId的音频和视频,将录制文件上传至云存储; 2:混流录制,将房间内订阅UserId的音视频混录成一个音视频文件,将录制文件上传至云存储;
recordParams.setOutputFormat(0L); // 0:(默认)输出文件为hls格式。1:输出文件格式为hls+mp4。2:输出文件格式为hls+aac
StorageParams storageParams1 = new StorageParams();
CloudVod cloudVod1 = new CloudVod();
TencentVod tencentVod1 = new TencentVod();
// 录制的文件永久保存
tencentVod1.setExpireTime(0L);
// 录制文件名拼接前缀
tencentVod1.setUserDefineRecordId(caseId+"@");
cloudVod1.setTencentVod(tencentVod1); // 腾讯云点播相关参数。
storageParams1.setCloudVod(cloudVod1); // 必填】腾讯云云点播的账号信息,目前仅支持存储至腾讯云点播VOD。
req.setRecordParams(recordParams); // 云端录制控制参数
req.setStorageParams(storageParams1); // 云端录制文件上传到云存储的参数(目前只支持使用腾讯云点播作为存储)
// 返回的resp是一个CreateCloudRecordingResponse的实例,与请求对象对应
CreateCloudRecordingResponse resp = client.CreateCloudRecording(req);
// 输出json格式的字符串回包
String s = JSON.toJSONString(resp);
return AjaxResult.success(s);
} catch (TencentCloudSDKException e) {
return AjaxResult.error(e.toString());
}
}
@Override
public AjaxResult closeDeleteCloudRecording(String taskId) {
// 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
// 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305
// 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
Credential cred = new Credential(secretId, secretKey);
// 实例化一个http选项,可选的,没有特殊需求可以跳过
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("trtc.tencentcloudapi.com");
// 实例化一个client选项,可选的,没有特殊需求可以跳过
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
// 实例化要请求产品的client对象,clientProfile是可选的
TrtcClient client = new TrtcClient(cred, "ap-beijing", clientProfile);
// 实例化一个请求对象,每个接口都会对应一个request对象
DeleteCloudRecordingRequest req = new DeleteCloudRecordingRequest();
// 返回的resp是一个DeleteCloudRecordingResponse的实例,与请求对象对应
DeleteCloudRecordingResponse resp = null;
try {
resp = client.DeleteCloudRecording(req);
} catch (TencentCloudSDKException e) {
return AjaxResult.error(e.toString());
}
return AjaxResult.success(DeleteCloudRecordingResponse.toJsonString(resp));
}
/**
* 查询出音视频集合,并下载,在将云点播上面的音视频删除
* @param fileIds 点播平台唯一ID集合
@@ -68,7 +68,7 @@
c.update_by ,c.update_time , c.arbitrator_name,ca.application_organ_id applicationOrganId ,ca.application_organ_name as applicantName,c.filearbitra_url
from case_log_record r
join case_application c on r.case_appli_id=c.id
LEFT JOIN case_affiliate ca ON ca.case_appli_id = c.id AND ca.identity_type=1
JOIN case_affiliate ca ON ca.case_appli_id = c.id AND ca.identity_type=1
<where>
<if test="lockStatus != null">
@@ -125,7 +125,7 @@
applicantName,
c.arbitrator_id,ca.identity_num , ca.identity_type,c.filearbitra_url,c.lock_status
from case_application c
LEFT JOIN case_affiliate ca ON ca.case_appli_id = c.id
JOIN case_affiliate ca ON ca.case_appli_id = c.id
<where>
<if test="caseStatus != null">
AND c.case_status = #{caseStatus}
@@ -219,7 +219,7 @@
c.case_status,ca.application_organ_id,
c.arbitrator_id,ca.identity_num , ca.identity_type
from case_application c
LEFT JOIN case_affiliate ca ON ca.case_appli_id = c.id
JOIN case_affiliate ca ON ca.case_appli_id = c.id
<where>
<if test="caseStatus != null">
AND c.case_status = #{caseStatus}
@@ -298,7 +298,7 @@
c.begin_video_date ,c.online_video_person ,c.contract_number ,c.create_by ,c.create_time ,c.lock_status,
c.update_by ,c.update_time , c.arbitrator_name,ca.application_organ_id applicationOrganId ,ca.application_organ_name as applicantName,c.filearbitra_url
from case_application c
LEFT JOIN case_affiliate ca ON ca.case_appli_id = c.id AND ca.identity_type=1
JOIN case_affiliate ca ON ca.case_appli_id = c.id AND ca.identity_type=1
<where>
<if test="caseStatus != null">
AND c.case_status = #{caseStatus}