| @@ -154,7 +154,7 @@ public class VideoController extends BaseController { | |||
| @ApiImplicitParam(name = "videoId", value = "视频编号", dataType = "String", paramType = "query", required = true)}) | |||
| public ResultData videoDetial(String videoId) { | |||
| try { | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(videoId); | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(videoId,true); | |||
| return new ResultData(videoDetail); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| @@ -272,7 +272,7 @@ public class PhotoSpeakVideoController extends BaseController { | |||
| @ApiImplicitParam(name = "videoId", value = "视频编号", dataType = "String", paramType = "query", required = true)}) | |||
| public ResultData videoDetial(String videoId) { | |||
| try { | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(videoId); | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(videoId,true); | |||
| return new ResultData(videoDetail); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| @@ -424,6 +424,7 @@ public class PhotoSpeakVideoController extends BaseController { | |||
| return new ResultData(); | |||
| } | |||
| @AuthIgnore | |||
| @ApiOperation("视频超分") | |||
| @GetMapping("/videoHy") | |||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||
| @@ -439,26 +440,22 @@ public class PhotoSpeakVideoController extends BaseController { | |||
| if (StringUtils.isEmpty(speakVideo.getSaveDir())){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"save_dir为空"); | |||
| } | |||
| if(!speakVideo.getUserId().equals(getMemberId())){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未找到用户数据"); | |||
| } | |||
| if(!EnumVideoStatus.upload_success.getCode().equals(speakVideo.getVideoStatus())){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"原始视频生成未完成"); | |||
| } | |||
| // if(!speakVideo.getUserId().equals(getMemberId())){ | |||
| // return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未找到用户数据"); | |||
| // } | |||
| if(EnumVideoStatus.ing.getCode().equals(speakVideo.getVideoHyStatus()) | |||
| || EnumVideoStatus.success.getCode().equals(speakVideo.getVideoHyStatus()) | |||
| || EnumVideoStatus.upload_ing.getCode().equals(speakVideo.getVideoHyStatus()) | |||
| || EnumVideoStatus.upload_fail.getCode().equals(speakVideo.getVideoHyStatus())){ | |||
| if(EnumVideoStatus.hy_ing.getCode().equals(speakVideo.getVideoStatus()) | |||
| || EnumVideoStatus.hy_success.getCode().equals(speakVideo.getVideoStatus()) | |||
| || EnumVideoStatus.hy_upload_ing.getCode().equals(speakVideo.getVideoStatus()) | |||
| || EnumVideoStatus.hy_upload_fail.getCode().equals(speakVideo.getVideoStatus())){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"高清晰度视频生成中"); | |||
| } | |||
| if(EnumVideoStatus.upload_success.getCode().equals(speakVideo.getVideoHyStatus())){ | |||
| if(EnumVideoStatus.hy_upload_success.getCode().equals(speakVideo.getVideoStatus())){ | |||
| //上传阿里云状态 生成成功 | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"高清晰度视频已生成完成"); | |||
| } | |||
| speakVideo.setVideoHyStatus(EnumVideoStatus.ing.getCode()); | |||
| speakVideo.setVideoStatus(EnumVideoStatus.hy_ing.getCode()); | |||
| speakVideo.setVideoMsg(""); | |||
| speakVideo.setIsHy(EnumYesOrNo.YES.getCode()); | |||
| speakVideo.setUpdateDate(new Date()); | |||
| @@ -471,7 +468,7 @@ public class PhotoSpeakVideoController extends BaseController { | |||
| @ApiOperation("获取视频是否生成成功") | |||
| @GetMapping("/checkVideoStatus") | |||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||
| public ResultData checkVideoStatus(@RequestParam("list") List<Long> list,@RequestParam("type") Integer type) { | |||
| return photoSpeakVideoService.checkVideoStatus(getMemberId(),list,type); | |||
| public ResultData checkVideoStatus(@RequestParam("list") List<Long> list) { | |||
| return photoSpeakVideoService.checkVideoStatus(getMemberId(),list); | |||
| } | |||
| } | |||
| @@ -204,7 +204,7 @@ public class UserMouldVideoController extends BaseController { | |||
| @ApiImplicitParam(name = "videoId", value = "视频编号", dataType = "String", paramType = "query", required = true)}) | |||
| public ResultData videoDetial(String videoId) { | |||
| try { | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(videoId); | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(videoId,true); | |||
| return new ResultData(videoDetail); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| @@ -85,7 +85,7 @@ public class VideoCallbackController extends BaseController { | |||
| if (Integer.parseInt(code) != 4000){ | |||
| String returnMsg; | |||
| if (sr){ | |||
| photoSpeakVideo.setVideoHyStatus(EnumVideoStatus.fail.getCode()); | |||
| photoSpeakVideo.setVideoStatus(EnumVideoStatus.hy_fail.getCode()); | |||
| returnMsg = "超分视频生成失败"; | |||
| }else { | |||
| photoSpeakVideo.setVideoStatus(EnumVideoStatus.fail.getCode()); | |||
| @@ -106,9 +106,11 @@ public class VideoCallbackController extends BaseController { | |||
| } | |||
| if (sr){ | |||
| photoSpeakVideo.setVideoHyStatus(EnumVideoStatus.success.getCode()); | |||
| photoSpeakVideo.setVideoStatus(EnumVideoStatus.hy_success.getCode()); | |||
| photoSpeakVideo.setVideoPath(url); | |||
| }else { | |||
| photoSpeakVideo.setVideoStatus(EnumVideoStatus.success.getCode()); | |||
| photoSpeakVideo.setVideoPath(url); | |||
| } | |||
| photoSpeakVideo.setVideoMsg("success"); | |||
| photoSpeakVideo.setUpdateDate(new Date()); | |||
| @@ -111,7 +111,7 @@ public class VideoController extends BaseController { | |||
| @ApiImplicitParam(name = "videoId", value = "视频编号", dataType = "String", paramType = "query", required = true)}) | |||
| public ResultData videoDetial(String videoId) { | |||
| try { | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(videoId); | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(videoId,true); | |||
| return new ResultData(videoDetail); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| @@ -4,8 +4,6 @@ import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.sm.AiBaiduCheckResult; | |||
| import okhttp3.*; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| import java.io.*; | |||
| @@ -14,6 +12,8 @@ import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.net.URL; | |||
| import java.net.URLConnection; | |||
| import java.util.Date; | |||
| import java.util.HashMap; | |||
| /** | |||
| * 图片质量检查方法 | |||
| @@ -24,13 +24,12 @@ public class BaiduImageCheckUtil { | |||
| // 获取token | |||
| private final static String auth_url = "https://aip.baidubce.com/oauth/2.0/token?"; | |||
| // 百度API Key | |||
| private final static String apiKey = "Your API Key"; | |||
| private final static String apiKey = "qnx99HW0HY9xoOEEVRuvtnQ4"; | |||
| // 百度Secret Key | |||
| private final static String secretKey = "Your Secret Key"; | |||
| private final static String secretKey = "RY5YCqGejrc32xT5kIxDj0mqP9QRiKfD"; | |||
| //写死的 access_token | |||
| private final static String access_token = "24.c1c7992795301773c60c8cf01abfe759.2592000.1689236723.282335-33618414"; | |||
| public static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build(); | |||
| private final static String access_token = "24.ba201483ba860779dcb402cc044a3bd4.2592000.1691298224.282335-35825024"; //7.7 | |||
| public static ResultData photoCheck(MultipartFile file) { | |||
| try { | |||
| @@ -40,9 +39,10 @@ public class BaiduImageCheckUtil { | |||
| String param = "image=" + imageUrl; | |||
| // 注意这里access_token有过期时间, 客户端可自行缓存,过期后重新获取。 | |||
| // Access Token的有效期(秒为单位,有效期30天) | |||
| // String accessToken = getAuth(); | |||
| String accessToken = getAuth(); | |||
| //这里暂时写死 | |||
| String result = BaiDuHttpUtil.post(photo_check_url, access_token, param); | |||
| String result = BaiDuHttpUtil.post(photo_check_url, accessToken, param); | |||
| System.out.println(result); | |||
| JSONObject jsonObject = JSON.parseObject(result); | |||
| //1:合规,2:不合规,3:疑似,4:审核失败 | |||
| @@ -98,17 +98,37 @@ public class BaiduImageCheckUtil { | |||
| * 获取API访问权限token,该token有一定的有效期,需要自行管理,当失效时需重新获取。 | |||
| * Access Token的有效期(秒为单位,有效期30天) | |||
| */ | |||
| public static String getAuth() throws IOException { | |||
| MediaType mediaType = MediaType.parse("application/json"); | |||
| RequestBody body = RequestBody.create(mediaType, ""); | |||
| Request request = new Request.Builder() | |||
| .url(auth_url + "client_id=" + apiKey + "&client_secret= " + secretKey + "&grant_type=client_credentials") | |||
| .method("POST", body) | |||
| .addHeader("Content-Type", "application/json") | |||
| .addHeader("Accept", "application/json") | |||
| .build(); | |||
| Response response = HTTP_CLIENT.newCall(request).execute(); | |||
| System.out.println(response.body().string()); | |||
| return response.body().string(); | |||
| public static String getAuth() { | |||
| HashMap<String, String> map = new HashMap<>(); | |||
| map.put("client_id", apiKey); | |||
| map.put("client_secret", secretKey); | |||
| map.put("grant_type", "client_credentials"); | |||
| String doPost = HttpUtil.doPost(auth_url, map); | |||
| JSONObject json = JSONObject.parseObject(doPost); | |||
| String access_token = (String) json.get("access_token"); | |||
| Integer expires_in = (Integer) json.get("expires_in"); | |||
| String checkExpires = checkExpires(expires_in); | |||
| if (checkExpires == null){ | |||
| return access_token; | |||
| } | |||
| return doPost; | |||
| } | |||
| private static String checkExpires(Integer expiresIn) { | |||
| int days = expiresIn / 60 / 60 / 24; | |||
| Date timeAfterDays = DateUtils.getTimeAfterDays(days, new Date()); | |||
| if (timeAfterDays.before(new Date())){ | |||
| String doPost = getAuth(); | |||
| JSONObject json = JSONObject.parseObject(doPost); | |||
| String access_token = (String) json.get("access_token"); | |||
| Integer expires_in = (Integer) json.get("expires_in"); | |||
| return access_token; | |||
| } | |||
| return null; | |||
| } | |||
| public static void main(String[] args) { | |||
| System.out.println(getAuth()); | |||
| } | |||
| } | |||
| @@ -189,7 +189,7 @@ logging: | |||
| path: ./logs/c | |||
| photo: | |||
| url: http://nas.pucao.cn:2002 | |||
| hy_url: http://nas.pucao.cn:2002 | |||
| url: http://111.198.0.15:22299 | |||
| hy_url: http://111.198.0.15:22288 | |||
| talk: | |||
| callbackUrl: https://phototest.metavatar.cc/C | |||
| @@ -50,6 +50,7 @@ public class PhotoSpeakSchedule { | |||
| */ | |||
| @Scheduled(cron = "0 20/30 * * * *?") // 每半小时检查一次 | |||
| public void photoSpeakCreateSchedule() { | |||
| logger.info("photoSpeakCreateSchedule :: start"); | |||
| PhotoSpeakVideo videoUpd = new PhotoSpeakVideo(); | |||
| videoUpd.setVideoStartDate(DateUtils.getHourDateBefore(2,new Date())); | |||
| videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode()); | |||
| @@ -70,6 +71,7 @@ public class PhotoSpeakSchedule { | |||
| */ | |||
| @Scheduled(cron = "0 */30 * * * *?") // 每半小时检查一次 | |||
| public void userVideoUploadSchedule() { | |||
| logger.info("userVideoUploadSchedule :: start"); | |||
| List<PhotoSpeakVideo> videos = photoSpeakVideoService.getNotUploadList(); | |||
| if (videos != null && videos.size() > 0) { | |||
| for (PhotoSpeakVideo video : videos) { | |||
| @@ -87,11 +89,13 @@ public class PhotoSpeakSchedule { | |||
| */ | |||
| @Scheduled(cron = "0 1/5 * * * *?") // 每五分钟检查一次 | |||
| public void userVideoDetailSchedule() { | |||
| List<PhotoSpeakVideo> videos = photoSpeakVideoService.getUpLoadIngList(); | |||
| logger.info("userVideoDetailSchedule :: start"); | |||
| List<PhotoSpeakVideo> videos = photoSpeakVideoService.getNotHaveUrl(); | |||
| if (videos != null && videos.size() > 0) { | |||
| for (PhotoSpeakVideo video : videos) { | |||
| try { | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(video.getVideoId()); | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(video.getVideoId(),false); | |||
| logger.info("userVideoDetailSchedule" + videoDetail); | |||
| if (videoDetail.isSuccess() | |||
| && StringUtils.isNotBlank(videoDetail.getDuration()) | |||
| && !"0.0".equals(videoDetail.getDuration())) { | |||
| @@ -99,7 +103,11 @@ public class PhotoSpeakSchedule { | |||
| video.setVideoPlayUrl(videoDetail.getVideoUrl()); | |||
| video.setVideoTime(videoDetail.getDuration()); | |||
| video.setVideoSize(videoDetail.getSize()); | |||
| video.setVideoStatus(EnumVideoStatus.upload_success.getCode()); | |||
| if (video.getVideoStatus() <= 5){ | |||
| video.setVideoStatus(EnumVideoStatus.upload_success.getCode()); | |||
| }else { | |||
| video.setVideoStatus(EnumVideoStatus.hy_upload_success.getCode()); | |||
| } | |||
| photoSpeakVideoService.updateById(video); | |||
| } | |||
| } catch (Exception e) { | |||
| @@ -112,7 +120,7 @@ public class PhotoSpeakSchedule { | |||
| /** | |||
| * 超分上传阿里云 | |||
| */ | |||
| @Scheduled(cron = "0 */30 * * * *?") // 每半小时检查一次 | |||
| // @Scheduled(cron = "0 */30 * * * *?") // 每半小时检查一次 | |||
| public void userVideoHyUploadSchedule() { | |||
| List<PhotoSpeakVideo> videos = photoSpeakVideoService.getNotHyUploadList(); | |||
| if (videos != null && videos.size() > 0) { | |||
| @@ -129,13 +137,13 @@ public class PhotoSpeakSchedule { | |||
| /** | |||
| * 获取超分时长和大小 | |||
| */ | |||
| @Scheduled(cron = "0 1/5 * * * *?") // 每五分钟检查一次 | |||
| // @Scheduled(cron = "0 1/5 * * * *?") // 每五分钟检查一次 | |||
| public void userVideoHyDetailSchedule() { | |||
| List<PhotoSpeakVideo> videos = photoSpeakVideoService.getUpLoadHyIngList(); | |||
| if (videos != null && videos.size() > 0) { | |||
| for (PhotoSpeakVideo video : videos) { | |||
| try { | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(video.getVideoId()); | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(video.getVideoId(),false); | |||
| if (videoDetail.isSuccess() | |||
| && StringUtils.isNotBlank(videoDetail.getDuration()) | |||
| && !"0.0".equals(videoDetail.getDuration())) { | |||
| @@ -143,7 +151,7 @@ public class PhotoSpeakSchedule { | |||
| video.setVideoPlayUrl(videoDetail.getVideoUrl()); | |||
| video.setVideoTime(videoDetail.getDuration()); | |||
| video.setVideoSize(videoDetail.getSize()); | |||
| video.setVideoHyStatus(EnumVideoStatus.upload_success.getCode()); | |||
| video.setVideoStatus(EnumVideoStatus.hy_upload_success.getCode()); | |||
| photoSpeakVideoService.updateById(video); | |||
| } | |||
| } catch (Exception e) { | |||
| @@ -158,9 +166,10 @@ public class PhotoSpeakSchedule { | |||
| */ | |||
| @Scheduled(cron = "0 20/30 * * * *?") // 每半小时检查一次 | |||
| public void photoSpeakCreateHySchedule() { | |||
| logger.info("photoSpeakCreateHySchedule :: start"); | |||
| PhotoSpeakVideo videoUpd = new PhotoSpeakVideo(); | |||
| videoUpd.setVideoStartDate(DateUtils.getHourDateBefore(2,new Date())); | |||
| videoUpd.setVideoHyStatus(EnumVideoStatus.fail.getCode()); | |||
| videoUpd.setVideoStatus(EnumVideoStatus.hy_fail.getCode()); | |||
| List<PhotoSpeakVideo> list = photoSpeakVideoService.findList(videoUpd); | |||
| if (list != null && list.size() > 0) { | |||
| for (PhotoSpeakVideo video : list) { | |||
| @@ -87,7 +87,7 @@ public class VideoSchedule { | |||
| if (videos != null && videos.size() > 0) { | |||
| for (UserMouldVideo video : videos) { | |||
| try { | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(video.getVideoId()); | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(video.getVideoId(),false); | |||
| if (videoDetail.isSuccess() | |||
| && StringUtils.isNotBlank(videoDetail.getDuration()) | |||
| && !"0.0".equals(videoDetail.getDuration())) { | |||
| @@ -192,7 +192,7 @@ logging: | |||
| path: ./logs/s | |||
| photo: | |||
| url: http://nas.pucao.cn:2002 | |||
| hy_url: http://nas.pucao.cn:2002 | |||
| url: http://111.198.0.15:22299 | |||
| hy_url: http://111.198.0.15:22288 | |||
| talk: | |||
| callbackUrl: https://phototest.metavatar.cc/C | |||
| @@ -7,4 +7,5 @@ import lombok.Data; | |||
| public class VoiceInfoVo { | |||
| private String url; | |||
| private String name; | |||
| private String EngName; | |||
| } | |||
| @@ -15,7 +15,15 @@ public enum EnumVideoStatus { | |||
| fail(3, "生成视频失败"), | |||
| upload_ing(4,"上传视频中"), | |||
| upload_success(5,"上传视频成功"), | |||
| upload_fail(6,"上传视频失败") | |||
| upload_fail(6,"上传视频失败"), | |||
| // 超分视频状态 | |||
| hy_ing(7, "超分视频生成中"), | |||
| hy_success(8,"超分视频生成成功"), | |||
| hy_fail(9, "超分视频生成失败"), | |||
| hy_upload_ing(10,"超分视频上传中"), | |||
| hy_upload_success(11,"超分视频上传成功"), | |||
| hy_upload_fail(12,"超分视频上传失败"), | |||
| ; | |||
| public static EnumVideoStatus getEnum(Integer code) { | |||
| @@ -23,5 +23,7 @@ public interface PhotoSpeakVideoMapper extends CommonMapper<PhotoSpeakVideo, Lon | |||
| List<PhotoSpeakVideo> getSortList(PhotoSpeakVideo record); | |||
| Integer checkVideoStatus(@Param("userId") Long userId, @Param("list") List<Long> list,@Param("type") Integer type); | |||
| Integer checkVideoStatus(@Param("userId") Long userId, @Param("list") List<Long> list); | |||
| List<PhotoSpeakVideo> getNotHaveUrl(PhotoSpeakVideo umVideoQ); | |||
| } | |||
| @@ -65,5 +65,7 @@ public interface PhotoSpeakVideoService { | |||
| List<PhotoSpeakVideo> getNotHyUploadList(); | |||
| ResultData checkVideoStatus(Long userId, List<Long> time, Integer type); | |||
| ResultData checkVideoStatus(Long userId, List<Long> time); | |||
| List<PhotoSpeakVideo> getNotHaveUrl(); | |||
| } | |||
| @@ -46,7 +46,7 @@ public class MusicInfoServiceImpl implements MusicInfoService { | |||
| @Override | |||
| public ResultData saveOrUpdate(MusicInfo record) { | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(record.getVoiceId()); | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(record.getVoiceId(),true); | |||
| if (videoDetail.isSuccess() | |||
| && StringUtils.isNotBlank(videoDetail.getDuration()) | |||
| && !"0.0".equals(videoDetail.getDuration()) | |||
| @@ -288,7 +288,7 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { | |||
| String progress = videoFactory.getExcutor(videoType).getVedioUploadProgress(result.getVideoId()); | |||
| Thread.sleep(1000); | |||
| if (StringUtils.isNotEmpty(progress) && progress.equals("complete")) { | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(result.getVideoId()); | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(result.getVideoId(),true); | |||
| if (videoDetail.isSuccess() | |||
| && StringUtils.isNotBlank(videoDetail.getDuration()) | |||
| && !"0.0".equals(videoDetail.getDuration())) { | |||
| @@ -330,6 +330,8 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { | |||
| List<Integer> videoStatuss = new ArrayList<>(); | |||
| videoStatuss.add(EnumVideoStatus.success.getCode()); | |||
| videoStatuss.add(EnumVideoStatus.upload_fail.getCode()); | |||
| videoStatuss.add(EnumVideoStatus.hy_success.getCode()); | |||
| videoStatuss.add(EnumVideoStatus.hy_upload_fail.getCode()); | |||
| umVideoQ.setVideoStatuss(videoStatuss); | |||
| return photoSpeakVideoMapper.getSortList(umVideoQ); | |||
| } | |||
| @@ -365,44 +367,47 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { | |||
| try { | |||
| AiVideoHqResult result = AiVideoHelper.videoHq(param); | |||
| if (result.isSuccess()) { | |||
| speakVideo.setVideoHyStatus(EnumVideoStatus.success.getCode()); | |||
| speakVideo.setVideoStatus(EnumVideoStatus.hy_success.getCode()); | |||
| speakVideo.setVideoMsg("超分视频生成成功"); | |||
| speakVideo.setVideoPath(result.getUrl()); | |||
| this.updateById(speakVideo); | |||
| return new ResultData(); | |||
| } | |||
| speakVideo.setVideoHyStatus(EnumVideoStatus.draft.getCode()); | |||
| speakVideo.setVideoStatus(EnumVideoStatus.hy_fail.getCode()); | |||
| speakVideo.setVideoMsg("Mata视频超分失败"); | |||
| speakVideo.setIsHy(EnumYesOrNo.NO.getCode()); | |||
| this.updateById(speakVideo); | |||
| return new ResultData(result.getCode(), result.getMsgInfo(result.getCode(),result.getMsg())); | |||
| }catch (Exception e){ | |||
| e.printStackTrace(); | |||
| speakVideo.setVideoHyStatus(EnumVideoStatus.draft.getCode()); | |||
| speakVideo.setVideoStatus(EnumVideoStatus.hy_fail.getCode()); | |||
| speakVideo.setVideoMsg("Mata视频超分失败"); | |||
| speakVideo.setIsHy(EnumYesOrNo.NO.getCode()); | |||
| this.updateById(speakVideo); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"Meta接口请求异常"); | |||
| } | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| speakVideo.setVideoHyStatus(EnumVideoStatus.draft.getCode()); | |||
| speakVideo.setVideoMsg("接口请求异常"); | |||
| speakVideo.setVideoStatus(EnumVideoStatus.hy_fail.getCode()); | |||
| speakVideo.setVideoMsg("超分视频接口请求异常"); | |||
| speakVideo.setIsHy(EnumYesOrNo.NO.getCode()); | |||
| this.updateById(speakVideo); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "接口请求异常"); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "超分视频接口请求异常"); | |||
| } | |||
| } | |||
| @Async | |||
| @Override | |||
| public void uploadHyVideo(PhotoSpeakVideo mouldVideo){ | |||
| if(EnumVideoStatus.success.getCode().equals(mouldVideo.getVideoHyStatus()) | |||
| || EnumVideoStatus.upload_fail.getCode().equals(mouldVideo.getVideoHyStatus())){ | |||
| if(EnumVideoStatus.hy_success.getCode().equals(mouldVideo.getVideoStatus()) | |||
| || EnumVideoStatus.hy_upload_fail.getCode().equals(mouldVideo.getVideoStatus())){ | |||
| String url = hy_url + mouldVideo.getVideoPath(); | |||
| VideUploadResult result = videoFactory.getExcutor(videoType).uploadVideoPath(mouldVideo.getTitle(), url); | |||
| if(result.isSuccess()){ | |||
| PhotoSpeakVideo videoUpd = new PhotoSpeakVideo(); | |||
| videoUpd.setId(mouldVideo.getId()); | |||
| videoUpd.setVideoId(result.getVideoId()); | |||
| videoUpd.setVideoHyStatus(EnumVideoStatus.upload_ing.getCode()); | |||
| videoUpd.setVideoStatus(EnumVideoStatus.hy_upload_ing.getCode()); | |||
| this.saveOrUpdate(videoUpd); | |||
| AtomicInteger integer = new AtomicInteger(30); | |||
| @@ -411,7 +416,7 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { | |||
| String progress = videoFactory.getExcutor(videoType).getVedioUploadProgress(result.getVideoId()); | |||
| Thread.sleep(1000); | |||
| if (progress.equals("complete")) { | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(result.getVideoId()); | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(result.getVideoId(),true); | |||
| if (videoDetail.isSuccess() | |||
| && StringUtils.isNotBlank(videoDetail.getDuration()) | |||
| && !"0.0".equals(videoDetail.getDuration())) { | |||
| @@ -419,22 +424,23 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { | |||
| mouldVideo.setVideoPlayUrl(videoDetail.getVideoUrl()); | |||
| mouldVideo.setVideoTime(videoDetail.getDuration()); | |||
| mouldVideo.setVideoSize(videoDetail.getSize()); | |||
| mouldVideo.setIsHy(2);//超分视频生成成功了状态为2 | |||
| mouldVideo.setVideoHyStatus(EnumVideoStatus.upload_success.getCode()); | |||
| mouldVideo.setVideoStatus(EnumVideoStatus.hy_upload_success.getCode()); | |||
| this.updateById(mouldVideo); | |||
| break; | |||
| } | |||
| } | |||
| if (integer.getAndDecrement() <= 0){ | |||
| mouldVideo.setVideoHyStatus(EnumVideoStatus.fail.getCode()); | |||
| mouldVideo.setVideoStatus(EnumVideoStatus.hy_fail.getCode()); | |||
| mouldVideo.setIsHy(EnumYesOrNo.NO.getCode()); | |||
| mouldVideo.setVideoMsg("视频上传失败,点击“编辑”重试"); | |||
| this.updateById(mouldVideo); | |||
| break; | |||
| } | |||
| } catch (InterruptedException e) { | |||
| e.printStackTrace(); | |||
| mouldVideo.setVideoHyStatus(EnumVideoStatus.fail.getCode()); | |||
| mouldVideo.setVideoStatus(EnumVideoStatus.hy_fail.getCode()); | |||
| mouldVideo.setIsHy(EnumYesOrNo.NO.getCode()); | |||
| mouldVideo.setVideoMsg("视频上传失败,点击“编辑”重试"); | |||
| this.updateById(mouldVideo); | |||
| } | |||
| @@ -446,7 +452,7 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { | |||
| @Override | |||
| public List<PhotoSpeakVideo> getUpLoadHyIngList() { | |||
| PhotoSpeakVideo umVideoQ = new PhotoSpeakVideo(); | |||
| umVideoQ.setVideoHyStatus(EnumVideoStatus.upload_ing.getCode()); | |||
| umVideoQ.setVideoStatus(EnumVideoStatus.hy_upload_ing.getCode()); | |||
| return photoSpeakVideoMapper.getSortList(umVideoQ); | |||
| } | |||
| @@ -454,22 +460,30 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { | |||
| public List<PhotoSpeakVideo> getNotHyUploadList() { | |||
| PhotoSpeakVideo umVideoQ = new PhotoSpeakVideo(); | |||
| List<Integer> videoStatuss = new ArrayList<>(); | |||
| videoStatuss.add(EnumVideoStatus.success.getCode()); | |||
| videoStatuss.add(EnumVideoStatus.upload_fail.getCode()); | |||
| videoStatuss.add(EnumVideoStatus.hy_success.getCode()); | |||
| videoStatuss.add(EnumVideoStatus.hy_upload_fail.getCode()); | |||
| umVideoQ.setVideoStatuss(videoStatuss); | |||
| return photoSpeakVideoMapper.getSortList(umVideoQ); | |||
| } | |||
| @Override | |||
| public ResultData checkVideoStatus(Long userId, List<Long> list, Integer type) { | |||
| public List<PhotoSpeakVideo> getNotHaveUrl() { | |||
| PhotoSpeakVideo umVideoQ = new PhotoSpeakVideo(); | |||
| List<Integer> videoStatuss = new ArrayList<>(); | |||
| videoStatuss.add(EnumVideoStatus.hy_upload_ing.getCode()); | |||
| videoStatuss.add(EnumVideoStatus.hy_upload_success.getCode()); | |||
| videoStatuss.add(EnumVideoStatus.upload_ing.getCode()); | |||
| videoStatuss.add(EnumVideoStatus.upload_success.getCode()); | |||
| umVideoQ.setVideoStatuss(videoStatuss); | |||
| return photoSpeakVideoMapper.getNotHaveUrl(umVideoQ); | |||
| } | |||
| @Override | |||
| public ResultData checkVideoStatus(Long userId, List<Long> list) { | |||
| if (CollectionUtils.isEmpty(list)){ | |||
| return new ResultData(ErrorCode.VIDEO_CREATING.getCode(),""); | |||
| } | |||
| if (type == null){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"类型不能为空"); | |||
| } | |||
| Integer integer = photoSpeakVideoMapper.checkVideoStatus(userId,list,type); | |||
| Integer integer = photoSpeakVideoMapper.checkVideoStatus(userId,list); | |||
| if (integer > 0){ | |||
| return new ResultData("生成视频成功"); | |||
| } | |||
| @@ -42,6 +42,7 @@ public class VoiceInfoServiceImpl implements VoiceInfoService { | |||
| strings.forEach(y->{ | |||
| VoiceInfoVo infoVo = new VoiceInfoVo(); | |||
| infoVo.setName(EnumSpeakType.getEnum(y).getMessage()); | |||
| infoVo.setEngName(y); | |||
| infoVo.setUrl(url + x.getMouldSmId() + "_" + y + end); | |||
| list.add(infoVo); | |||
| }); | |||
| @@ -49,12 +50,14 @@ public class VoiceInfoServiceImpl implements VoiceInfoService { | |||
| VoiceInfoVo infoVo = new VoiceInfoVo(); | |||
| infoVo.setName(EnumSpeakType.getEnum(0).getMessage()); | |||
| infoVo.setUrl(url + x.getMouldSmId() + "_" + "default" + end); | |||
| infoVo.setEngName("default"); | |||
| list.add(infoVo); | |||
| x.setStyle(list); | |||
| } else { | |||
| List<VoiceInfoVo> list = Lists.newArrayList(); | |||
| VoiceInfoVo infoVo = new VoiceInfoVo(); | |||
| infoVo.setName(EnumSpeakType.getEnum(0).getMessage()); | |||
| infoVo.setEngName("default"); | |||
| infoVo.setUrl(url + x.getMouldSmId() + "_" + "default" + end); | |||
| list.add(infoVo); | |||
| x.setStyle(list); | |||
| @@ -137,7 +137,7 @@ public class VoiceMaterialServiceImpl implements VoiceMaterialService { | |||
| return; | |||
| } | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(record.getVideoId()); | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(record.getVideoId(),true); | |||
| if (videoDetail.isSuccess()) { | |||
| record.setMaterial(videoDetail.getVideoUrl()); | |||
| if(record.getId() != null){ | |||
| @@ -21,6 +21,8 @@ public class AiPhotoSpeakResult { | |||
| return "(MetaService)没有检测到文本"; | |||
| } else if (code == 3008 && msg.equals("check languages")) { | |||
| return "(MetaService)文字和语种不对应"; | |||
| } else if (code == 4001 && msg.equals("long audio")) { | |||
| return "(MetaService)视频时长大于一分钟"; | |||
| } else { | |||
| return "(MetaService:" + msg + ")服务被Avatar攻击..."; | |||
| } | |||
| @@ -20,6 +20,7 @@ import lombok.extern.slf4j.Slf4j; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.beans.factory.annotation.Value; | |||
| import org.springframework.stereotype.Component; | |||
| import sun.net.www.content.audio.wav; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.security.MessageDigest; | |||
| @@ -49,15 +50,13 @@ public class AiVideoHelper { | |||
| } | |||
| private static String hy_url; | |||
| @Value("${photo.hy_url}") | |||
| public void setHyUrl(String url){ | |||
| this.hy_url = url; | |||
| public void setHyUrl(String hyUrl){ | |||
| this.hy_url = hyUrl; | |||
| } | |||
| private static String talk_url; | |||
| @Value("${photo.talk}") | |||
| public void setTalkUrl(String url){ | |||
| this.talk_url = url; | |||
| public void setTalkUrl(String talkUrl){ | |||
| this.talk_url = talkUrl; | |||
| } | |||
| public static String photo_speak_suffix = "/img_talking"; | |||
| public static String image_quality_suffix = "/image_qualit"; | |||
| @@ -129,9 +128,9 @@ public class AiVideoHelper { | |||
| // } | |||
| } | |||
| public static AiPhotoSpeakResult createPhotoSpeakVideo(AiPhotoSpeakParam videoParam) { | |||
| String response = doPost(url + photo_speak_suffix, JSONObject.toJSONString(videoParam)); | |||
| String response = doPost("http://111.198.0.15:22299" + photo_speak_suffix, JSONObject.toJSONString(videoParam)); | |||
| log.info("生成视频end response:" + response); | |||
| log.info("生成视频的 IP:" + url + photo_speak_suffix); | |||
| log.info("生成视频的 IP:" + "http://111.198.0.15:22299" + photo_speak_suffix); | |||
| AiPhotoSpeakResult result = new AiPhotoSpeakResult(); | |||
| if (StringUtils.isBlank(response)) { | |||
| result.setSuccess(false); | |||
| @@ -274,7 +273,7 @@ public class AiVideoHelper { | |||
| result.setMsg("(MetaService)视频超分异常,请稍后重试"); | |||
| return result; | |||
| } | |||
| if (code.intValue() == 3000) { | |||
| if (code.intValue() == 5000) { | |||
| result.setCode(200); | |||
| result.setSuccess(true); | |||
| result.setUrl(url + strURL); | |||
| @@ -312,24 +311,26 @@ public class AiVideoHelper { | |||
| // | |||
| // AiPhotoSpeakParam param = new AiPhotoSpeakParam(); | |||
| // param.setGen_txt("人多泰达股份冲冠怒发代发"); | |||
| // param.setImg(Base64Util.imageUrlToBase64("https://suimang.oss-accelerate.aliyuncs.com/builtin/personphoto/16564099737021232.png")); | |||
| // param.setGender("male"); | |||
| // param.setVoice_id("yue-CN-YunSongNeural"); | |||
| // param.setGen_txt("道可道,非常道。名可名,非常名。无名天地之始;有名万物之母。故常无欲,以观其妙;常有欲,以观其徼。此两者,同出而异名,同谓之玄。玄之又玄,众妙之门"); | |||
| // param.setImg(Base64Util.imageUrlToBase64("https://suimang.oss-accelerate.aliyuncs.com/builtin/personphoto/165640997370212321.png")); | |||
| // param.setGender("female"); | |||
| // param.setVoice_id("zh-CN-XiaoqiuNeural"); | |||
| // param.setCallback_url("https://phototest.metavatar.cc/C/callback/photo/speak"); | |||
| // param.setTask_id(837169827124269056L); | |||
| // param.setVoice_style("default"); | |||
| // param.setUrl("None"); | |||
| // AiPhotoSpeakResult video = AiVideoHelper.createPhotoSpeakVideo(param); | |||
| AiPhotoSpeakParam param = new AiPhotoSpeakParam(); | |||
| param.setCallback_url("https://phototest.metavatar.cc/C/callback/photo/speak"); | |||
| param.setTask_id(836805079248850944L); | |||
| param.setGen_txt("None"); | |||
| param.setImg(Base64Util.imageUrlToBase64("https://suimang.oss-accelerate.aliyuncs.com/capi/2023-06-07/6da595fe12ef405bb6434f31e6bad4ec.png")); | |||
| param.setGender("None"); | |||
| param.setVoice_id("default"); | |||
| param.setVoice_style("default"); | |||
| param.setUrl("https://video.metavatar.cc/sv/262b03bd-18929af12fd/262b03bd-18929af12fd.mp3"); | |||
| AiPhotoSpeakResult video = AiVideoHelper.createPhotoSpeakVideo(param); | |||
| // AiPhotoSpeakParam param = new AiPhotoSpeakParam(); | |||
| // param.setCallback_url("https://phototest.metavatar.cc/C/callback/photo/speak"); | |||
| // param.setTask_id(836805079248850944L); | |||
| // param.setGen_txt("None"); | |||
| // param.setImg(Base64Util.imageUrlToBase64("https://suimang.oss-accelerate.aliyuncs.com/capi/2023-06-07/6da595fe12ef405bb6434f31e6bad4ec.png")); | |||
| // param.setGender("None"); | |||
| // param.setVoice_id("default"); | |||
| // param.setVoice_style("default"); | |||
| // param.setUrl("https://video.metavatar.cc/sv/262b03bd-18929af12fd/262b03bd-18929af12fd.mp3"); | |||
| // AiPhotoSpeakResult video = AiVideoHelper.createPhotoSpeakVideo(param); | |||
| // AiCheckPhotoParam param = new AiCheckPhotoParam(); | |||
| // String img = Base64Util.imageUrlToBase64("https://suimang.oss-accelerate.aliyuncs.com/builtin/personmould/16760216806604820_cSHoijDX_grace_1080.jpg"); | |||
| @@ -345,11 +346,13 @@ public class AiVideoHelper { | |||
| // AiPreviewResult result = AiVideoHelper.voicePreview(param); | |||
| // System.out.println(result); | |||
| // AiVideoHqParam param = new AiVideoHqParam(); | |||
| // param.setSave_dir("static/video/2023-07-06/16886220017209544_wav.mp4"); | |||
| // param.setAudio_path("static/mp3/2023-07-06/291ab7dc-18929b6e89e_convert.wav"); | |||
| // AiVideoHqResult result = AiVideoHelper.videoHq(param); | |||
| // System.out.println(result); | |||
| AiVideoHqParam param = new AiVideoHqParam(); | |||
| param.setSave_dir("static/tts/2023-07-07/16886958135060428.wav.mp4"); | |||
| param.setAudio_path("static/tts/2023-07-07/16886958135060428.wav"); | |||
| param.setCallback_url("https://phototest.metavatar.cc/C/callback/photo/speak"); | |||
| param.setTask_id(836541377936281600L); | |||
| AiVideoHqResult result = AiVideoHelper.videoHq(param); | |||
| System.out.println(result); | |||
| } | |||
| @@ -160,12 +160,7 @@ | |||
| select count(1) | |||
| from photo_speak_video | |||
| where user_id = #{userId} | |||
| <if test="type == 1"> | |||
| and video_status = 5 | |||
| </if> | |||
| <if test="type == 2"> | |||
| and video_hy_status = 5 | |||
| </if> | |||
| and (video_status = 5 or video_status = 11) | |||
| <if test="list != null and list.size > 0"> | |||
| and id in | |||
| <foreach collection="list" index="index" item="id" open="(" separator="," close=")"> | |||
| @@ -174,4 +169,17 @@ | |||
| </if> | |||
| </select> | |||
| <select id="getNotHaveUrl" resultType="com.iformall.domain.po.sm.PhotoSpeakVideo"> | |||
| select id,title,video_id,video_path, video_play_url,video_status | |||
| from photo_speak_video | |||
| where `is_del` = 0 | |||
| <if test=" null != videoStatuss "> | |||
| and video_status in | |||
| <foreach collection="videoStatuss" index="index" item="videoStatusItem" open="(" separator="," close=")"> | |||
| #{videoStatusItem} | |||
| </foreach> | |||
| </if> | |||
| or `cover_img` = '' | |||
| </select> | |||
| </mapper> | |||
| @@ -23,7 +23,7 @@ public interface VideoExcutor { | |||
| public String getVedioContentLength(String videoId); | |||
| VideUploadResult getVideoDetailWithCache(String videoId); | |||
| VideUploadResult getVideoDetailWithCache(String videoId,Boolean flag); | |||
| VideUploadResult getVideoDetailFromApi(String videoId); | |||
| @@ -141,8 +141,11 @@ public class AliyunVideoExcutor implements VideoExcutor { | |||
| } | |||
| @Override | |||
| public VideUploadResult getVideoDetailWithCache(String videoId) { | |||
| VideUploadResult videoDetail = UploadCacheHelper.getVideoDetail(redisTemplate, videoId); | |||
| public VideUploadResult getVideoDetailWithCache(String videoId,Boolean flag) { | |||
| VideUploadResult videoDetail = null; | |||
| if (flag){ | |||
| videoDetail = UploadCacheHelper.getVideoDetail(redisTemplate, videoId); | |||
| } | |||
| if(videoDetail != null){ | |||
| return videoDetail; | |||
| }else{ | |||