| | |
| | | package cn.iocoder.yudao.module.digitalcourse.service.digitalhumans; |
| | | |
| | | import cn.hutool.http.HttpException; |
| | | import cn.hutool.http.HttpRequest; |
| | | import cn.hutool.http.HttpResponse; |
| | | import cn.iocoder.yudao.module.digitalcourse.controller.admin.digitalhumans.vo.DigitalHumansTrailVO; |
| | |
| | | public class DigitalHumansServiceUtil { |
| | | |
| | | private static final String HEYGEM_CORE_URL = "heygem.core.url"; |
| | | private static final String VIDEO2MOV = "video2mov"; |
| | | private static final String VIDEO2MOV_URL = "video2mov.url"; |
| | | private static final String HEYGEM_VOICE_DATA = "heygem.voice.data"; |
| | | private static final String HEYGEM_FACE2FACE = "heygem.face2face"; |
| | | private static final String EASEGEN_URL = "easegen.url"; |
| | |
| | | private FileApi fileApi; |
| | | |
| | | public void remoteHeyGemMatting(DigitalHumansTrailVO digitalHumansTrailVO) { |
| | | System.out.println(digitalHumansTrailVO); |
| | | String video2movUrl = configApi.getConfigValueByKey(VIDEO2MOV); |
| | | String extname = digitalHumansTrailVO.getVideoUrl().substring(digitalHumansTrailVO.getVideoUrl().lastIndexOf(".")); |
| | | String modelFileName = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) + extname; |
| | | String modelFilePath = Paths.get(video2movUrl, modelFileName).toString(); |
| | | |
| | | String substring = configApi.getConfigValueByKey(EASEGEN_URL) + digitalHumansTrailVO.getVideoUrl().substring(digitalHumansTrailVO.getVideoUrl().lastIndexOf("/")); |
| | | |
| | | try { |
| | | Files.copy(Path.of(substring), Path.of(modelFilePath), StandardCopyOption.REPLACE_EXISTING); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | //modelFileName |
| | | try { |
| | | // 发送POST请求 |
| | | HttpResponse execute = HttpRequest.get(configApi.getConfigValueByKey(VIDEO2MOV_URL) + "?file=" + modelFileName).execute(); |
| | | String body = execute.body(); |
| | | // 检查响应状态码是否成功 |
| | | if (execute.getStatus() != 200) { |
| | | digitalHumansMapper.update(new UpdateWrapper<DigitalHumansDO>().lambda().eq(DigitalHumansDO::getCode, digitalHumansTrailVO.getCode()).set(DigitalHumansDO::getStatus, 7)); |
| | | return; |
| | | } |
| | | // 解析响应,检查是否有错误信息 |
| | | JSONObject responseJson = JSON.parseObject(body); |
| | | String final_video_path = responseJson.getString("final_video_path"); |
| | | byte[] content = Files.readAllBytes(Paths.get(final_video_path)); |
| | | String fileUrl = fileApi.createFile(content); |
| | | digitalHumansMapper.update( |
| | | new UpdateWrapper<DigitalHumansDO>() |
| | | .lambda() |
| | | .eq(DigitalHumansDO::getCode, digitalHumansTrailVO.getCode()) // 条件:code 等于传入的值 |
| | | .set(DigitalHumansDO::getFixVideoUrl, fileUrl) |
| | | .set(DigitalHumansDO::getStatus,2) |
| | | ); |
| | | System.out.println(responseJson); |
| | | // 处理业务逻辑错误,更新状态和错误信息 |
| | | } catch (HttpException e) { |
| | | throw new RuntimeException(e); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | @Async |
| | | public void remoteHeyGemTrain(DigitalHumansTrailVO digitalHumansTrailVo){ |
| | |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | //todo 视频抠图 |
| | | String extname = digitalHumansTrailVo.getVideoUrl().substring(digitalHumansTrailVo.getVideoUrl().lastIndexOf(".")); |
| | | String extname = digitalHumansTrailVo.getFixVideoUrl().substring(digitalHumansTrailVo.getFixVideoUrl().lastIndexOf(".")); |
| | | String modelFileName = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) + extname; |
| | | String modelFilePath = Paths.get(temp, modelFileName).toString(); |
| | | |
| | | String substring = configApi.getConfigValueByKey(EASEGEN_URL)+digitalHumansTrailVo.getVideoUrl().substring(digitalHumansTrailVo.getVideoUrl().lastIndexOf("/")); |
| | | String substring = configApi.getConfigValueByKey(EASEGEN_URL)+digitalHumansTrailVo.getFixVideoUrl().substring(digitalHumansTrailVo.getFixVideoUrl().lastIndexOf("/")); |
| | | |
| | | try { |
| | | Files.copy(Path.of(substring), Path.of(modelFilePath), StandardCopyOption.REPLACE_EXISTING); |