优化国标录像服务端,使用zlm新接口实现功能

This commit is contained in:
648540858
2023-12-05 11:29:05 +08:00
parent fc77b3f819
commit ad36354ef4
14 changed files with 329 additions and 73 deletions

View File

@@ -275,7 +275,7 @@ public class ZLMHttpHookListener {
List<SsrcTransaction> ssrcTransactionForAll = sessionManager.getSsrcTransactionForAll(null, null, null, param.getStream());
if (ssrcTransactionForAll != null && ssrcTransactionForAll.size() == 1) {
// 为录制国标模拟一个鉴权信息
// 为录制国标模拟一个鉴权信息, 方便后续写入录像文件时使用
StreamAuthorityInfo streamAuthorityInfo = StreamAuthorityInfo.getInstanceByHook(param);
streamAuthorityInfo.setApp(param.getApp());
streamAuthorityInfo.setStream(ssrcTransactionForAll.get(0).getStream());
@@ -291,8 +291,18 @@ public class ZLMHttpHookListener {
}
// 如果是录像下载就设置视频间隔十秒
if (ssrcTransactionForAll.get(0).getType() == InviteSessionType.DOWNLOAD) {
result.setMp4_max_second(30);
result.setEnable_mp4(true);
// 获取录像的总时长,然后设置为这个视频的时长
InviteInfo inviteInfo = inviteStreamService.getInviteInfo(InviteSessionType.DOWNLOAD, deviceId, channelId, param.getStream());
if (inviteInfo.getStreamInfo() != null ) {
String startTime = inviteInfo.getStreamInfo().getStartTime();
String endTime = inviteInfo.getStreamInfo().getEndTime();
long difference = DateUtil.getDifference(startTime, endTime)/1000;
result.setMp4_max_second((int)difference);
result.setEnable_mp4(true);
// 设置为2保证得到的mp4的时长是正常的
result.setModify_stamp(2);
}
}
}
if (param.getApp().equalsIgnoreCase("rtp")) {

View File

@@ -41,4 +41,15 @@ public class HookSubscribeFactory {
return hookSubscribe;
}
public static HookSubscribeForRecordMp4 on_record_mp4(String mediaServerId, String app, String stream) {
HookSubscribeForRecordMp4 hookSubscribe = new HookSubscribeForRecordMp4();
JSONObject subscribeKey = new com.alibaba.fastjson2.JSONObject();
subscribeKey.put("app", app);
subscribeKey.put("stream", stream);
subscribeKey.put("mediaServerId", mediaServerId);
hookSubscribe.setContent(subscribeKey);
return hookSubscribe;
}
}

View File

@@ -0,0 +1,44 @@
package com.genersoft.iot.vmp.media.zlm.dto;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.annotation.JSONField;
import java.time.Instant;
/**
* hook订阅-录像完成
* @author lin
*/
public class HookSubscribeForRecordMp4 implements IHookSubscribe{
private HookType hookType = HookType.on_record_mp4;
private JSONObject content;
@JSONField(format="yyyy-MM-dd HH:mm:ss")
private Instant expires;
@Override
public HookType getHookType() {
return hookType;
}
@Override
public JSONObject getContent() {
return content;
}
public void setContent(JSONObject content) {
this.content = content;
}
@Override
public Instant getExpires() {
return expires;
}
@Override
public void setExpires(Instant expires) {
this.expires = expires;
}
}

View File

@@ -7,6 +7,7 @@ public class HookResultForOnPublish extends HookResult{
private int mp4_max_second;
private String mp4_save_path;
private String stream_replace;
private Integer modify_stamp;
public HookResultForOnPublish() {
}
@@ -60,14 +61,23 @@ public class HookResultForOnPublish extends HookResult{
this.stream_replace = stream_replace;
}
public Integer getModify_stamp() {
return modify_stamp;
}
public void setModify_stamp(Integer modify_stamp) {
this.modify_stamp = modify_stamp;
}
@Override
public String toString() {
return "HookResultForOnPublish{" +
"enable_audio=" + enable_audio +
", enable_mp4=" + enable_mp4 +
", mp4_max_second=" + mp4_max_second +
", stream_replace=" + stream_replace +
", mp4_save_path='" + mp4_save_path + '\'' +
", stream_replace='" + stream_replace + '\'' +
", modify_stamp='" + modify_stamp + '\'' +
'}';
}
}