|
@@ -1,6 +1,11 @@
|
|
|
package com.taais.biz.service.impl;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
@@ -8,8 +13,12 @@ import com.mybatisflex.core.paginate.Page;
|
|
|
import com.mybatisflex.core.query.QueryWrapper;
|
|
|
import com.taais.biz.constant.BizConstant;
|
|
|
import com.taais.biz.domain.bo.VideoStableStartResultBo;
|
|
|
+import com.taais.biz.utils.ZipUtils;
|
|
|
+import com.taais.common.core.config.TaaisConfig;
|
|
|
+import com.taais.common.core.constant.Constants;
|
|
|
import com.taais.common.core.core.domain.CommonResult;
|
|
|
import com.taais.common.core.utils.MapstructUtils;
|
|
|
+import com.taais.common.core.utils.StringUtils;
|
|
|
import com.taais.common.json.utils.JsonUtils;
|
|
|
import com.taais.common.orm.core.page.PageQuery;
|
|
|
import com.taais.common.core.core.page.PageResult;
|
|
@@ -18,8 +27,13 @@ import com.taais.system.domain.vo.SysOssVo;
|
|
|
import com.taais.system.service.ISysOssService;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
import org.apache.http.entity.StringEntity;
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -30,11 +44,6 @@ import com.taais.biz.domain.bo.VideoStableBo;
|
|
|
import com.taais.biz.domain.vo.VideoStableVo;
|
|
|
import com.taais.biz.service.IVideoStableService;
|
|
|
|
|
|
-import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
-import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
-import org.apache.http.impl.client.HttpClients;
|
|
|
-import org.apache.http.util.EntityUtils;
|
|
|
-
|
|
|
import static com.taais.biz.domain.table.VideoStableTableDef.VIDEO_STABLE;
|
|
|
|
|
|
/**
|
|
@@ -66,8 +75,6 @@ public class VideoStableServiceImpl extends BaseServiceImpl<VideoStableMapper, V
|
|
|
(videoStableBo.getName()));
|
|
|
queryWrapper.and(VIDEO_STABLE.INPUT_OSS_ID.eq
|
|
|
(videoStableBo.getInputOssId()));
|
|
|
- queryWrapper.and(VIDEO_STABLE.OUTPUT_OSS_ID.eq
|
|
|
- (videoStableBo.getOutputOssId()));
|
|
|
queryWrapper.and(VIDEO_STABLE.START_TIME.eq
|
|
|
(videoStableBo.getStartTime()));
|
|
|
queryWrapper.and(VIDEO_STABLE.END_TIME.eq
|
|
@@ -143,6 +150,27 @@ public class VideoStableServiceImpl extends BaseServiceImpl<VideoStableMapper, V
|
|
|
return this.save(videoStable);// 使用全局配置的雪花算法主键生成器生成ID值
|
|
|
}
|
|
|
|
|
|
+ public static String removeFileExtension(String fileName) {
|
|
|
+ int lastDotIndex = fileName.lastIndexOf('.');
|
|
|
+ if (lastDotIndex == -1) {
|
|
|
+ return fileName; // 如果没有找到'.',则返回原文件名
|
|
|
+ }
|
|
|
+ return fileName.substring(0, lastDotIndex);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void makeDir(String path) {
|
|
|
+ File folder = new File(path);
|
|
|
+ if (!folder.exists()) {
|
|
|
+ folder.mkdirs();
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ FileUtils.cleanDirectory(folder);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 修改视频去抖动
|
|
|
*
|
|
@@ -175,26 +203,60 @@ public class VideoStableServiceImpl extends BaseServiceImpl<VideoStableMapper, V
|
|
|
public CommonResult start(Long id) {
|
|
|
VideoStable videoStable = getById(id);
|
|
|
|
|
|
+ SysOssVo inputOssEntity = ossService.getById(videoStable.getInputOssId());
|
|
|
+
|
|
|
+ String filePath = inputOssEntity.getFileName();
|
|
|
+ String localPath = TaaisConfig.getProfile();
|
|
|
+ String resourcePath = localPath + StringUtils.substringAfter(filePath, Constants.RESOURCE_PREFIX);
|
|
|
+
|
|
|
+ String fileName = StringUtils.substringAfterLast(filePath, "/");
|
|
|
+ String fileName_without_suffix = removeFileExtension(fileName);
|
|
|
+
|
|
|
+ Path path = Paths.get(resourcePath);
|
|
|
+ Path inputPath = path.resolveSibling(fileName_without_suffix + "_images");
|
|
|
+ Path outputPath = path.resolveSibling(fileName_without_suffix + "_stable");
|
|
|
+
|
|
|
+ makeDir(inputPath.toString());
|
|
|
+ makeDir(outputPath.toString());
|
|
|
+
|
|
|
+ ZipUtils.unzip(resourcePath, inputPath.toString());
|
|
|
+
|
|
|
+ videoStable.setInputPath(inputPath.toString());
|
|
|
+ videoStable.setOutputPath(outputPath.toString());
|
|
|
+
|
|
|
+ videoStable.setStartTime(new Date());
|
|
|
+
|
|
|
+ boolean flag = sendMsg(videoStable);
|
|
|
+ if (flag) {
|
|
|
+ videoStable.setStatus(BizConstant.VideoStatus.RUNNING);
|
|
|
+ } else {
|
|
|
+ videoStable.setEndTime(new Date());
|
|
|
+ videoStable.setStatus(BizConstant.VideoStatus.FAILED);
|
|
|
+ }
|
|
|
+
|
|
|
+ updateById(videoStable);
|
|
|
+ return CommonResult.success("start video_stable success");
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean sendMsg(VideoStable videoStable) {
|
|
|
log.info("start video_stable_url: {}", video_stable_url);
|
|
|
- try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
|
- HttpPost request = new HttpPost(video_stable_url);
|
|
|
- // 设置请求体
|
|
|
- System.out.println(JsonUtils.toJsonString(videoStable));
|
|
|
- StringEntity entity = new StringEntity(JsonUtils.toJsonString(videoStable), "UTF-8");
|
|
|
- entity.setContentType("application/json");
|
|
|
- request.setEntity(entity);
|
|
|
+
|
|
|
+ CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
+ HttpPost request = new HttpPost(video_stable_url);
|
|
|
+ // 设置请求体
|
|
|
+ System.out.println(JsonUtils.toJsonString(videoStable));
|
|
|
+ StringEntity entity = new StringEntity(JsonUtils.toJsonString(videoStable), "UTF-8");
|
|
|
+ entity.setContentType("application/json");
|
|
|
+ request.setEntity(entity);
|
|
|
+
|
|
|
+ try {
|
|
|
CloseableHttpResponse response = httpClient.execute(request);
|
|
|
String responseBody = EntityUtils.toString(response.getEntity());
|
|
|
- System.out.println(responseBody);
|
|
|
-
|
|
|
- videoStable.setStatus(BizConstant.VideoStatus.RUNNING);
|
|
|
- updateById(videoStable);
|
|
|
- return CommonResult.success("start video_stable success");
|
|
|
+ log.info("responseBody -> " + responseBody);
|
|
|
+ return true;
|
|
|
} catch (Exception e) {
|
|
|
- videoStable.setStatus(BizConstant.VideoStatus.FAILED);
|
|
|
- updateById(videoStable);
|
|
|
- e.printStackTrace();
|
|
|
- return CommonResult.fail("start video_stable error -> " + e.getMessage());
|
|
|
+ log.error("sendMsg error", e);
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
|