| | |
| | | import com.ard.common.core.domain.RtpServerParam; |
| | | import com.ard.common.core.enums.LiveStreamType; |
| | | import com.ard.common.core.utils.DateUtils; |
| | | import com.ard.common.core.utils.file.FileMultipartFile; |
| | | import com.ard.gb28181.api.RemoteGb28181Service; |
| | | import com.ard.gb28181.api.domain.Device; |
| | | import com.ard.qs.api.RemoteQsDeviceService; |
| | | import com.ard.qs.api.domain.QsDevice; |
| | | import com.ard.system.api.RemoteFileService; |
| | | import com.ard.system.api.domain.SysFile; |
| | | import com.ard.work.api.RemoteCameraService; |
| | | import com.ard.work.api.RemoteChannelService; |
| | | import com.ard.work.api.domian.ArdChannel; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | | import org.springframework.util.DigestUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | @Slf4j |
| | | @Service |
| | | public class MediaServerServiceImpl implements IMediaServerService { |
| | | |
| | | @Resource |
| | | private RemoteFileService remoteFileService; |
| | | @Resource |
| | | private MediaServerMapper mediaServerMapper; |
| | | |
| | |
| | | * @param app app |
| | | * @param stream 流id |
| | | */ |
| | | //@Override |
| | | // public String snapOnPlay1(ZlmMediaServer mediaServer, String app, String stream) { |
| | | // String fileName = app + "-" + stream + ".jpg"; |
| | | // // 请求截图 |
| | | // log.info("[请求截图]: " + fileName); |
| | | // |
| | | // IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType()); |
| | | // if (mediaNodeServerService == null) { |
| | | // log.info("[getSnap] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType()); |
| | | // throw new RuntimeException("[getSnap] 失败, mediaServer的类型: " + mediaServer.getType() + ",未找到对应的实现类"); |
| | | // } |
| | | // String filePath = fileDomain + filePrefix + "/snap/" + fileName; |
| | | // mediaNodeServerService.getSnap(mediaServer, app, stream, 30, 300, this.filePath + "/snap", fileName); |
| | | // return filePath; |
| | | // } |
| | | /** |
| | | * 点播成功时调用截图 |
| | | * |
| | | * @param mediaServer media |
| | | * @param app app |
| | | * @param stream 流id |
| | | */ |
| | | @Override |
| | | public String snapOnPlay(ZlmMediaServer mediaServer, String app, String stream) { |
| | | String fileName = app + "-" + stream + ".jpg"; |
| | |
| | | log.info("[getSnap] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType()); |
| | | throw new RuntimeException("[getSnap] 失败, mediaServer的类型: " + mediaServer.getType() + ",未找到对应的实现类"); |
| | | } |
| | | String filePath = fileDomain + filePrefix + "/snap/" + fileName; |
| | | mediaNodeServerService.getSnap(mediaServer, app, stream, 30, 300, this.filePath + "/snap", fileName); |
| | | return filePath; |
| | | } |
| | | |
| | | // 生成临时文件路径(用于 FFmpeg 截图) |
| | | String tempDir = System.getProperty("java.io.tmpdir") + "/snap_temp/"; |
| | | File tempDirFile = new File(tempDir); |
| | | if (!tempDirFile.exists()) { |
| | | tempDirFile.mkdirs(); |
| | | } |
| | | String tempFilePath = tempDir + fileName; |
| | | |
| | | try { |
| | | // 1. 获取截图到临时文件 |
| | | mediaNodeServerService.getSnap(mediaServer, app, stream, 30, 300, tempDir, fileName); |
| | | // 2. 检查临时文件是否存在 |
| | | File tempFile = new File(tempFilePath); |
| | | if (!tempFile.exists()) { |
| | | log.error("[截图失败] 临时文件不存在: {}", tempFilePath); |
| | | return null; |
| | | } |
| | | |
| | | // 3. 使用 FileMultipartFile 转换为 MultipartFile |
| | | MultipartFile multipartFile = new FileMultipartFile( |
| | | tempFile, |
| | | fileName, |
| | | "image/jpeg" |
| | | ); |
| | | |
| | | // 3. 调用文件上传接口,上传到 MinIO(bucketName 可以固定为 "snap" 或动态传入) |
| | | R<SysFile> result = remoteFileService.upload(multipartFile, "snap"); |
| | | |
| | | // 4. 清理临时文件 |
| | | Files.deleteIfExists(Paths.get(tempFilePath)); |
| | | |
| | | // 5. 返回 URL |
| | | if (result.getCode() == Constants.SUCCESS && result.getData() != null) { |
| | | String url = result.getData().getUrl(); |
| | | log.info("[截图上传成功] URL: {}", url); |
| | | return url; |
| | | } else { |
| | | log.error("[截图上传失败] {}", result.getMsg()); |
| | | return null; |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error("[截图失败] ", e); |
| | | return null; |
| | | } |
| | | } |
| | | /** |
| | | * 获取截图 |
| | | * |